@promptbook/remote-server 0.88.0-8 → 0.88.0-9

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 };
@@ -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-9",
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-9"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -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-9';
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
@@ -1718,6 +1718,57 @@
1718
1718
  * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1719
1719
  */
1720
1720
 
1721
+ /**
1722
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1723
+ *
1724
+ * @public exported from `@promptbook/utils`
1725
+ */
1726
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1727
+ try {
1728
+ JSON.parse(value);
1729
+ return true;
1730
+ }
1731
+ catch (error) {
1732
+ if (!(error instanceof Error)) {
1733
+ throw error;
1734
+ }
1735
+ if (error.message.includes('Unexpected token')) {
1736
+ return false;
1737
+ }
1738
+ return false;
1739
+ }
1740
+ }
1741
+
1742
+ /**
1743
+ * Recursively converts JSON strings to JSON objects
1744
+
1745
+ * @public exported from `@promptbook/utils`
1746
+ */
1747
+ function jsonStringsToJsons(object) {
1748
+ if (object === null) {
1749
+ return object;
1750
+ }
1751
+ if (Array.isArray(object)) {
1752
+ return object.map(jsonStringsToJsons);
1753
+ }
1754
+ if (typeof object !== 'object') {
1755
+ return object;
1756
+ }
1757
+ const newObject = { ...object };
1758
+ for (const [key, value] of Object.entries(object)) {
1759
+ if (typeof value === 'string' && isValidJsonString(value)) {
1760
+ newObject[key] = JSON.parse(value);
1761
+ }
1762
+ else {
1763
+ newObject[key] = jsonStringsToJsons(value);
1764
+ }
1765
+ }
1766
+ return newObject;
1767
+ }
1768
+ /**
1769
+ * TODO: Type the return type correctly
1770
+ */
1771
+
1721
1772
  /**
1722
1773
  * Deserializes the error object
1723
1774
  *
@@ -1795,11 +1846,12 @@
1795
1846
  let updatedAt = createdAt;
1796
1847
  const errors = [];
1797
1848
  const warnings = [];
1798
- const currentValue = {};
1849
+ let currentValue = {};
1799
1850
  const partialResultSubject = new rxjs.Subject();
1800
1851
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1801
1852
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1802
1853
  Object.assign(currentValue, newOngoingResult);
1854
+ // <- TODO: assign deep
1803
1855
  partialResultSubject.next(newOngoingResult);
1804
1856
  });
1805
1857
  finalResultPromise
@@ -1819,7 +1871,8 @@
1819
1871
  // And delete `ExecutionTask.currentValue.preparedPipeline`
1820
1872
  assertsTaskSuccessful(executionResult);
1821
1873
  status = 'FINISHED';
1822
- Object.assign(currentValue, executionResult);
1874
+ currentValue = jsonStringsToJsons(executionResult);
1875
+ // <- TODO: Convert JSON values in string to JSON objects
1823
1876
  partialResultSubject.next(executionResult);
1824
1877
  }
1825
1878
  catch (error) {
@@ -1942,27 +1995,6 @@
1942
1995
  * TODO: [🍏] Implement for MacOs
1943
1996
  */
1944
1997
 
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
1998
  /**
1967
1999
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1968
2000
  * 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.