@promptbook/legacy-documents 0.73.0 → 0.74.0-11

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 (40) hide show
  1. package/README.md +176 -3
  2. package/esm/index.es.js +218 -288
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/anthropic-claude.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/azure-openai.index.d.ts +2 -2
  6. package/esm/typings/src/_packages/browser.index.d.ts +2 -2
  7. package/esm/typings/src/_packages/cli.index.d.ts +2 -2
  8. package/esm/typings/src/_packages/core.index.d.ts +7 -3
  9. package/esm/typings/src/_packages/documents.index.d.ts +2 -2
  10. package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -2
  11. package/esm/typings/src/_packages/fake-llm.index.d.ts +2 -2
  12. package/esm/typings/src/_packages/langtail.index.d.ts +2 -2
  13. package/esm/typings/src/_packages/legacy-documents.index.d.ts +2 -2
  14. package/esm/typings/src/_packages/markdown-utils.index.d.ts +2 -2
  15. package/esm/typings/src/_packages/node.index.d.ts +2 -2
  16. package/esm/typings/src/_packages/openai.index.d.ts +2 -2
  17. package/esm/typings/src/_packages/pdf.index.d.ts +2 -2
  18. package/esm/typings/src/_packages/remote-client.index.d.ts +2 -2
  19. package/esm/typings/src/_packages/remote-server.index.d.ts +2 -2
  20. package/esm/typings/src/_packages/utils.index.d.ts +2 -2
  21. package/esm/typings/src/_packages/website-crawler.index.d.ts +2 -2
  22. package/esm/typings/src/cli/cli-commands/make.d.ts +0 -1
  23. package/esm/typings/src/cli/cli-commands/run.d.ts +14 -0
  24. package/esm/typings/src/cli/promptbookCli.d.ts +1 -0
  25. package/esm/typings/src/cli/test/ptbk.d.ts +5 -2
  26. package/esm/typings/src/commands/{PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts → BOOK_VERSION/BookVersionCommand.d.ts} +4 -4
  27. package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +9 -0
  28. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
  29. package/esm/typings/src/commands/index.d.ts +1 -1
  30. package/esm/typings/src/config.d.ts +6 -0
  31. package/esm/typings/src/storage/blackhole/BlackholeStorage.d.ts +33 -0
  32. package/esm/typings/src/storage/memory/MemoryStorage.d.ts +1 -1
  33. package/esm/typings/src/storage/{memory/utils → utils}/PrefixStorage.d.ts +1 -1
  34. package/esm/typings/src/version.d.ts +13 -2
  35. package/package.json +2 -2
  36. package/umd/index.umd.js +219 -288
  37. package/umd/index.umd.js.map +1 -1
  38. package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +0 -9
  39. /package/esm/typings/src/commands/{PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts → BOOK_VERSION/bookVersionCommand.test.d.ts} +0 -0
  40. /package/esm/typings/src/storage/{memory → local-storage}/utils/makePromptbookStorageFromWebStorage.d.ts +0 -0
package/esm/index.es.js CHANGED
@@ -13,10 +13,20 @@ import { unparse, parse } from 'papaparse';
13
13
 
14
14
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
15
15
  /**
16
- * The version of the Promptbook library
16
+ * The version of the Book language
17
+ *
18
+ * @see https://github.com/webgptorg/book
19
+ */
20
+ var BOOK_LANGUAGE_VERSION = '1.0.0';
21
+ /**
22
+ * The version of the Promptbook engine
23
+ *
24
+ * @see https://github.com/webgptorg/promptbook
25
+ */
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.74.0-10';
27
+ /**
28
+ * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
17
29
  */
18
- var PROMPTBOOK_VERSION = '0.72.0';
19
- // TODO: [main] !!!! List here all the versions and annotate + put into script
20
30
 
