@promptbook/remote-server 0.88.0-8 → 0.88.0

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.
@@ -62,6 +62,7 @@ import { clonePipeline } from '../utils/serialization/clonePipeline';
62
62
  import { deepClone } from '../utils/serialization/deepClone';
63
63
  import { exportJson } from '../utils/serialization/exportJson';
64
64
  import { isSerializableAsJson } from '../utils/serialization/isSerializableAsJson';
65
+ import { jsonStringsToJsons } from '../utils/serialization/jsonStringsToJsons';
65
66
  import { difference } from '../utils/sets/difference';
66
67
  import { intersection } from '../utils/sets/intersection';
67
68
  import { union } from '../utils/sets/union';
@@ -143,6 +144,7 @@ export { clonePipeline };
143
144
  export { deepClone };
144
145
  export { exportJson };
145
146
  export { isSerializableAsJson };
147
+ export { jsonStringsToJsons };
146
148
  export { difference };
147
149
  export { intersection };
148
150
  export { union };
@@ -162,7 +162,7 @@ export declare const DEFAULT_MAX_PARALLEL_COUNT = 5;
162
162
  *
163
163
  * @public exported from `@promptbook/core`
164
164
  */
165
- export declare const DEFAULT_MAX_EXECUTION_ATTEMPTS = 3;
165
+ export declare const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10;
166
166
  /**
167
167
  * @@@
168
168
  * TODO: [🐝][main] !!3 Use
@@ -1,3 +1,4 @@
1
+ import type { task_id } from '../types/typeAliases';
1
2
  /**
2
3
  * This error indicates errors during the execution of the pipeline
3
4
  *
@@ -5,5 +6,9 @@
5
6
  */
6
7
  export declare class PipelineExecutionError extends Error {
7
8
  readonly name = "PipelineExecutionError";
9
+ readonly id?: task_id;
8
10
  constructor(message: string);
9
11
  }
12
+ /**
13
+ * TODO: !!!!!! Add id to all errors
14
+ */
@@ -1,3 +1,4 @@
1
+ import type { task_id } from '../../types/typeAliases';
1
2
  import type { ALL_ERRORS } from '../0-index';
2
3
  /**
3
4
  * Represents a serialized error or custom Promptbook error
@@ -5,6 +6,10 @@ import type { ALL_ERRORS } from '../0-index';
5
6
  * Note: [🚉] This is fully serializable as JSON
6
7
  */
