@promptbook/legacy-documents 0.71.0-17 → 0.72.0-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/esm/index.es.js +229 -202
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/cli.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -2
  5. package/esm/typings/src/_packages/openai.index.d.ts +8 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +8 -2
  7. package/esm/typings/src/dialogs/callback/CallbackInterfaceTools.d.ts +1 -1
  8. package/esm/typings/src/dialogs/simple-prompt/SimplePromptInterfaceTools.d.ts +1 -1
  9. package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/LindatAutomaticTranslator.d.ts +1 -1
  10. package/esm/typings/src/execution/utils/addUsage.d.ts +0 -56
  11. package/esm/typings/src/execution/utils/usage-constants.d.ts +127 -0
  12. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  13. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  14. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +1 -1
  15. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionToolsOptions.d.ts +2 -1
  16. package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +1 -1
  18. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +1 -1
  19. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +37 -0
  20. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionToolsOptions.d.ts +14 -0
  21. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +11 -2
  22. package/esm/typings/src/llm-providers/openai/OpenAiExecutionToolsOptions.d.ts +2 -2
  23. package/esm/typings/src/llm-providers/openai/createOpenAiAssistantExecutionTools.d.ts +15 -0
  24. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +9 -0
  25. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +9 -0
  26. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -3
  27. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Request.d.ts +15 -6
  28. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_ListModels_Response.d.ts +2 -2
  29. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Request.d.ts +6 -12
  30. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Prompt_Response.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/remote/interfaces/RemoteLlmExecutionToolsOptions.d.ts +9 -14
  32. package/esm/typings/src/llm-providers/remote/interfaces/RemoteServerOptions.d.ts +22 -8
  33. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  34. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
  35. package/esm/typings/src/scripting/python/PythonExecutionTools.d.ts +1 -1
  36. package/esm/typings/src/scripting/typescript/TypescriptExecutionTools.d.ts +1 -1
  37. package/esm/typings/src/storage/file-cache-storage/FileCacheStorage.d.ts +1 -1
  38. package/esm/typings/src/types/Prompt.d.ts +1 -0
  39. package/esm/typings/src/types/typeAliases.d.ts +11 -8
  40. package/package.json +2 -2
  41. package/umd/index.umd.js +229 -202
  42. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -15,7 +15,7 @@ import { unparse, parse } from 'papaparse';
15
15
  /**
16
16
  * The version of the Promptbook library
17
17
  */
18
- var PROMPTBOOK_VERSION = '0.71.0-16';
18
+ var PROMPTBOOK_VERSION = '0.72.0-9';
19
19
  // TODO: [main] !!!! List here all the versions and annotate + put into script
20
20
 