21
31
  /*! *****************************************************************************
22
32
  Copyright (c) Microsoft Corporation.
@@ -560,12 +570,9 @@ function $execCommandNormalizeOptions(options) {
560
570
  })
561
571
  .filter(function (arg) { return arg !== ''; });
562
572
  if (_.length > 1) {
563
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
564
573
  _a = __read(_), command = _a[0], args = _a.slice(1);
565
574
  }
566
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
567
575
  if (options.args) {
568
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
569
576
  args = __spreadArray(__spreadArray([], __read(args), false), __read(options.args), false);
570
577
  }
571
578
  var humanReadableCommand = !['npx', 'npm'].includes(command) ? command : args[0];
@@ -1147,23 +1154,6 @@ function nameToSubfolderPath(name) {
1147
1154
  return [name.substr(0, 1).toLowerCase(), name.substr(1, 1).toLowerCase()];
1148
1155
  }
1149
1156
 
1150
- /**
1151
- * Just marks a place of place where should be something implemented
1152
- * No side effects.
1153
- *
1154
- * Note: It can be usefull suppressing eslint errors of unused variables
1155
- *
1156
- * @param value any values
1157
- * @returns void
1158
- * @private within the repository
1159
- */
1160
- function TODO_USE() {
1161
- var value = [];
1162
- for (var _i = 0; _i < arguments.length; _i++) {
1163
- value[_i] = arguments[_i];
1164
- }
1165
- }
1166
-
1167
1157
  /**
1168
1158
  * Create a filename for intermediate cache for scrapers
1169
1159
  *
@@ -1173,12 +1163,12 @@ function TODO_USE() {
1173
1163
  */
