@promptbook/remote-server 0.88.0-9 → 0.89.0-1

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 (25) hide show
  1. package/README.md +35 -14
  2. package/esm/index.es.js +62 -26
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +10 -0
  6. package/esm/typings/src/config.d.ts +1 -1
  7. package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
  8. package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
  9. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +7 -0
  10. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
  11. package/esm/typings/src/playground/BrjappConnector.d.ts +64 -0
  12. package/esm/typings/src/playground/brjapp-api-schema.d.ts +12879 -0
  13. package/esm/typings/src/playground/playground.d.ts +5 -0
  14. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +2 -1
  15. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -3
  16. package/esm/typings/src/types/typeAliases.d.ts +2 -2
  17. package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
  18. package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
  19. package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
  20. package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
  21. package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
  22. package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
  23. package/package.json +2 -2
  24. package/umd/index.umd.js +65 -29
  25. package/umd/index.umd.js.map +1 -1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ts-node
2
+ export {};
3
+ /**
4
+ * Note: [⚫] Code in this file should never be published in any package
5
+ */
@@ -37,7 +37,8 @@ export type PromptbookServer_AnonymousIdentification = {
37
37
  /**
38
38
  * Identifier of the end user
39
39
  *
40
- * Note: this is passed to the certain model providers to identify misuse
40
+ * Note: This can be either some id or email or any other identifier
41
+ * Note: In anonymous mode, this is passed to the certain model providers to identify misuse
41
42
  * Note: In anonymous mode, there is no need to identify yourself, nor does it change the actual configuration of LLM Tools (unlike in application mode)
42
43
  */
43
44
  readonly userId?: string_user_id;
@@ -58,15 +58,27 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
58
58
  };
59
59
  export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
60
60
  /**
61
- * @@@
61
+ * Identifier of the application
62
+ *
63
+ * Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
64
+ * Note: This can be some id or some semantic name like "email-agent"
62
65
  */
63
66
  readonly appId: string_app_id | null;
64
67
  /**
65
- * @@@
68
+ * Identifier of the end user
69
+ *
70
+ * Note: This can be either some id or email or any other identifier
71
+ * Note: This is also passed to the certain model providers to identify misuse
66
72
  */
67
73
  readonly userId?: string_user_id;
68
74
  /**
69
- * @@@
75
+ * Token of the user to verify its identity
76
+ *
77
+ * Note: This is passed for example to `createLlmExecutionTools`
78
+ */
79
+ readonly userToken?: string_user_id;
80
+ /**
81
+ * Additional arbitrary options to identify the client or to pass custom metadata
70
82
  */
71
83
  readonly customOptions?: TCustomOptions;
72
84
  };
