@promptbook/utils 0.79.0 → 0.80.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 (40) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +278 -205
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +6 -6
  5. package/esm/typings/src/_packages/core.index.d.ts +8 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
  9. package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
  10. package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
  11. package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -1
  12. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
  13. package/esm/typings/src/config.d.ts +0 -25
  14. package/esm/typings/src/constants.d.ts +35 -0
  15. package/esm/typings/src/conversion/{pipelineStringToJson.d.ts → compilePipeline.d.ts} +3 -3
  16. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
  17. package/esm/typings/src/conversion/{pipelineStringToJsonSync.d.ts → precompilePipeline.d.ts} +4 -3
  18. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
  19. package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
  20. package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
  21. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
  22. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  23. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  24. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
  25. package/esm/typings/src/prepare/unpreparePipeline.d.ts +1 -0
  26. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  27. package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
  28. package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
  29. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
  30. package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
  31. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
  32. package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
  33. package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
  34. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
  35. package/package.json +3 -2
  36. package/umd/index.umd.js +279 -204
  37. package/umd/index.umd.js.map +1 -1
  38. package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
  39. /package/esm/typings/src/conversion/{pipelineStringToJson.test.d.ts → compilePipeline.test.d.ts} +0 -0
  40. /package/esm/typings/src/conversion/{pipelineStringToJsonSync.test.d.ts → precompilePipeline.test.d.ts} +0 -0