1174
1164
  function getScraperIntermediateSource(source, options) {
1175
1165
  return __awaiter(this, void 0, void 0, function () {
1176
- var sourceFilename, url, rootDirname, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
1166
+ var sourceFilename, url, cacheDirname, intermediateFilesStrategy, extension, isVerbose, hash, semanticName, pieces, name, cacheFilename, isDestroyed, fileHandler;
1177
1167
  return __generator(this, function (_a) {
1178
1168
  switch (_a.label) {
1179
1169
  case 0:
1180
1170
  sourceFilename = source.filename, url = source.url;
1181
- rootDirname = options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
1171
+ options.rootDirname, cacheDirname = options.cacheDirname, intermediateFilesStrategy = options.intermediateFilesStrategy, extension = options.extension, isVerbose = options.isVerbose;
1182
1172
  hash = SHA256(
1183
1173
  // <- TODO: [🥬] Encapsulate sha256 to some private utility function
1184
1174
  hexEncoder.parse(sourceFilename || url || 'untitled'))
@@ -1187,8 +1177,6 @@ function getScraperIntermediateSource(source, options) {
1187
1177
  semanticName = normalizeToKebabCase(titleToName((sourceFilename || url || '').split('intermediate').join(''))).substring(0, 20);
1188
1178
  pieces = ['intermediate', semanticName, hash].filter(function (piece) { return piece !== ''; });
1189
1179
  name = pieces.join('-').split('--').join('-');
1190
- // <- TODO: Use MAX_FILENAME_LENGTH
1191
- TODO_USE(rootDirname); // <- TODO: [😡]
1192
1180
  cacheFilename = join.apply(void 0, __spreadArray(__spreadArray([process.cwd(),
1193
1181
  cacheDirname], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), [name], false)).split('\\')
1194
1182
  .join('/') +
@@ -1558,7 +1546,7 @@ function isValidPromptbookVersion(version) {
1558
1546
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1559
1547
  return false;
1560
1548
  }
1561
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
1549
+ // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1562
1550
  return true;
1563
1551
  }
1564
1552
 
@@ -1629,7 +1617,7 @@ function isValidPipelineUrl(url) {
1629
1617
  if (!url.startsWith('https://')) {
1630
1618
  return false;
1631
1619
  }
1632
- if (!url.endsWith('.ptbk.md')) {
1620
+ if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.ptbk.md') || url.endsWith('.ptbk'))) {
1633
1621
  return false;
1634
1622
  }
1635
1623
  if (url.includes('#')) {
@@ -2418,6 +2406,188 @@ $deepFreeze({
2418
2406
  },
2419
2407
  });
2420
2408
 
2409
+ /**
2410
+ * @@@
2411
+ *
2412
+ * @public exported from `@promptbook/utils`
2413
+ */
2414
+ function deepClone(objectValue) {
2415
+ return JSON.parse(JSON.stringify(objectValue));
2416
+ /*
2417
+ TODO: [🧠] Is there a better implementation?
2418
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
2419
+ > for (const propertyName of propertyNames) {
2420
+ > const value = (objectValue as really_any)[propertyName];
2421
+ > if (value && typeof value === 'object') {
2422
+ > deepClone(value);
2423
+ > }
2424
+ > }
2425
+ > return Object.assign({}, objectValue);
2426
+ */
2427
+ }
2428
+ /**
2429
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
2430
+ */
2431
+
2432
+ /**
2433
+ * Function `addUsage` will add multiple usages into one
2434
+ *
2435
+ * Note: If you provide 0 values, it returns ZERO_USAGE
2436
+ *
2437
+ * @public exported from `@promptbook/core`
2438
+ */
2439
+ function addUsage() {
2440
+ var usageItems = [];
2441
+ for (var _i = 0; _i < arguments.length; _i++) {
2442
+ usageItems[_i] = arguments[_i];
2443
+ }
2444
+ return usageItems.reduce(function (acc, item) {
2445
+ var e_1, _a, e_2, _b;
2446
+ var _c;
2447
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2448
+ try {
2449
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2450
+ var key = _e.value;
2451
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2452
+ //@ts-ignore
2453
+ if (item.input[key]) {
2454
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2455
+ //@ts-ignore
2456
+ acc.input[key].value += item.input[key].value || 0;
2457
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2458
+ //@ts-ignore
2459
+ if (item.input[key].isUncertain) {
2460
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2461
+ //@ts-ignore
2462
+ acc.input[key].isUncertain = true;
2463
+ }
2464
+ }
2465
+ }
2466
+ }
2467
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2468
+ finally {
2469
+ try {
2470
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2471
+ }
2472
+ finally { if (e_1) throw e_1.error; }
2473
+ }
2474
+ try {
2475
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2476
+ var key = _g.value;
2477
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2478
+ //@ts-ignore
2479
+ if (item.output[key]) {
2480
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2481
+ //@ts-ignore
2482
+ acc.output[key].value += item.output[key].value || 0;
2483
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2484
+ //@ts-ignore
2485
+ if (item.output[key].isUncertain) {
2486
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2487
+ //@ts-ignore
2488
+ acc.output[key].isUncertain = true;
2489
+ }
2490
+ }
2491
+ }
2492
+ }
2493
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2494
+ finally {
2495
+ try {
2496
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2497
+ }
2498
+ finally { if (e_2) throw e_2.error; }
2499
+ }
2500
+ return acc;
2501
+ }, deepClone(ZERO_USAGE));
2502
+ }
2503
+
2504
+ /**
2505
+ * Intercepts LLM tools and counts total usage of the tools
2506
+ *
2507
+ * @param llmTools LLM tools to be intercepted with usage counting
2508
+ * @returns LLM tools with same functionality with added total cost counting
2509
+ * @public exported from `@promptbook/core`
2510
+ */
2511
+ function countTotalUsage(llmTools) {
2512
+ var _this = this;
2513
+ var totalUsage = ZERO_USAGE;
2514
+ var proxyTools = {
2515
+ get title() {
2516
+ // TODO: [🧠] Maybe put here some suffix
2517
+ return llmTools.title;
2518
+ },
2519
+ get description() {
2520
+ // TODO: [🧠] Maybe put here some suffix
2521
+ return llmTools.description;
2522
+ },
2523
+ checkConfiguration: function () {
2524
+ return __awaiter(this, void 0, void 0, function () {
2525
+ return __generator(this, function (_a) {
2526
+ return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
2527
+ });
2528
+ });
2529
+ },
2530
+ listModels: function () {
2531
+ return /* not await */ llmTools.listModels();
2532
+ },
2533
+ getTotalUsage: function () {
2534
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2535
+ return totalUsage;
2536
+ },
2537
+ };
2538
+ if (llmTools.callChatModel !== undefined) {
2539
+ proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2540
+ var promptResult;
2541
+ return __generator(this, function (_a) {
2542
+ switch (_a.label) {
2543
+ case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2544
+ case 1:
2545
+ promptResult = _a.sent();
2546
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2547
+ return [2 /*return*/, promptResult];
2548
+ }
2549
+ });
2550
+ }); };
2551
+ }
2552
+ if (llmTools.callCompletionModel !== undefined) {
2553
+ proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2554
+ var promptResult;
2555
+ return __generator(this, function (_a) {
2556
+ switch (_a.label) {
2557
+ case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2558
+ case 1:
2559
+ promptResult = _a.sent();
2560
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2561
+ return [2 /*return*/, promptResult];
2562
+ }
2563
+ });
2564
+ }); };
2565
+ }
2566
+ if (llmTools.callEmbeddingModel !== undefined) {
2567
+ proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2568
+ var promptResult;
2569
+ return __generator(this, function (_a) {
2570
+ switch (_a.label) {
2571
+ case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2572
+ case 1:
2573
+ promptResult = _a.sent();
2574
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2575
+ return [2 /*return*/, promptResult];
2576
+ }
2577
+ });
2578
+ }); };
2579
+ }
2580
+ // <- Note: [🤖]
2581
+ return proxyTools;
2582
+ }
2583
+ /**
2584
+ * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
2585
+ * TODO: [🧠] Is there some meaningfull way how to test this util
2586
+ * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
2587
+ * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
2588
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2589
+ */
2590
+
2421
2591
  /**
2422
2592
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
2423
2593
  *
@@ -2710,188 +2880,6 @@ function joinLlmExecutionTools() {
2710
2880
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2711
2881
  */