21
21
  /*! *****************************************************************************
@@ -2267,127 +2267,6 @@ function serializeError(error) {
2267
2267
  };
2268
2268
  }
2269
2269
 
2270
- /**
2271
- * @@@
2272
- *
2273
- * @public exported from `@promptbook/utils`
2274
- */
2275
- function deepClone(objectValue) {
2276
- return JSON.parse(JSON.stringify(objectValue));
2277
- /*
2278
- TODO: [🧠] Is there a better implementation?
2279
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
2280
- > for (const propertyName of propertyNames) {
2281
- > const value = (objectValue as really_any)[propertyName];
2282
- > if (value && typeof value === 'object') {
2283
- > deepClone(value);
2284
- > }
2285
- > }
2286
- > return Object.assign({}, objectValue);
2287
- */
2288
- }
2289
- /**
2290
- * TODO: [🧠] Is there a way how to meaningfully test this utility
2291
- */
2292
-
2293
- /**
2294
- * @@@
2295
- *
2296
- * @public exported from `@promptbook/core`
2297
- */
2298
- var ZERO_USAGE = $deepFreeze({
2299
- price: { value: 0 },
2300
- input: {
2301
- tokensCount: { value: 0 },
2302
- charactersCount: { value: 0 },
2303
- wordsCount: { value: 0 },
2304
- sentencesCount: { value: 0 },
2305
- linesCount: { value: 0 },
2306
- paragraphsCount: { value: 0 },
2307
- pagesCount: { value: 0 },
2308
- },
2309
- output: {
2310
- tokensCount: { value: 0 },
2311
- charactersCount: { value: 0 },
2312
- wordsCount: { value: 0 },
2313
- sentencesCount: { value: 0 },
2314
- linesCount: { value: 0 },
2315
- paragraphsCount: { value: 0 },
2316
- pagesCount: { value: 0 },
2317
- },
2318
- });
2319
- /**
2320
- * Function `addUsage` will add multiple usages into one
2321
- *
2322
- * Note: If you provide 0 values, it returns ZERO_USAGE
2323
- *
2324
- * @public exported from `@promptbook/core`
2325
- */
2326
- function addUsage() {
2327
- var usageItems = [];
2328
- for (var _i = 0; _i < arguments.length; _i++) {
2329
- usageItems[_i] = arguments[_i];
2330
- }
2331
- return usageItems.reduce(function (acc, item) {
2332
- var e_1, _a, e_2, _b;
2333
- var _c;
2334
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2335
- try {
2336
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2337
- var key = _e.value;
2338
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2339
- //@ts-ignore
2340
- if (item.input[key]) {
2341
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2342
- //@ts-ignore
2343
- acc.input[key].value += item.input[key].value || 0;
2344
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2345
- //@ts-ignore
2346
- if (item.input[key].isUncertain) {
2347
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2348
- //@ts-ignore
2349
- acc.input[key].isUncertain = true;
2350
- }
2351
- }
2352
- }
2353
- }
2354
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2355
- finally {
2356
- try {
2357
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2358
- }
2359
- finally { if (e_1) throw e_1.error; }
2360
- }
2361
- try {
2362
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2363
- var key = _g.value;
2364
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2365
- //@ts-ignore
2366
- if (item.output[key]) {
2367
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2368
- //@ts-ignore
2369
- acc.output[key].value += item.output[key].value || 0;
2370
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2371
- //@ts-ignore
2372
- if (item.output[key].isUncertain) {
2373
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2374
- //@ts-ignore
2375
- acc.output[key].isUncertain = true;
2376
- }
2377
- }
2378
- }
2379
- }
2380
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
2381
- finally {
2382
- try {
2383
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2384
- }
2385
- finally { if (e_2) throw e_2.error; }
2386
- }
2387
- return acc;
2388
- }, deepClone(ZERO_USAGE));
2389
- }
2390
-
2391
2270
  /**
2392
2271
  * Async version of Array.forEach
2393
2272
  *
@@ -2465,91 +2344,57 @@ function forEachAsync(array, options, callbackfunction) {
2465
2344
  }
2466
2345
 
2467
2346
  /**
2468
- * Intercepts LLM tools and counts total usage of the tools
2347
+ * Represents the usage with no resources consumed
2469
2348
  *
2470
- * @param llmTools LLM tools to be intercepted with usage counting
2471
- * @returns LLM tools with same functionality with added total cost counting
2472
2349
  * @public exported from `@promptbook/core`
2473
2350
  */
2474
- function countTotalUsage(llmTools) {
2475
- var _this = this;
2476
- var totalUsage = ZERO_USAGE;
2477
- var proxyTools = {
2478
- get title() {
2479
- // TODO: [🧠] Maybe put here some suffix
2480
- return llmTools.title;
2481
- },
2482
- get description() {
2483
- // TODO: [🧠] Maybe put here some suffix
2484
- return llmTools.description;
2485
- },
2486
- checkConfiguration: function () {
2487
- return __awaiter(this, void 0, void 0, function () {
2488
- return __generator(this, function (_a) {
2489
- return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
2490
- });
2491
- });
2492
- },
2493
- listModels: function () {
2494
- return /* not await */ llmTools.listModels();
2495
- },
2496
- getTotalUsage: function () {
2497
- // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2498
- return totalUsage;
2499
- },
2500
- };
2501
- if (llmTools.callChatModel !== undefined) {
2502
- proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2503
- var promptResult;
2504
- return __generator(this, function (_a) {
2505
- switch (_a.label) {
2506
- case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2507
- case 1:
2508
- promptResult = _a.sent();
2509
- totalUsage = addUsage(totalUsage, promptResult.usage);
2510
- return [2 /*return*/, promptResult];
2511
- }
2512
- });
2513
- }); };
2514
- }
2515
- if (llmTools.callCompletionModel !== undefined) {
2516
- proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2517
- var promptResult;
2518
- return __generator(this, function (_a) {
2519
- switch (_a.label) {
2520
- case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2521
- case 1:
2522
- promptResult = _a.sent();
2523
- totalUsage = addUsage(totalUsage, promptResult.usage);
2524
- return [2 /*return*/, promptResult];
2525
- }
2526
- });
2527
- }); };
2528
- }
2529
- if (llmTools.callEmbeddingModel !== undefined) {
2530
- proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2531
- var promptResult;
2532
- return __generator(this, function (_a) {
2533
- switch (_a.label) {
2534
- case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2535
- case 1:
2536
- promptResult = _a.sent();
2537
- totalUsage = addUsage(totalUsage, promptResult.usage);
2538
- return [2 /*return*/, promptResult];
2539
- }
2540
- });
2541
- }); };
2542
- }
2543
- // <- Note: [🤖]
2544
- return proxyTools;
2545
- }
2351
+ var ZERO_USAGE = $deepFreeze({
2352
+ price: { value: 0 },
2353
+ input: {
2354
+ tokensCount: { value: 0 },
2355
+ charactersCount: { value: 0 },
2356
+ wordsCount: { value: 0 },
2357
+ sentencesCount: { value: 0 },
2358
+ linesCount: { value: 0 },
2359
+ paragraphsCount: { value: 0 },
2360
+ pagesCount: { value: 0 },
2361
+ },
2362
+ output: {
2363
+ tokensCount: { value: 0 },
2364
+ charactersCount: { value: 0 },
2365
+ wordsCount: { value: 0 },
2366
+ sentencesCount: { value: 0 },
2367
+ linesCount: { value: 0 },
2368
+ paragraphsCount: { value: 0 },
2369
+ pagesCount: { value: 0 },
2370
+ },
2371
+ });
2546
2372
  /**
2547
- * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
2548
- * TODO: [🧠] Is there some meaningfull way how to test this util
2549
- * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
2550
- * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
2551
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2373
+ * Represents the usage with unknown resources consumed
2374
+ *
2375
+ * @public exported from `@promptbook/core`
2552
2376
  */