package/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/utils`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -13,7 +13,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
13
13
  *
14
14
  * @see https://github.com/webgptorg/promptbook
15
15
  */
16
- var PROMPTBOOK_ENGINE_VERSION = '0.78.4';
16
+ var PROMPTBOOK_ENGINE_VERSION = '0.80.0-0';
17
17
  /**
18
18
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
19
19
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -165,24 +165,6 @@ var ADMIN_GITHUB_NAME = 'hejny';
165
165
  * @private within the repository - too low-level in comparison with other `MAX_...`
166
166
  */
167
167
  var LOOP_LIMIT = 1000;
168
- /**
169
- * Nonce which is used for replacing things in strings
170
- *
171
- * @private within the repository
172
- */
173
- var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
174
- /**
175
- * @@@
176
- *
177
- * @private within the repository
178
- */
179
- var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
180
- /**
181
- * @@@
182
- *
183
- * @private within the repository
184
- */
185
- var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
186
168
  // <- TODO: [🧜‍♂️]
187
169
  /**
188
170
  * @@@
@@ -196,7 +178,6 @@ Object.freeze({
196
178
  skipEmptyLines: true,
197
179
  });
198
180
  /**
199
- * TODO: Extract `constants.ts` from `config.ts`
200
181
  * Note: [💞] Ignore a discrepancy between file name and entity name
201
182
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
202
183
  */
@@ -1605,6 +1586,18 @@ function normalizeWhitespaces(sentence) {
1605
1586
  return sentence.replace(/\s+/gs, ' ').trim();
1606
1587
  }
1607
1588
 
1589
+ /**
1590
+ * Orders JSON object by keys
1591
+ *
1592
+ * @returns The same type of object as the input re-ordered
1593
+ * @public exported from `@promptbook/utils`
1594
+ */
1595
+ function orderJson(options) {
1596
+ var value = options.value, order = options.order;
1597
+ var orderedValue = __assign(__assign({}, (order === undefined ? {} : Object.fromEntries(order.map(function (key) { return [key, undefined]; })))), value);
1598
+ return orderedValue;
1599
+ }
1600
+
1608
1601
  /**
1609
1602
  * Parses keywords from any object and recursively walks through
1610
1603
  *
@@ -1710,6 +1703,268 @@ function extractParameterNames(template) {
1710
1703
  return parameterNames;
1711
1704
  }
1712
1705
 
1706
+ /**
1707
+ * Freezes the given object and all its nested objects recursively
1708
+ *
1709
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
1710
+ * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1711
+ *
1712
+ * @returns The same object as the input, but deeply frozen
1713
+ * @public exported from `@promptbook/utils`
1714
+ */
1715
+ function $deepFreeze(objectValue) {
1716
+ var e_1, _a;
1717
+ if (Array.isArray(objectValue)) {
1718
+ return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
1719
+ }
1720
+ var propertyNames = Object.getOwnPropertyNames(objectValue);
1721
+ try {
1722
+ for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1723
+ var propertyName = propertyNames_1_1.value;
1724
+ var value = objectValue[propertyName];
1725
+ if (value && typeof value === 'object') {
1726
+ $deepFreeze(value);
1727
+ }
1728
+ }
1729
+ }
1730
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1731
+ finally {
1732
+ try {
1733
+ if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1734
+ }
1735
+ finally { if (e_1) throw e_1.error; }
1736
+ }
1737
+ Object.freeze(objectValue);
1738
+ return objectValue;
1739
+ }
1740
+ /**
1741
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1742
+ */
1743
+
1744
+ /**
1745
+ * Checks if the value is [🚉] serializable as JSON
1746
+ * If not, throws an UnexpectedError with a rich error message and tracking
1747
+ *
1748
+ * - Almost all primitives are serializable BUT:
1749
+ * - `undefined` is not serializable
1750
+ * - `NaN` is not serializable
1751
+ * - Objects and arrays are serializable if all their properties are serializable
1752
+ * - Functions are not serializable
1753
+ * - Circular references are not serializable
1754
+ * - `Date` objects are not serializable
1755
+ * - `Map` and `Set` objects are not serializable
1756
+ * - `RegExp` objects are not serializable
1757
+ * - `Error` objects are not serializable
1758
+ * - `Symbol` objects are not serializable
1759
+ * - And much more...
1760
+ *
1761
+ * @throws UnexpectedError if the value is not serializable as JSON
1762
+ * @public exported from `@promptbook/utils`
1763
+ */
1764
+ function checkSerializableAsJson(options) {
1765
+ var e_1, _a;
1766
+ var value = options.value, name = options.name, message = options.message;
1767
+ if (value === undefined) {
1768
+ throw new UnexpectedError("".concat(name, " is undefined"));
1769
+ }
1770
+ else if (value === null) {
1771
+ return;
1772
+ }
1773
+ else if (typeof value === 'boolean') {
1774
+ return;
1775
+ }
1776
+ else if (typeof value === 'number' && !isNaN(value)) {
1777
+ return;
1778
+ }
1779
+ else if (typeof value === 'string') {
1780
+ return;
1781
+ }
1782
+ else if (typeof value === 'symbol') {
1783
+ throw new UnexpectedError("".concat(name, " is symbol"));
1784
+ }
1785
+ else if (typeof value === 'function') {
1786
+ throw new UnexpectedError("".concat(name, " is function"));
1787
+ }
1788
+ else if (typeof value === 'object' && Array.isArray(value)) {
1789
+ for (var i = 0; i < value.length; i++) {
1790
+ checkSerializableAsJson({ name: "".concat(name, "[").concat(i, "]"), value: value[i], message: message });
1791
+ }
1792
+ }
1793
+ else if (typeof value === 'object') {
1794
+ if (value instanceof Date) {
1795
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is Date\n\n Use `string_date_iso8601` instead\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1796
+ }
1797
+ else if (value instanceof Map) {
1798
+ throw new UnexpectedError("".concat(name, " is Map"));
1799
+ }
1800
+ else if (value instanceof Set) {
1801
+ throw new UnexpectedError("".concat(name, " is Set"));
1802
+ }
1803
+ else if (value instanceof RegExp) {
1804
+ throw new UnexpectedError("".concat(name, " is RegExp"));
1805
+ }
1806
+ else if (value instanceof Error) {
1807
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is unserialized Error\n\n Use function `serializeError`\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n\n "); }));
1808
+ }
1809
+ else {
1810
+ try {
1811
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1812
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1813
+ if (subValue === undefined) {
1814
+ // Note: undefined in object is serializable - it is just omited
1815
+ continue;
1816
+ }
1817
+ checkSerializableAsJson({ name: "".concat(name, ".").concat(subName), value: subValue, message: message });
1818
+ }
1819
+ }
1820
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1821
+ finally {
1822
+ try {
1823
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1824
+ }
1825
+ finally { if (e_1) throw e_1.error; }
1826
+ }
1827
+ try {
1828
+ JSON.stringify(value); // <- TODO: [0]
1829
+ }
1830
+ catch (error) {
1831
+ if (!(error instanceof Error)) {
1832
+ throw error;
1833
+ }
1834
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1835
+ }
1836
+ /*
1837
+ TODO: [0] Is there some more elegant way to check circular references?
1838
+ const seen = new Set();
1839
+ const stack = [{ value }];
1840
+ while (stack.length > 0) {
1841
+ const { value } = stack.pop()!;
1842
+ if (typeof value === 'object' && value !== null) {
1843
+ if (seen.has(value)) {
1844
+ throw new UnexpectedError(`${name} has circular reference`);
1845
+ }
1846
+ seen.add(value);
1847
+ if (Array.isArray(value)) {
1848
+ stack.push(...value.map((value) => ({ value })));
1849
+ } else {
1850
+ stack.push(...Object.values(value).map((value) => ({ value })));
1851
+ }
1852
+ }
1853
+ }
1854
+ */
1855
+ return;
1856
+ }
1857
+ }
1858
+ else {
1859
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is unknown type\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1860
+ }
1861
+ }
1862
+ /**
1863
+ * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
1864
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1865
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1866
+ */
1867
+
1868
+ /**
1869
+ * @@@
1870
+ *
1871
+ * @public exported from `@promptbook/utils`
1872
+ */
1873
+ function deepClone(objectValue) {
1874
+ return JSON.parse(JSON.stringify(objectValue));
1875
+ /*
1876
+ !!!!!!!!
1877
+ TODO: [🧠] Is there a better implementation?
1878
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
1879
+ > for (const propertyName of propertyNames) {
1880
+ > const value = (objectValue as really_any)[propertyName];
1881
+ > if (value && typeof value === 'object') {
1882
+ > deepClone(value);
1883
+ > }
1884
+ > }
1885
+ > return Object.assign({}, objectValue);
1886
+ */
1887
+ }
1888
+ /**
1889
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1890
+ */
1891
+
1892
+ /**
1893
+ * Utility to export a JSON object from a function
1894
+ *
1895
+ * 1) Checks if the value is serializable as JSON
1896
+ * 2) Makes a deep clone of the object
1897
+ * 2) Orders the object properties
1898
+ * 2) Deeply freezes the cloned object
1899
+ *
1900
+ * Note: This function does not mutates the given object
1901
+ *
1902
+ * @returns The same type of object as the input but read-only and re-ordered
1903
+ * @public exported from `@promptbook/utils`
1904
+ */
1905
+ function exportJson(options) {
1906
+ var name = options.name, value = options.value, order = options.order, message = options.message;
1907
+ checkSerializableAsJson({ name: name, value: value, message: message });
1908
+ var orderedValue =
1909
+ // TODO: Fix error "Type instantiation is excessively deep and possibly infinite."
1910
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1911
+ // @ts-ignore
1912
+ order === undefined
1913
+ ? deepClone(value)
1914
+ : orderJson({
1915
+ value: value,
1916
+ // <- Note: checkSerializableAsJson asserts that the value is serializable as JSON
1917
+ order: order,
1918
+ });
1919
+ $deepFreeze(orderedValue);
1920
+ return orderedValue;
1921
+ }
1922
+ /**
1923
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
1924
+ */
1925
+
1926
+ /**
1927
+ * Nonce which is used for replacing things in strings
1928
+ *
1929
+ * @private within the repository
1930
+ */
1931
+ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
1932
+ /**
1933
+ * @@@
1934
+ *
1935
+ * @private within the repository
1936
+ */
1937
+ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
1938
+ /**
1939
+ * @@@
1940
+ *
1941
+ * @private within the repository
1942
+ */
1943
+ var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1944
+ /**
1945
+ * The names of the parameters that are reserved for special purposes
1946
+ *
1947
+ * @public exported from `@promptbook/core`
1948
+ */
1949
+ exportJson({
1950
+ name: 'RESERVED_PARAMETER_NAMES',
1951
+ message: "The names of the parameters that are reserved for special purposes",
1952
+ value: [
1953
+ 'content',
1954
+ 'context',
1955
+ 'knowledge',
1956
+ 'examples',
1957
+ 'modelName',
1958
+ 'currentDate',
1959
+ // <- TODO: list here all command names
1960
+ // <- TODO: Add more like 'date', 'modelName',...
1961
+ // <- TODO: Add [emoji] + instructions ACRY when adding new reserved parameter
1962
+ ],
1963
+ });
1964
+ /**
1965
+ * Note: [💞] Ignore a discrepancy between file name and entity name
1966
+ */
1967
+
1713
1968
  /**
1714
1969
  * Replaces parameters in template with values from parameters object
1715
1970
  *
@@ -1891,166 +2146,6 @@ function removeQuotes(text) {
1891
2146
  return text;
1892
2147
  }
1893
2148
 
1894
- /**
1895
- * @@@
1896
- *
1897
- * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
1898
- * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
1899
- *
1900
- * @returns The same object as the input, but deeply frozen
1901
- * @public exported from `@promptbook/utils`
1902
- */
1903
- function $deepFreeze(objectValue) {
1904
- var e_1, _a;
1905
- if (Array.isArray(objectValue)) {
1906
- return Object.freeze(objectValue.map(function (item) { return $deepFreeze(item); }));
1907
- }
1908
- var propertyNames = Object.getOwnPropertyNames(objectValue);
1909
- try {
1910
- for (var propertyNames_1 = __values(propertyNames), propertyNames_1_1 = propertyNames_1.next(); !propertyNames_1_1.done; propertyNames_1_1 = propertyNames_1.next()) {
1911
- var propertyName = propertyNames_1_1.value;
1912
- var value = objectValue[propertyName];
1913
- if (value && typeof value === 'object') {
1914
- $deepFreeze(value);
1915
- }
1916
- }
1917
- }
1918
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1919
- finally {
1920
- try {
1921
- if (propertyNames_1_1 && !propertyNames_1_1.done && (_a = propertyNames_1.return)) _a.call(propertyNames_1);
1922
- }
1923
- finally { if (e_1) throw e_1.error; }
1924
- }
1925
- return Object.freeze(objectValue);
1926
- }
1927
- /**
1928
- * TODO: [🧠] Is there a way how to meaningfully test this utility
1929
- */
1930
-
1931
- /**
1932
- * Checks if the value is [🚉] serializable as JSON
1933
- * If not, throws an UnexpectedError with a rich error message and tracking
1934
- *
1935
- * - Almost all primitives are serializable BUT:
1936
- * - `undefined` is not serializable
1937
- * - `NaN` is not serializable
1938
- * - Objects and arrays are serializable if all their properties are serializable
1939
- * - Functions are not serializable
1940
- * - Circular references are not serializable
1941
- * - `Date` objects are not serializable
1942
- * - `Map` and `Set` objects are not serializable
1943
- * - `RegExp` objects are not serializable
1944
- * - `Error` objects are not serializable
1945
- * - `Symbol` objects are not serializable
1946
- * - And much more...
1947
- *
1948
- * @throws UnexpectedError if the value is not serializable as JSON
1949
- * @public exported from `@promptbook/utils`
1950
- */
1951
- function checkSerializableAsJson(name, value) {
1952
- var e_1, _a;
1953
- if (value === undefined) {
1954
- throw new UnexpectedError("".concat(name, " is undefined"));
1955
- }
1956
- else if (value === null) {
1957
- return;
1958
- }
1959
- else if (typeof value === 'boolean') {
1960
- return;
1961
- }
1962
- else if (typeof value === 'number' && !isNaN(value)) {
1963
- return;
1964
- }
1965
- else if (typeof value === 'string') {
1966
- return;
1967
- }
1968
- else if (typeof value === 'symbol') {
1969
- throw new UnexpectedError("".concat(name, " is symbol"));
1970
- }
1971
- else if (typeof value === 'function') {
1972
- throw new UnexpectedError("".concat(name, " is function"));
1973
- }
1974
- else if (typeof value === 'object' && Array.isArray(value)) {
1975
- for (var i = 0; i < value.length; i++) {
1976
- checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
1977
- }
1978
- }
1979
- else if (typeof value === 'object') {
1980
- if (value instanceof Date) {
1981
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
1982
- }
1983
- else if (value instanceof Map) {
1984
- throw new UnexpectedError("".concat(name, " is Map"));
1985
- }
1986
- else if (value instanceof Set) {
1987
- throw new UnexpectedError("".concat(name, " is Set"));
1988
- }
1989
- else if (value instanceof RegExp) {
1990
- throw new UnexpectedError("".concat(name, " is RegExp"));
1991
- }
1992
- else if (value instanceof Error) {
1993
- throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
1994
- }
1995
- else {
1996
- try {
1997
- for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
1998
- var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
1999
- if (subValue === undefined) {
2000
- // Note: undefined in object is serializable - it is just omited
2001
- continue;
2002
- }
2003
- checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
2004
- }
2005
- }
2006
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2007
- finally {
2008
- try {
2009
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2010
- }
2011
- finally { if (e_1) throw e_1.error; }
2012
- }
2013
- try {
2014
- JSON.stringify(value); // <- TODO: [0]
2015
- }
2016
- catch (error) {
2017
- if (!(error instanceof Error)) {
2018
- throw error;
2019
- }
2020
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
2021
- }
2022
- /*
2023
- TODO: [0] Is there some more elegant way to check circular references?
2024
- const seen = new Set();
2025
- const stack = [{ value }];
2026
- while (stack.length > 0) {
2027
- const { value } = stack.pop()!;
2028
- if (typeof value === 'object' && value !== null) {
2029
- if (seen.has(value)) {
2030
- throw new UnexpectedError(`${name} has circular reference`);
2031
- }
2032
- seen.add(value);
2033
- if (Array.isArray(value)) {
2034
- stack.push(...value.map((value) => ({ value })));
2035
- } else {
2036
- stack.push(...Object.values(value).map((value) => ({ value })));
2037
- }
2038
- }
2039
- }
2040
- */
2041
- return;
2042
- }
2043
- }
2044
- else {
2045
- throw new UnexpectedError("".concat(name, " is unknown"));
2046
- }
2047
- }
2048
- /**
2049
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
2050
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
2051
- * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
2052
- */
2053
-
2054
2149
  /**
2055
2150
  * @@@
2056
2151
  *
@@ -2081,29 +2176,7 @@ function clonePipeline(pipeline) {
2081
2176
  * TODO: [🍙] Make some standard order of json properties
2082
2177
  */
2083
2178
 
2084
- /**
2085
- * @@@
2086
- *
2087
- * @public exported from `@promptbook/utils`
2088
- */
2089
- function deepClone(objectValue) {
2090
- return JSON.parse(JSON.stringify(objectValue));
2091
- /*
2092
- TODO: [🧠] Is there a better implementation?
2093
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
2094
- > for (const propertyName of propertyNames) {
2095
- > const value = (objectValue as really_any)[propertyName];
2096
- > if (value && typeof value === 'object') {
2097
- > deepClone(value);
2098
- > }
2099
- > }
2100
- > return Object.assign({}, objectValue);
2101
- */
2102
- }
2103
- /**
2104
- * TODO: [🧠] Is there a way how to meaningfully test this utility
2105
- */
2106
-
2179
+ // <- TODO: !!!!!!! Auto convert to type `import { ... } from 'type-fest';`
2107
2180
  /**
2108
2181
  * Tests if the value is [🚉] serializable as JSON
2109
2182
  *
@@ -2125,7 +2198,7 @@ function deepClone(objectValue) {
2125
2198
  */
2126
2199
  function isSerializableAsJson(value) {
2127
2200
  try {
2128
- checkSerializableAsJson('', value);
2201
+ checkSerializableAsJson({ value: value });
2129
2202
  return true;
2130
2203
  }
2131
2204
  catch (error) {
@@ -2521,5 +2594,5 @@ function isValidUuid(value) {
2521
2594
  return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
2522
2595
  }
2523
2596
 
2524
- export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, replaceParameters, searchKeywords, serializeError, spaceTrim, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
2597
+ export { $deepFreeze, $getCurrentDate, $isRunningInBrowser, $isRunningInJest, $isRunningInNode, $isRunningInWebWorker, $randomSeed, BOOK_LANGUAGE_VERSION, CHARACTERS_PER_STANDARD_LINE, CountUtils, DIACRITIC_VARIANTS_LETTERS, LINES_PER_STANDARD_PAGE, PROMPTBOOK_ENGINE_VERSION, capitalize, checkSerializableAsJson, clonePipeline, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, deepClone, deserializeError, difference, exportJson, extractParameterNames, extractVariablesFromScript, forEachAsync, intersection, isHostnameOnPrivateNetwork, isSerializableAsJson, isUrlOnPrivateNetwork, isValidEmail, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, orderJson, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renderPromptbookMermaid, replaceParameters, searchKeywords, serializeError, spaceTrim, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
2525
2598
  //# sourceMappingURL=index.es.js.map