2712
2882
 
2713
- /**
2714
- * @@@
2715
- *
2716
- * @public exported from `@promptbook/utils`
2717
- */
2718
- function deepClone(objectValue) {
2719
- return JSON.parse(JSON.stringify(objectValue));
2720
- /*
2721
- TODO: [🧠] Is there a better implementation?
2722
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
2723
- > for (const propertyName of propertyNames) {
2724
- > const value = (objectValue as really_any)[propertyName];
2725
- > if (value && typeof value === 'object') {
2726
- > deepClone(value);
2727
- > }
2728
- > }
2729
- > return Object.assign({}, objectValue);
2730
- */
2731
- }
2732
- /**
2733
- * TODO: [🧠] Is there a way how to meaningfully test this utility
2734
- */
2735
-
2736
- /**
2737
- * Function `addUsage` will add multiple usages into one
2738
- *
2739
- * Note: If you provide 0 values, it returns ZERO_USAGE
2740
- *
2741
- * @public exported from `@promptbook/core`
2742
- */
2743
- function addUsage() {
2744
- var usageItems = [];
2745
- for (var _i = 0; _i < arguments.length; _i++) {
2746
- usageItems[_i] = arguments[_i];
2747
- }
2748
- return usageItems.reduce(function (acc, item) {
2749
- var e_1, _a, e_2, _b;
2750
- var _c;
2751
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2752
- try {
2753
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2754
- var key = _e.value;
2755
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2756
- //@ts-ignore
2757
- if (item.input[key]) {
2758
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2759
- //@ts-ignore
2760
- acc.input[key].value += item.input[key].value || 0;
2761
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2762
- //@ts-ignore
2763
- if (item.input[key].isUncertain) {
2764
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2765
- //@ts-ignore
2766
- acc.input[key].isUncertain = true;
2767
- }
2768
- }
2769
- }
2770
- }
2771
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2772
- finally {
2773
- try {
2774
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2775
- }
2776
- finally { if (e_1) throw e_1.error; }
2777
- }
2778
- try {
2779
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2780
- var key = _g.value;
2781
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2782
- //@ts-ignore
2783
- if (item.output[key]) {
2784
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2785
- //@ts-ignore
2786
- acc.output[key].value += item.output[key].value || 0;
2787
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2788
- //@ts-ignore
2789
- if (item.output[key].isUncertain) {
2790
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2791
- //@ts-ignore
2792
- acc.output[key].isUncertain = true;
2793
- }
2794
- }
2795
- }
2796
- }
2797
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2798
- finally {
2799
- try {
2800
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2801
- }
2802
- finally { if (e_2) throw e_2.error; }
2803
- }
2804
- return acc;
2805
- }, deepClone(ZERO_USAGE));
2806
- }
2807
-
2808
- /**
2809
- * Intercepts LLM tools and counts total usage of the tools
2810
- *
2811
- * @param llmTools LLM tools to be intercepted with usage counting
2812
- * @returns LLM tools with same functionality with added total cost counting
2813
- * @public exported from `@promptbook/core`
2814
- */
2815
- function countTotalUsage(llmTools) {
2816
- var _this = this;
2817
- var totalUsage = ZERO_USAGE;
2818
- var proxyTools = {
2819
- get title() {
2820
- // TODO: [🧠] Maybe put here some suffix
2821
- return llmTools.title;
2822
- },
2823
- get description() {
2824
- // TODO: [🧠] Maybe put here some suffix
2825
- return llmTools.description;
2826
- },
2827
- checkConfiguration: function () {
2828
- return __awaiter(this, void 0, void 0, function () {
2829
- return __generator(this, function (_a) {
2830
- return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
2831
- });
2832
- });
2833
- },
2834
- listModels: function () {
2835
- return /* not await */ llmTools.listModels();
2836
- },
2837
- getTotalUsage: function () {
2838
- // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2839
- return totalUsage;
2840
- },
2841
- };
2842
- if (llmTools.callChatModel !== undefined) {
2843
- proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2844
- var promptResult;
2845
- return __generator(this, function (_a) {
2846
- switch (_a.label) {
2847
- case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2848
- case 1:
2849
- promptResult = _a.sent();
2850
- totalUsage = addUsage(totalUsage, promptResult.usage);
2851
- return [2 /*return*/, promptResult];
2852
- }
2853
- });
2854
- }); };
2855
- }
2856
- if (llmTools.callCompletionModel !== undefined) {
2857
- proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2858
- var promptResult;
2859
- return __generator(this, function (_a) {
2860
- switch (_a.label) {
2861
- case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2862
- case 1:
2863
- promptResult = _a.sent();
2864
- totalUsage = addUsage(totalUsage, promptResult.usage);
2865
- return [2 /*return*/, promptResult];
2866
- }
2867
- });
2868
- }); };
2869
- }
2870
- if (llmTools.callEmbeddingModel !== undefined) {
2871
- proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2872
- var promptResult;
2873
- return __generator(this, function (_a) {
2874
- switch (_a.label) {
2875
- case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2876
- case 1:
2877
- promptResult = _a.sent();
2878
- totalUsage = addUsage(totalUsage, promptResult.usage);
2879
- return [2 /*return*/, promptResult];
2880
- }
2881
- });
2882
- }); };
2883
- }
2884
- // <- Note: [🤖]
2885
- return proxyTools;
2886
- }
2887
- /**
2888
- * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
2889
- * TODO: [🧠] Is there some meaningfull way how to test this util
2890
- * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
2891
- * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
2892
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2893
- */
2894
-
2895
2883
  /**
2896
2884
  * Takes an item or an array of items and returns an array of items
2897
2885
  *
@@ -3281,16 +3269,13 @@ function extensionToMimeType(value) {
3281
3269
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3282
3270
  var _a;
3283
3271
  return __awaiter(this, void 0, void 0, function () {
3284
- var sourceContent, name, _b, _c, rootDirname, _d,
3285
- // <- TODO: process.cwd() if running in Node.js
3286
- isVerbose, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3272
+ var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3287
3273
  return __generator(this, function (_e) {
3288
3274
  switch (_e.label) {
3289
3275
  case 0:
3290
3276
  sourceContent = knowledgeSource.sourceContent;
3291
3277
  name = knowledgeSource.name;
3292
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _d = _b.isVerbose, isVerbose = _d === void 0 ? DEFAULT_IS_VERBOSE : _d;
3293
- TODO_USE(isVerbose);
3278
+ _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
3294
3279
  if (!name) {
3295
3280
  name = sourceContentToName(sourceContent);
3296
3281
  }
@@ -3570,15 +3555,13 @@ function clonePipeline(pipeline) {
3570
3555
  */