2377
+ $deepFreeze({
2378
+ price: { value: 0, isUncertain: true },
2379
+ input: {
2380
+ tokensCount: { value: 0, isUncertain: true },
2381
+ charactersCount: { value: 0, isUncertain: true },
2382
+ wordsCount: { value: 0, isUncertain: true },
2383
+ sentencesCount: { value: 0, isUncertain: true },
2384
+ linesCount: { value: 0, isUncertain: true },
2385
+ paragraphsCount: { value: 0, isUncertain: true },
2386
+ pagesCount: { value: 0, isUncertain: true },
2387
+ },
2388
+ output: {
2389
+ tokensCount: { value: 0, isUncertain: true },
2390
+ charactersCount: { value: 0, isUncertain: true },
2391
+ wordsCount: { value: 0, isUncertain: true },
2392
+ sentencesCount: { value: 0, isUncertain: true },
2393
+ linesCount: { value: 0, isUncertain: true },
2394
+ paragraphsCount: { value: 0, isUncertain: true },
2395
+ pagesCount: { value: 0, isUncertain: true },
2396
+ },
2397
+ });
2553
2398
 
2554
2399
  /**
2555
2400
  * Multiple LLM Execution Tools is a proxy server that uses multiple execution tools internally and exposes the executor interface externally.
@@ -2844,6 +2689,188 @@ function joinLlmExecutionTools() {
2844
2689
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2845
2690
  */
2846
2691
 
