@promptbook/markdown-utils 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 +1 -1
  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/markdown-utils",
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,
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('spacetrim'), require('prettier'), require('prettier/parser-html'), require('rxjs'), require('crypto'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'rxjs', 'crypto', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.rxjs, global.crypto, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, spaceTrim, prettier, parserHtml, rxjs, crypto, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, spaceTrim, prettier, parserHtml, crypto, rxjs, waitasecond, hexEncoder, sha256, path, 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
 
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-9';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -659,7 +659,7 @@
659
659
  *
660
660
  * @public exported from `@promptbook/core`
661
661
  */
662
- const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3; // <- TODO: [🤹‍♂️]
662
+ const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
663
663
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
664
664
  /**
665
665
  * Where to store the temporary downloads
@@ -1676,6 +1676,21 @@
1676
1676
  }
1677
1677
  }
1678
1678
 
1679
+ /**
1680
+ * Generates random token
1681
+ *
1682
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1683
+ *
1684
+ * @private internal helper function
1685
+ * @returns secure random token
1686
+ */
1687
+ function $randomToken(randomness) {
1688
+ return crypto.randomBytes(randomness).toString('hex');
1689
+ }
1690
+ /**
1691
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1692
+ */
1693
+
1679
1694
  /**
1680
1695
  * This error indicates errors during the execution of the pipeline
1681
1696
  *
@@ -1683,11 +1698,17 @@
1683
1698
  */
1684
1699
  class PipelineExecutionError extends Error {
1685
1700
  constructor(message) {
1701
+ // Added id parameter
1686
1702
  super(message);
1687
1703
  this.name = 'PipelineExecutionError';
1704
+ // TODO: [🐙] DRY - Maybe $randomId
1705
+ this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1688
1706
  Object.setPrototypeOf(this, PipelineExecutionError.prototype);
1689
1707
  }
1690
1708
  }
1709
+ /**
1710
+ * TODO: !!!!!! Add id to all errors
1711
+ */
1691
1712
 
1692
1713
  /**
1693
1714
  * Determine if the pipeline is fully prepared
@@ -1726,21 +1747,6 @@
1726
1747
  * - [♨] Are tasks prepared
1727
1748
  */
1728
1749
 
1729
- /**
1730
- * Generates random token
1731
- *
1732
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1733
- *
1734
- * @private internal helper function
1735
- * @returns secure random token
1736
- */
1737
- function $randomToken(randomness) {
1738
- return crypto.randomBytes(randomness).toString('hex');
1739
- }
1740
- /**
1741
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1742
- */
1743
-
1744
1750
  /**
1745
1751
  * Recursively converts JSON strings to JSON objects
1746
1752
 
@@ -1957,7 +1963,7 @@
1957
1963
  * @public exported from `@promptbook/utils`
1958
1964
  */
1959
1965
  function deserializeError(error) {
1960
- const { name, stack } = error;
1966
+ const { name, stack, id } = error; // Added id
1961
1967
  let { message } = error;
1962
1968
  let ErrorClass = ALL_ERRORS[error.name];
1963
1969
  if (ErrorClass === undefined) {
@@ -1972,7 +1978,9 @@
1972
1978
  ${block(stack || '')}
1973
1979
  `);
1974
1980
  }
1975
- return new ErrorClass(message);
1981
+ const deserializedError = new ErrorClass(message);
1982
+ deserializedError.id = id; // Assign id to the error object
1983
+ return deserializedError;
1976
1984
  }
1977
1985
 
1978
1986
  /**
@@ -2022,6 +2030,7 @@
2022
2030
  */
2023
2031
  function createTask(options) {
2024
2032
  const { taskType, taskProcessCallback } = options;
2033
+ // TODO: [🐙] DRY
2025
2034
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2026
2035
  let status = 'RUNNING';
2027
2036
  const createdAt = new Date();
@@ -2054,7 +2063,7 @@
2054
2063
  assertsTaskSuccessful(executionResult);
2055
2064
  status = 'FINISHED';
2056
2065
  currentValue = jsonStringsToJsons(executionResult);
2057
- // <- TODO: Convert JSON values in string to JSON objects
2066
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
2058
2067
  partialResultSubject.next(executionResult);
2059
2068
  }
2060
2069
  catch (error) {
@@ -2118,19 +2127,21 @@
2118
2127
  */
2119
2128
  function serializeError(error) {
2120
2129
  const { name, message, stack } = error;
2130
+ const { id } = error;
2121
2131
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2122
2132
  console.error(spaceTrim__default["default"]((block) => `
2123
-
2133
+
2124
2134
  Cannot serialize error with name "${name}"
2125
2135
 
2126
2136
  ${block(stack || message)}
2127
-
2137
+
2128
2138
  `));
2129
2139
  }
2130
2140
  return {
2131
2141
  name: name,
2132
2142
  message,
2133
2143
  stack,
2144
+ id, // Include id in the serialized object
2134
2145
  };
2135
2146
  }
2136
2147
 
@@ -2273,8 +2284,9 @@
2273
2284
  * @returns LLM tools with same functionality with added total cost counting
2274
2285
  * @public exported from `@promptbook/core`
2275
2286
  */
2276
- function countTotalUsage(llmTools) {
2287
+ function countUsage(llmTools) {
2277
2288
  let totalUsage = ZERO_USAGE;
2289
+ const spending = new rxjs.Subject();
2278
2290
  const proxyTools = {
2279
2291
  get title() {
2280
2292
  // TODO: [🧠] Maybe put here some suffix
@@ -2284,12 +2296,15 @@
2284
2296
  // TODO: [🧠] Maybe put here some suffix
2285
2297
  return llmTools.description;
2286
2298
  },
2287
- async checkConfiguration() {
2299
+ checkConfiguration() {
2288
2300
  return /* not await */ llmTools.checkConfiguration();
2289
2301
  },
2290
2302
  listModels() {
2291
2303
  return /* not await */ llmTools.listModels();
2292
2304
  },
2305
+ spending() {
2306
+ return spending.asObservable();
2307
+ },
2293
2308
  getTotalUsage() {
2294
2309
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
2295
2310
  return totalUsage;
@@ -2300,6 +2315,7 @@
2300
2315
  // console.info('[🚕] callChatModel through countTotalUsage');
2301
2316
  const promptResult = await llmTools.callChatModel(prompt);
2302
2317
  totalUsage = addUsage(totalUsage, promptResult.usage);
2318
+ spending.next(promptResult.usage);
2303
2319
  return promptResult;
2304
2320
  };
2305
2321
  }
@@ -2308,6 +2324,7 @@
2308
2324
  // console.info('[🚕] callCompletionModel through countTotalUsage');
2309
2325
  const promptResult = await llmTools.callCompletionModel(prompt);
2310
2326
  totalUsage = addUsage(totalUsage, promptResult.usage);
2327
+ spending.next(promptResult.usage);
2311
2328
  return promptResult;
2312
2329
  };
2313
2330
  }
@@ -2316,6 +2333,7 @@
2316
2333
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
2317
2334
  const promptResult = await llmTools.callEmbeddingModel(prompt);
2318
2335
  totalUsage = addUsage(totalUsage, promptResult.usage);
2336
+ spending.next(promptResult.usage);
2319
2337
  return promptResult;
2320
2338
  };
2321
2339
  }
@@ -3598,7 +3616,7 @@
3598
3616
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
3599
3617
  const _llms = arrayableToArray(tools.llm);
3600
3618
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
3601
- const llmToolsWithUsage = countTotalUsage(llmTools);
3619
+ const llmToolsWithUsage = countUsage(llmTools);
3602
3620
  // <- TODO: [🌯]
3603
3621
  /*
3604
3622
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -4326,6 +4344,9 @@
4326
4344
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4327
4345
  return text.length;
4328
4346
  }
4347
+ /**
4348
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4349
+ */
4329
4350
 
4330
4351
  /**
4331
4352
  * Number of characters per standard line with 11pt Arial font size.
@@ -4357,6 +4378,9 @@
4357
4378
  const lines = text.split('\n');
4358
4379
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4359
4380
  }
4381
+ /**
4382
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4383
+ */
4360
4384
 
4361
4385
  /**
4362
4386
  * Counts number of pages in the text
@@ -4368,6 +4392,9 @@
4368
4392
  function countPages(text) {
4369
4393
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4370
4394
  }
4395
+ /**
4396
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4397
+ */
4371
4398
 
4372
4399
  /**
4373
4400
  * Counts number of paragraphs in the text
@@ -4377,6 +4404,9 @@
4377
4404
  function countParagraphs(text) {
4378
4405
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4379
4406
  }
4407
+ /**
4408
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4409
+ */
4380
4410
 
4381
4411
  /**
4382
4412
  * Split text into sentences
@@ -4394,6 +4424,9 @@
4394
4424
  function countSentences(text) {
4395
4425
  return splitIntoSentences(text).length;
4396
4426
  }
4427
+ /**
4428
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4429
+ */
4397
4430
 
4398
4431
  /**
4399
4432
  * Counts number of words in the text
@@ -4407,6 +4440,9 @@
4407
4440
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4408
4441
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4409
4442
  }
4443
+ /**
4444
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4445
+ */
4410
4446
 
4411
4447
  /**
4412
4448
  * Index of all counter functions