3571
3556
  function prepareTemplates(pipeline, tools, options) {
3572
3557
  return __awaiter(this, void 0, void 0, function () {
3573
- var _a, maxParallelCount, templates, parameters, knowledgePiecesCount, templatesPrepared;
3558
+ var _a, maxParallelCount, templates, knowledgePiecesCount, templatesPrepared;
3574
3559
  var _this = this;
3575
3560
  return __generator(this, function (_b) {
3576
3561
  switch (_b.label) {
3577
3562
  case 0:
3578
3563
  _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _a;
3579
- templates = pipeline.templates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3580
- // TODO: [main] !! Apply examples to each template (if missing and is for the template defined)
3581
- TODO_USE(parameters);
3564
+ templates = pipeline.templates, pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3582
3565
  templatesPrepared = new Array(templates.length);
3583
3566
  return [4 /*yield*/, forEachAsync(templates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
3584
3567
  var dependentParameterNames, preparedContent, preparedTemplate;
@@ -3648,7 +3631,7 @@ function preparePipeline(pipeline, tools, options) {
3648
3631
  currentPreparation = {
3649
3632
  id: 1,
3650
3633
  // TODO: [🍥]> date: $currentDate(),
3651
- promptbookVersion: PROMPTBOOK_VERSION,
3634
+ promptbookVersion: PROMPTBOOK_ENGINE_VERSION,
3652
3635
  usage: ZERO_USAGE,
3653
3636
  };
3654
3637
  preparations = [
@@ -3972,22 +3955,12 @@ var CsvFormatDefinition = {
3972
3955
  formatName: 'CSV',
3973
3956
  aliases: ['SPREADSHEET', 'TABLE'],
3974
3957
  isValid: function (value, settings, schema) {
3975
- // TODO: Implement CSV validation
3976
- TODO_USE(value /* <- TODO: Use value here */);
3977
- TODO_USE(settings /* <- TODO: Use settings here */);
3978
- TODO_USE(schema /* <- TODO: Use schema here */);
3979
3958
  return true;
3980
3959
  },
3981
3960
  canBeValid: function (partialValue, settings, schema) {
3982
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
3983
- TODO_USE(settings /* <- TODO: Use settings here */);
3984
- TODO_USE(schema /* <- TODO: Use schema here */);
3985
3961
  return true;
3986
3962
  },
3987
3963
  heal: function (value, settings, schema) {
3988
- TODO_USE(value /* <- TODO: Use partialValue here */);
3989
- TODO_USE(settings /* <- TODO: Use settings here */);
3990
- TODO_USE(schema /* <- TODO: Use schema here */);
3991
3964
  throw new Error('Not implemented');
3992
3965
  },
3993
3966
  subvalueDefinitions: [
@@ -4106,20 +4079,12 @@ var JsonFormatDefinition = {
4106
4079
  formatName: 'JSON',
4107
4080
  mimeType: 'application/json',
4108
4081
  isValid: function (value, settings, schema) {
4109
- TODO_USE(schema /* <- TODO: Use schema here */);
4110
- TODO_USE(settings /* <- TODO: Use settings here */);
4111
4082
  return isValidJsonString(value);
4112
4083
  },
4113
4084
  canBeValid: function (partialValue, settings, schema) {
4114
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
4115
- TODO_USE(settings /* <- TODO: Use settings here */);
4116
- TODO_USE(schema /* <- TODO: Use schema here */);
4117
4085
  return true;
4118
4086
  },
4119
4087
  heal: function (value, settings, schema) {
4120
- TODO_USE(value /* <- TODO: Use partialValue here */);
4121
- TODO_USE(settings /* <- TODO: Use settings here */);
4122
- TODO_USE(schema /* <- TODO: Use schema here */);
4123
4088
  throw new Error('Not implemented');
4124
4089
  },
4125
4090
  subvalueDefinitions: [],
@@ -4201,21 +4166,12 @@ var XmlFormatDefinition = {
4201
4166
  formatName: 'XML',
4202
4167
  mimeType: 'application/xml',
4203
4168
  isValid: function (value, settings, schema) {
4204
- TODO_USE(value /* <- TODO: Use value here */);
4205
- TODO_USE(settings /* <- TODO: Use settings here */);
4206
- TODO_USE(schema /* <- TODO: Use schema here */);
4207
4169
  return true;
4208
4170
  },
4209
4171
  canBeValid: function (partialValue, settings, schema) {
4210
- TODO_USE(partialValue /* <- TODO: Use partialValue here */);
4211
- TODO_USE(settings /* <- TODO: Use settings here */);
4212
- TODO_USE(schema /* <- TODO: Use schema here */);
4213
4172
  return true;
4214
4173
  },
4215
4174
  heal: function (value, settings, schema) {
4216
- TODO_USE(value /* <- TODO: Use partialValue here */);
4217
- TODO_USE(settings /* <- TODO: Use settings here */);
4218
- TODO_USE(schema /* <- TODO: Use schema here */);
4219
4175
  throw new Error('Not implemented');
4220
4176
  },
4221
4177
  subvalueDefinitions: [],
@@ -4429,27 +4385,6 @@ function extractJsonBlock(markdown) {
4429
4385
  * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
4430
4386
  */
4431
4387
 
4432
- /**
4433
- * Just says that the variable is not used but should be kept
4434
- * No side effects.
4435
- *
4436
- * Note: It can be usefull for:
4437
- *
4438
- * 1) Suppressing eager optimization of unused imports
4439
- * 2) Suppressing eslint errors of unused variables in the tests
4440
- * 3) Keeping the type of the variable for type testing
4441
- *
4442
- * @param value any values
4443
- * @returns void
4444
- * @private within the repository
4445
- */
4446
- function keepUnused() {
4447
- var valuesToKeep = [];
4448
- for (var _i = 0; _i < arguments.length; _i++) {
4449
- valuesToKeep[_i] = arguments[_i];
4450
- }
4451
- }
4452
-
4453
4388
  /**
4454
4389
  * Replaces parameters in template with values from parameters object
4455
4390
  *
@@ -4562,10 +4497,12 @@ function countLines(text) {
4562
4497
  * @public exported from `@promptbook/utils`
4563
4498
  */
4564
4499
  function countPages(text) {
4565
- var sentencesPerPage = 5; // Assuming each page has 5 sentences
4566
- var sentences = text.split(/[.!?]+/).filter(function (sentence) { return sentence.trim() !== ''; });
4567
- var pageCount = Math.ceil(sentences.length / sentencesPerPage);
4568
- return pageCount;
4500
+ if (text === '') {
4501
+ return 0;
4502
+ }
4503
+ var pagesByLinesCount = Math.ceil(countLines(text) / 44);
4504
+ var pagesByCharactersCount = Math.ceil(countCharacters(text) / 2772);
4505
+ return Math.max(pagesByLinesCount, pagesByCharactersCount);
4569
4506
  }
4570
4507
 
4571
4508
  /**
@@ -4943,7 +4880,6 @@ function executeAttempts(options) {
4943
4880
  $ongoingTemplateResult.$resultString = extractJsonBlock($ongoingTemplateResult.$resultString || '');
4944
4881
  }
4945
4882
  catch (error) {
4946
- keepUnused(error);
4947
4883
  throw new ExpectError(spaceTrim(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
4948
4884
  /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
4949
4885
  }
@@ -5121,7 +5057,6 @@ function executeFormatSubvalues(options) {
5121
5057
  function getContextForTemplate(template) {
5122
5058
  return __awaiter(this, void 0, void 0, function () {
5123
5059
  return __generator(this, function (_a) {
5124
- TODO_USE(template);
5125
5060
  return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [🏍] Implement */];
5126
5061
  });
5127
5062
  });
@@ -5134,11 +5069,9 @@ function getContextForTemplate(template) {
5134
5069
  */
5135
5070
  function getKnowledgeForTemplate(options) {
5136
5071
  return __awaiter(this, void 0, void 0, function () {
5137
- var preparedPipeline, template;
5072
+ var preparedPipeline;
5138
5073
  return __generator(this, function (_a) {
5139
- preparedPipeline = options.preparedPipeline, template = options.template;
5140
- // TODO: [♨] Implement Better - use real index and keyword search from `template` and {examples}
5141
- TODO_USE(template);
5074
+ preparedPipeline = options.preparedPipeline, options.template;
5142
5075
  return [2 /*return*/, preparedPipeline.knowledgePieces.map(function (_a) {
5143
5076
  var content = _a.content;
5144
5077
  return "- ".concat(content);
@@ -5155,8 +5088,6 @@ function getKnowledgeForTemplate(options) {
5155
5088
  function getExamplesForTemplate(template) {
5156
5089
  return __awaiter(this, void 0, void 0, function () {
5157
5090
  return __generator(this, function (_a) {
5158
- // TODO: [♨] Implement Better - use real index and keyword search
5159
- TODO_USE(template);
5160
5091
  return [2 /*return*/, RESERVED_PARAMETER_MISSING_VALUE /* <- TODO: [♨] Implement */];
5161
5092
  });
5162
5093
  });
@@ -5175,13 +5106,13 @@ function getReservedParametersForTemplate(options) {
5175
5106
  switch (_b.label) {
5176
5107
  case 0:
5177
5108
  preparedPipeline = options.preparedPipeline, template = options.template, pipelineIdentification = options.pipelineIdentification;
5178
- return [4 /*yield*/, getContextForTemplate(template)];
5109
+ return [4 /*yield*/, getContextForTemplate()];
5179
5110
  case 1:
5180
5111
  context = _b.sent();
5181
5112
  return [4 /*yield*/, getKnowledgeForTemplate({ preparedPipeline: preparedPipeline, template: template })];
5182
5113
  case 2:
5183
5114
  knowledge = _b.sent();
5184
- return [4 /*yield*/, getExamplesForTemplate(template)];
5115
+ return [4 /*yield*/, getExamplesForTemplate()];
5185
5116
  case 3:
5186
5117
  examples = _b.sent();
5187
5118
  currentDate = new Date().toISOString();
@@ -5416,7 +5347,7 @@ function executePipeline(options) {
5416
5347
  executionReport = {
5417
5348
  pipelineUrl: preparedPipeline.pipelineUrl,
5418
5349
  title: preparedPipeline.title,
5419
- promptbookUsedVersion: PROMPTBOOK_VERSION,
5350
+ promptbookUsedVersion: PROMPTBOOK_ENGINE_VERSION,
5420
5351
  promptbookRequestedVersion: preparedPipeline.promptbookVersion,
5421
5352
  description: preparedPipeline.description,
5422
5353
  promptExecutions: [],
@@ -5796,13 +5727,13 @@ var MarkdownScraper = /** @class */ (function () {
5796
5727
  */
5797
5728
  MarkdownScraper.prototype.scrape = function (source) {
5798
5729
  return __awaiter(this, void 0, void 0, function () {
5799
- var _a, _b, maxParallelCount, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
5730
+ var _a, _c, isVerbose, llm, _llms, llmTools, collection, prepareKnowledgeFromMarkdownExecutor, _d, prepareTitleExecutor, _e, prepareKeywordsExecutor, _f, knowledgeContent, result, outputParameters, knowledgePiecesRaw, knowledgeTextPieces, knowledge;
5800
5731
  var _g, _h, _j;
5801
5732
  var _this = this;
5802
5733
  return __generator(this, function (_k) {
5803
5734
  switch (_k.label) {
5804
5735
  case 0:
5805
- _a = this.options, _b = _a.maxParallelCount, maxParallelCount = _b === void 0 ? DEFAULT_MAX_PARALLEL_COUNT : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
5736
+ _a = this.options, _a.maxParallelCount, _c = _a.isVerbose, isVerbose = _c === void 0 ? DEFAULT_IS_VERBOSE : _c;
5806
5737
  llm = this.tools.llm;
5807
5738
  if (llm === undefined) {
5808
5739
  throw new MissingToolsError('LLM tools are required for scraping external files');
@@ -5810,7 +5741,6 @@ var MarkdownScraper = /** @class */ (function () {
5810
5741
  }
5811
5742
  _llms = arrayableToArray(llm);
5812
5743
  llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools.apply(void 0, __spreadArray([], __read(_llms), false));
5813
- TODO_USE(maxParallelCount); // <- [🪂]
5814
5744
  collection = createCollectionFromJson.apply(void 0, __spreadArray([], __read(PipelineCollection), false));
5815
5745
  _d = createPipelineExecutor;
5816
5746
  _g = {};
@@ -6299,5 +6229,5 @@ var _LegacyDocumentScraperRegistration = $scrapersRegister.register(createLegacy
6299
6229
  * TODO: [🎶] Naming "constructor" vs "creator" vs "factory"
6300
6230
  */
6301
6231
 
6302
- export { LegacyDocumentScraper, PROMPTBOOK_VERSION, _LegacyDocumentScraperRegistration, createLegacyDocumentScraper };
6232
+ export { BOOK_LANGUAGE_VERSION, LegacyDocumentScraper, PROMPTBOOK_ENGINE_VERSION, _LegacyDocumentScraperRegistration, createLegacyDocumentScraper };
6303
6233
  //# sourceMappingURL=index.es.js.map