2692
+ /**
2693
+ * @@@
2694
+ *
2695
+ * @public exported from `@promptbook/utils`
2696
+ */
2697
+ function deepClone(objectValue) {
2698
+ return JSON.parse(JSON.stringify(objectValue));
2699
+ /*
2700
+ TODO: [🧠] Is there a better implementation?
2701
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
2702
+ > for (const propertyName of propertyNames) {
2703
+ > const value = (objectValue as really_any)[propertyName];
2704
+ > if (value && typeof value === 'object') {
2705
+ > deepClone(value);
2706
+ > }
2707
+ > }
2708
+ > return Object.assign({}, objectValue);
2709
+ */
2710
+ }
2711
+ /**
2712
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
2713
+ */
2714
+
2715
+ /**
2716
+ * Function `addUsage` will add multiple usages into one
2717
+ *
2718
+ * Note: If you provide 0 values, it returns ZERO_USAGE
2719
+ *
2720
+ * @public exported from `@promptbook/core`
2721
+ */
2722
+ function addUsage() {
2723
+ var usageItems = [];
2724
+ for (var _i = 0; _i < arguments.length; _i++) {
2725
+ usageItems[_i] = arguments[_i];
2726
+ }
2727
+ return usageItems.reduce(function (acc, item) {
2728
+ var e_1, _a, e_2, _b;
2729
+ var _c;
2730
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
2731
+ try {
2732
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
2733
+ var key = _e.value;
2734
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2735
+ //@ts-ignore
2736
+ if (item.input[key]) {
2737
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2738
+ //@ts-ignore
2739
+ acc.input[key].value += item.input[key].value || 0;
2740
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2741
+ //@ts-ignore
2742
+ if (item.input[key].isUncertain) {
2743
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2744
+ //@ts-ignore
2745
+ acc.input[key].isUncertain = true;
2746
+ }
2747
+ }
2748
+ }
2749
+ }
2750
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2751
+ finally {
2752
+ try {
2753
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2754
+ }
2755
+ finally { if (e_1) throw e_1.error; }
2756
+ }
2757
+ try {
2758
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
2759
+ var key = _g.value;
2760
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2761
+ //@ts-ignore
2762
+ if (item.output[key]) {
2763
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2764
+ //@ts-ignore
2765
+ acc.output[key].value += item.output[key].value || 0;
2766
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2767
+ //@ts-ignore
2768
+ if (item.output[key].isUncertain) {
2769
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2770
+ //@ts-ignore
2771
+ acc.output[key].isUncertain = true;
2772
+ }
2773
+ }
2774
+ }
2775
+ }
2776
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2777
+ finally {
2778
+ try {
2779
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
2780
+ }
2781
+ finally { if (e_2) throw e_2.error; }
2782
+ }
2783
+ return acc;
2784
+ }, deepClone(ZERO_USAGE));
2785
+ }
2786
+
2787
+ /**
2788
+ * Intercepts LLM tools and counts total usage of the tools
2789
+ *
2790
+ * @param llmTools LLM tools to be intercepted with usage counting
2791
+ * @returns LLM tools with same functionality with added total cost counting
2792
+ * @public exported from `@promptbook/core`
2793
+ */
2794
+ function countTotalUsage(llmTools) {
2795
+ var _this = this;
2796
+ var totalUsage = ZERO_USAGE;
2797
+ var proxyTools = {
2798
+ get title() {
2799
+ // TODO: [🧠] Maybe put here some suffix
2800
+ return llmTools.title;
2801
+ },
2802
+ get description() {
2803
+ // TODO: [🧠] Maybe put here some suffix
2804
+ return llmTools.description;
2805
+ },
2806
+ checkConfiguration: function () {
2807
+ return __awaiter(this, void 0, void 0, function () {
2808
+ return __generator(this, function (_a) {
2809
+ return [2 /*return*/, /* not await */ llmTools.checkConfiguration()];
2810
+ });
2811
+ });
2812
+ },
2813
+ listModels: function () {
2814
+ return /* not await */ llmTools.listModels();
2815
+ },
2816
+ getTotalUsage: function () {
2817
+ // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2818
+ return totalUsage;
2819
+ },
2820
+ };
2821
+ if (llmTools.callChatModel !== undefined) {
2822
+ proxyTools.callChatModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2823
+ var promptResult;
2824
+ return __generator(this, function (_a) {
2825
+ switch (_a.label) {
2826
+ case 0: return [4 /*yield*/, llmTools.callChatModel(prompt)];
2827
+ case 1:
2828
+ promptResult = _a.sent();
2829
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2830
+ return [2 /*return*/, promptResult];
2831
+ }
2832
+ });
2833
+ }); };
2834
+ }
2835
+ if (llmTools.callCompletionModel !== undefined) {
2836
+ proxyTools.callCompletionModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2837
+ var promptResult;
2838
+ return __generator(this, function (_a) {
2839
+ switch (_a.label) {
2840
+ case 0: return [4 /*yield*/, llmTools.callCompletionModel(prompt)];
2841
+ case 1:
2842
+ promptResult = _a.sent();
2843
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2844
+ return [2 /*return*/, promptResult];
2845
+ }
2846
+ });
2847
+ }); };
2848
+ }
2849
+ if (llmTools.callEmbeddingModel !== undefined) {
2850
+ proxyTools.callEmbeddingModel = function (prompt) { return __awaiter(_this, void 0, void 0, function () {
2851
+ var promptResult;
2852
+ return __generator(this, function (_a) {
2853
+ switch (_a.label) {
2854
+ case 0: return [4 /*yield*/, llmTools.callEmbeddingModel(prompt)];
2855
+ case 1:
2856
+ promptResult = _a.sent();
2857
+ totalUsage = addUsage(totalUsage, promptResult.usage);
2858
+ return [2 /*return*/, promptResult];
2859
+ }
2860
+ });
2861
+ }); };
2862
+ }
2863
+ // <- Note: [🤖]
2864
+ return proxyTools;
2865
+ }
2866
+ /**
2867
+ * TODO: [🧠][💸] Maybe make some common abstraction `interceptLlmTools` and use here (or use javascript Proxy?)
2868
+ * TODO: [🧠] Is there some meaningfull way how to test this util
2869
+ * TODO: [🧠][🌯] Maybe a way how to hide ability to `get totalUsage`
2870
+ * > const [llmToolsWithUsage,getUsage] = countTotalUsage(llmTools);
2871
+ * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2872
+ */
2873
+
2847
2874
  /**
2848
2875
  * Takes an item or an array of items and returns an array of items
2849
2876
  *