7
8
  export type ErrorJson = {
9
+ /**
10
+ * The unique identifier of the error
11
+ */
12
+ readonly id?: task_id;
8
13
  /**
9
14
  * The type of the error
10
15
  */
@@ -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
+ */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Recursively converts JSON strings to JSON objects
3
+
4
+ * @public exported from `@promptbook/utils`
5
+ */
6
+ export declare function jsonStringsToJsons<T>(object: T): T;
7
+ /**
8
+ * TODO: Type the return type correctly
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.88.0-8",
3
+ "version": "0.88.0",
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-8"
50
+ "@promptbook/core": "0.88.0"
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-8';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
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
 
@@ -1704,18 +1727,54 @@
1704
1727
  */
1705
1728
 
1706
1729
  /**
1707
- * Generates random token
1708
- *
1709
- * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
1730
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1710
1731
  *
1711
- * @private internal helper function
1712
- * @returns secure random token
1732
+ * @public exported from `@promptbook/utils`
1713
1733
  */
1714
- function $randomToken(randomness) {
1715
- return crypto.randomBytes(randomness).toString('hex');
1734
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1735
+ try {
1736
+ JSON.parse(value);
1737
+ return true;
1738
+ }
1739
+ catch (error) {
1740
+ if (!(error instanceof Error)) {
1741
+ throw error;
1742
+ }
1743
+ if (error.message.includes('Unexpected token')) {
1744
+ return false;
1745
+ }
1746
+ return false;
1747
+ }
1716
1748
  }
1749
+
1717
1750
  /**
1718
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1751
+ * Recursively converts JSON strings to JSON objects
1752
+
1753
+ * @public exported from `@promptbook/utils`
1754
+ */
1755
+ function jsonStringsToJsons(object) {
1756
+ if (object === null) {
1757
+ return object;
1758
+ }
1759
+ if (Array.isArray(object)) {
1760
+ return object.map(jsonStringsToJsons);
1761
+ }
1762
+ if (typeof object !== 'object') {
1763
+ return object;
1764
+ }
1765
+ const newObject = { ...object };
1766
+ for (const [key, value] of Object.entries(object)) {
1767
+ if (typeof value === 'string' && isValidJsonString(value)) {
1768
+ newObject[key] = JSON.parse(value);
1769
+ }
1770
+ else {
1771
+ newObject[key] = jsonStringsToJsons(value);
1772
+ }
1773
+ }
1774
+ return newObject;
1775
+ }
1776
+ /**
1777
+ * TODO: Type the return type correctly
1719
1778
  */
1720
1779
 
1721
1780
  /**
@@ -1724,7 +1783,7 @@
1724
1783
  * @public exported from `@promptbook/utils`
1725
1784
  */
1726
1785
  function deserializeError(error) {
1727
- const { name, stack } = error;
1786
+ const { name, stack, id } = error; // Added id
1728
1787
  let { message } = error;
1729
1788
  let ErrorClass = ALL_ERRORS[error.name];
1730
1789
  if (ErrorClass === undefined) {
@@ -1739,7 +1798,9 @@
1739
1798
  ${block(stack || '')}
1740
1799
  `);
1741
1800
  }
1742
- return new ErrorClass(message);
1801
+ const deserializedError = new ErrorClass(message);
1802
+ deserializedError.id = id; // Assign id to the error object
1803
+ return deserializedError;
1743
1804
  }
1744
1805
 
1745
1806
  /**
@@ -1789,17 +1850,19 @@
1789
1850
  */
1790
1851
  function createTask(options) {
1791
1852
  const { taskType, taskProcessCallback } = options;
1853
+ // TODO: [🐙] DRY
1792
1854
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1793
1855
  let status = 'RUNNING';
1794
1856
  const createdAt = new Date();
1795
1857
  let updatedAt = createdAt;
1796
1858
  const errors = [];
1797
1859
  const warnings = [];
1798
- const currentValue = {};
1860
+ let currentValue = {};
1799
1861
  const partialResultSubject = new rxjs.Subject();
1800
1862
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1801
1863
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1802
1864
  Object.assign(currentValue, newOngoingResult);
1865
+ // <- TODO: assign deep
1803
1866
  partialResultSubject.next(newOngoingResult);
1804
1867
  });
1805
1868
  finalResultPromise
@@ -1819,7 +1882,8 @@
1819
1882
  // And delete `ExecutionTask.currentValue.preparedPipeline`
1820
1883
  assertsTaskSuccessful(executionResult);
1821
1884
  status = 'FINISHED';
1822
- Object.assign(currentValue, executionResult);
1885
+ currentValue = jsonStringsToJsons(executionResult);
1886
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1823
1887
  partialResultSubject.next(executionResult);
1824
1888
  }
1825
1889
  catch (error) {
@@ -1942,27 +2006,6 @@
1942
2006
  * TODO: [🍏] Implement for MacOs
1943
2007
  */
1944
2008
 
1945
- /**
1946
- * Function isValidJsonString will tell you if the string is valid JSON or not
1947
- *
1948
- * @public exported from `@promptbook/utils`
1949
- */
1950
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
1951
- try {
1952
- JSON.parse(value);
1953
- return true;
1954
- }
1955
- catch (error) {
1956
- if (!(error instanceof Error)) {
1957
- throw error;
1958
- }
1959
- if (error.message.includes('Unexpected token')) {
1960
- return false;
1961
- }
1962
- return false;
1963
- }
1964
- }
1965
-
1966
2009
  /**
1967
2010
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1968
2011
  * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
@@ -4656,6 +4699,9 @@
4656
4699
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4657
4700
  return text.length;
4658
4701
  }
4702
+ /**
4703
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4704
+ */
4659
4705
 
4660
4706
  /**
4661
4707
  * Number of characters per standard line with 11pt Arial font size.
@@ -4687,6 +4733,9 @@
4687
4733
  const lines = text.split('\n');
4688
4734
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4689
4735
  }
4736
+ /**
4737
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4738
+ */
4690
4739
 
4691
4740
  /**
4692
4741
  * Counts number of pages in the text
@@ -4698,6 +4747,9 @@
4698
4747
  function countPages(text) {
4699
4748
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4700
4749
  }
4750
+ /**
4751
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4752
+ */
4701
4753
 
4702
4754
  /**
4703
4755
  * Counts number of paragraphs in the text
@@ -4707,6 +4759,9 @@
4707
4759
  function countParagraphs(text) {
4708
4760
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4709
4761
  }
4762
+ /**
4763
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4764
+ */
4710
4765
 
4711
4766
  /**
4712
4767
  * Split text into sentences
@@ -4724,6 +4779,9 @@
4724
4779
  function countSentences(text) {
4725
4780
  return splitIntoSentences(text).length;
4726
4781
  }
4782
+ /**
4783
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4784
+ */
4727
4785
 
4728
4786
  /**
4729
4787
  * Counts number of words in the text
@@ -4737,6 +4795,9 @@
4737
4795
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4738
4796
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4739
4797
  }
4798
+ /**
4799
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4800
+ */
4740
4801
 
4741
4802
  /**
4742
4803
  * Index of all counter functions