@@ -433,13 +433,13 @@ export type string_uuid = string & {
433
433
  *
434
434
  * @@@
435
435
  */
436
- export type string_app_id = id;
436
+ export type string_app_id = id | 'app';
437
437
  /**
438
438
  * End user identifier
439
439
  *
440
440
  * @@@
441
441
  */
442
- export type string_user_id = id;
442
+ export type string_user_id = id | string_email;
443
443
  /**
444
444
  * Semantic helper
445
445
  *
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
5
5
  * @public exported from `@promptbook/utils`
6
6
  */
7
7
  export declare function countCharacters(text: string): ExpectationAmount;
8
+ /**
9
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
10
+ */
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
7
7
  * @public exported from `@promptbook/utils`
8
8
  */
9
9
  export declare function countLines(text: string): ExpectationAmount;
10
+ /**
11
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
12
+ */
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
7
7
  * @public exported from `@promptbook/utils`
8
8
  */
9
9
  export declare function countPages(text: string): ExpectationAmount;
10
+ /**
11
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
12
+ */
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
5
5
  * @public exported from `@promptbook/utils`
6
6
  */
7
7
  export declare function countParagraphs(text: string): ExpectationAmount;
8
+ /**
9
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
10
+ */
@@ -11,3 +11,6 @@ export declare function splitIntoSentences(text: string): ReadonlyArray<string>;
11
11
  * @public exported from `@promptbook/utils`
12
12
  */
13
13
  export declare function countSentences(text: string): ExpectationAmount;
14
+ /**
15
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
16
+ */
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
5
5
  * @public exported from `@promptbook/utils`
6
6
  */
7
7
  export declare function countWords(text: string): ExpectationAmount;
8
+ /**
9
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
10
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.88.0-9",
3
+ "version": "0.89.0-1",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.88.0-9"
50
+ "@promptbook/core": "0.89.0-1"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.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('colors'), require('express'), require('http'), require('socket.io'), require('spacetrim'), require('waitasecond'), require('child_process'), require('fs/promises'), require('path'), require('rxjs'), require('crypto'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'http', 'socket.io', 'spacetrim', 'waitasecond', 'child_process', 'fs/promises', 'path', 'rxjs', 'crypto', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.waitasecond, global.child_process, global.promises, global.path, global.rxjs, global.crypto, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, colors, express, http, socket_io, spaceTrim, waitasecond, child_process, promises, path, rxjs, crypto, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('express'), require('http'), require('socket.io'), require('spacetrim'), require('waitasecond'), require('crypto'), require('child_process'), require('fs/promises'), require('path'), require('rxjs'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'http', 'socket.io', 'spacetrim', 'waitasecond', 'crypto', 'child_process', 'fs/promises', 'path', 'rxjs', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.waitasecond, global.crypto, global.child_process, global.promises, global.path, global.rxjs, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, colors, express, http, socket_io, spaceTrim, waitasecond, crypto, child_process, promises, path, rxjs, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-9';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -151,7 +151,7 @@
151
151
  *
152
152
  * @public exported from `@promptbook/core`
153
153
  */
154
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
154
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
155
155
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
156
156
  /**
157
157
  * Where to store the temporary downloads
@@ -207,6 +207,21 @@
207
207
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
208
208
  */
209
209
 
210
+ /**
211
+ * Generates random token
212
+ *
213
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
214
+ *
215
+ * @private internal helper function
216
+ * @returns secure random token
217
+ */
218
+ function $randomToken(randomness) {
219
+ return crypto.randomBytes(randomness).toString('hex');
220
+ }
221
+ /**
222
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
223
+ */
224
+
210
225
  /**
211
226
  * This error indicates errors during the execution of the pipeline
212
227
  *
@@ -214,11 +229,17 @@
214
229
  */
215
230
  class PipelineExecutionError extends Error {
216
231
  constructor(message) {
232
+ // Added id parameter
217
233
  super(message);
218
234
  this.name = 'PipelineExecutionError';
235
+ // TODO: [🐙] DRY - Maybe $randomId
236
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
219
237
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
220
238
  }
221
239
  }
240
+ /**
241
+ * TODO: !!!!!! Add id to all errors
242
+ */
222
243
 
223
244
  /**
224
245
  * This error indicates problems parsing the format value
@@ -548,19 +569,21 @@
548
569
  */
549
570
  function serializeError(error) {
550
571
  const { name, message, stack } = error;
572
+ const { id } = error;
551
573
  if (!Object.keys(ALL_ERRORS).includes(name)) {
552
574
  console.error(spaceTrim__default["default"]((block) => `
553
-
575
+
554
576
  Cannot serialize error with name "${name}"
555
577
 
556
578
  ${block(stack || message)}
557
-
579
+
558
580
  `));
559
581
  }
560
582
  return {
561
583
  name: name,
562
584
  message,
563
585
  stack,
586
+ id, // Include id in the serialized object
564
587
  };
565
588
  }
566
589
 
@@ -1703,21 +1726,6 @@
1703
1726
  * - [♨] Are tasks prepared
1704
1727
  */
1705
1728
 
1706
- /**
1707
- * Generates random token
1708
- *
1709
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1710
- *
1711
- * @private internal helper function
1712
- * @returns secure random token
1713
- */
1714
- function $randomToken(randomness) {
1715
- return crypto.randomBytes(randomness).toString('hex');
1716
- }
1717
- /**
1718
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1719
- */
1720
-
1721
1729
  /**
1722
1730
  * Function isValidJsonString will tell you if the string is valid JSON or not
1723
1731
  *
@@ -1775,7 +1783,7 @@
1775
1783
  * @public exported from `@promptbook/utils`
1776
1784
  */
1777
1785
  function deserializeError(error) {
1778
- const { name, stack } = error;
1786
+ const { name, stack, id } = error; // Added id
1779
1787
  let { message } = error;
1780
1788
  let ErrorClass = ALL_ERRORS[error.name];
1781
1789
  if (ErrorClass === undefined) {
@@ -1790,7 +1798,9 @@
1790
1798
  ${block(stack || '')}
1791
1799
  `);
1792
1800
  }
1793
- return new ErrorClass(message);
1801
+ const deserializedError = new ErrorClass(message);
1802
+ deserializedError.id = id; // Assign id to the error object
1803
+ return deserializedError;
1794
1804
  }
1795
1805
 
1796
1806
  /**
@@ -1840,6 +1850,7 @@
1840
1850
  */
1841
1851
  function createTask(options) {
1842
1852
  const { taskType, taskProcessCallback } = options;
1853
+ // TODO: [🐙] DRY
1843
1854
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1844
1855
  let status = 'RUNNING';
1845
1856
  const createdAt = new Date();
@@ -1872,7 +1883,7 @@
1872
1883
  assertsTaskSuccessful(executionResult);
1873
1884
  status = 'FINISHED';
1874
1885
  currentValue = jsonStringsToJsons(executionResult);
1875
- // <- TODO: Convert JSON values in string to JSON objects
1886
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1876
1887
  partialResultSubject.next(executionResult);
1877
1888
  }
1878
1889
  catch (error) {
@@ -2516,8 +2527,9 @@
2516
2527
  * @returns LLM tools with same functionality with added total cost counting
2517
2528
  * @public exported from `@promptbook/core`
2518
2529
  */
2519
- function countTotalUsage(llmTools) {
2530
+ function countUsage(llmTools) {
2520
2531
  let totalUsage = ZERO_USAGE;
2532
+ const spending = new rxjs.Subject();
2521
2533
  const proxyTools = {
2522
2534
  get title() {
2523
2535
  // TODO: [🧠] Maybe put here some suffix
@@ -2527,12 +2539,15 @@
2527
2539
  // TODO: [🧠] Maybe put here some suffix
2528
2540
  return llmTools.description;
2529
2541
  },
2530
- async checkConfiguration() {
2542
+ checkConfiguration() {
2531
2543
  return /* not await */ llmTools.checkConfiguration();
2532
2544
  },
2533
2545
  listModels() {
2534
2546
  return /* not await */ llmTools.listModels();
2535
2547
  },
2548
+ spending() {
2549
+ return spending.asObservable();
2550
+ },
2536
2551
  getTotalUsage() {
2537
2552
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2538
2553
  return totalUsage;
@@ -2543,6 +2558,7 @@
2543
2558
  // console.info('[🚕] callChatModel through countTotalUsage');
2544
2559
  const promptResult = await llmTools.callChatModel(prompt);
2545
2560
  totalUsage = addUsage(totalUsage, promptResult.usage);
2561
+ spending.next(promptResult.usage);
2546
2562
  return promptResult;
2547
2563
  };
2548
2564
  }
@@ -2551,6 +2567,7 @@
2551
2567
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2552
2568
  const promptResult = await llmTools.callCompletionModel(prompt);
2553
2569
  totalUsage = addUsage(totalUsage, promptResult.usage);
2570
+ spending.next(promptResult.usage);
2554
2571
  return promptResult;
2555
2572
  };
2556
2573
  }
@@ -2559,6 +2576,7 @@
2559
2576
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2560
2577
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2561
2578
  totalUsage = addUsage(totalUsage, promptResult.usage);
2579
+ spending.next(promptResult.usage);
2562
2580
  return promptResult;
2563
2581
  };
2564
2582
  }
@@ -3841,7 +3859,7 @@
3841
3859
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3842
3860
  const _llms = arrayableToArray(tools.llm);
3843
3861
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3844
- const llmToolsWithUsage = countTotalUsage(llmTools);
3862
+ const llmToolsWithUsage = countUsage(llmTools);
3845
3863
  // <- TODO: [🌯]
3846
3864
  /*
3847
3865
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -4688,6 +4706,9 @@
4688
4706
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4689
4707
  return text.length;
4690
4708
  }
4709
+ /**
4710
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4711
+ */
4691
4712
 
4692
4713
  /**
4693
4714
  * Number of characters per standard line with 11pt Arial font size.
@@ -4719,6 +4740,9 @@
4719
4740
  const lines = text.split('\n');
4720
4741
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4721
4742
  }
4743
+ /**
4744
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4745
+ */
4722
4746
 
4723
4747
  /**
4724
4748
  * Counts number of pages in the text
@@ -4730,6 +4754,9 @@
4730
4754
  function countPages(text) {
4731
4755
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4732
4756
  }
4757
+ /**
4758
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4759
+ */
4733
4760
 
4734
4761
  /**
4735
4762
  * Counts number of paragraphs in the text
@@ -4739,6 +4766,9 @@
4739
4766
  function countParagraphs(text) {
4740
4767
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4741
4768
  }
4769
+ /**
4770
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4771
+ */
4742
4772
 
4743
4773
  /**
4744
4774
  * Split text into sentences
@@ -4756,6 +4786,9 @@
4756
4786
  function countSentences(text) {
4757
4787
  return splitIntoSentences(text).length;
4758
4788
  }
4789
+ /**
4790
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4791
+ */
4759
4792
 
4760
4793
  /**
4761
4794
  * Counts number of words in the text
@@ -4769,6 +4802,9 @@
4769
4802
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4770
4803
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4771
4804
  }
4805
+ /**
4806
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4807
+ */
4772
4808
 
4773
4809
  /**
4774
4810
  * Index of all counter functions