@promptbook/remote-client 0.92.0-11 → 0.92.0-13

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 (24) hide show
  1. package/esm/index.es.js +50 -55
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/browser.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -4
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -2
  6. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +3 -1
  7. package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
  8. package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
  9. package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +3 -3
  10. package/esm/typings/src/formats/_common/{FormatSubvalueDefinition.d.ts → FormatSubvalueParser.d.ts} +1 -1
  11. package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
  12. package/esm/typings/src/formats/index.d.ts +2 -2
  13. package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
  14. package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
  15. package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
  16. package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
  17. package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
  18. package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
  19. package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
  20. package/package.json +2 -2
  21. package/umd/index.umd.js +50 -55
  22. package/umd/index.umd.js.map +1 -1
  23. package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
  24. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +0 -19
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  * @generated
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-11';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-13';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1834,6 +1834,24 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
1834
1834
  // encoding: 'utf-8',
1835
1835
  });
1836
1836
 
1837
+ /**
1838
+ * Converts a CSV string into an object
1839
+ *
1840
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
1841
+ *
1842
+ * @private - for now until `@promptbook/csv` is released
1843
+ */
1844
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
1845
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
1846
+ // Note: Autoheal invalid '\n' characters
1847
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
1848
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
1849
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
1850
+ }
1851
+ const csv = parse(value, settings);
1852
+ return csv;
1853
+ }
1854
+
1837
1855
  /**
1838
1856
  * Function to check if a string is valid CSV
1839
1857
  *
@@ -1856,31 +1874,13 @@ function isValidCsvString(value) {
1856
1874
  }
1857
1875
  }
1858
1876
 
1859
- /**
1860
- * Converts a CSV string into an object
1861
- *
1862
- * Note: This is wrapper around `papaparse.parse()` with better autohealing
1863
- *
1864
- * @private - for now until `@promptbook/csv` is released
1865
- */
1866
- function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
1867
- settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
1868
- // Note: Autoheal invalid '\n' characters
1869
- if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
1870
- console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
1871
- value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
1872
- }
1873
- const csv = parse(value, settings);
1874
- return csv;
1875
- }
1876
-
1877
1877
  /**
1878
1878
  * Definition for CSV spreadsheet
1879
1879
  *
1880
1880
  * @public exported from `@promptbook/core`
1881
1881
  * <- TODO: [🏢] Export from package `@promptbook/csv`
1882
1882
  */
1883
- const CsvFormatDefinition = {
1883
+ const CsvFormatParser = {
1884
1884
  formatName: 'CSV',
1885
1885
  aliases: ['SPREADSHEET', 'TABLE'],
1886
1886
  isValid(value, settings, schema) {
@@ -1892,7 +1892,7 @@ const CsvFormatDefinition = {
1892
1892
  heal(value, settings, schema) {
1893
1893
  throw new Error('Not implemented');
1894
1894
  },
1895
- subvalueDefinitions: [
1895
+ subvalueParsers: [
1896
1896
  {
1897
1897
  subvalueName: 'ROW',
1898
1898
  async mapValues(value, outputParameterName, settings, mapCallback) {
@@ -1953,10 +1953,10 @@ const CsvFormatDefinition = {
1953
1953
  ],
1954
1954
  };
1955
1955
  /**
1956
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
1957
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
1958
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
1959
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
1956
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
1957
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
1958
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
1959
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
1960
1960
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
1961
1961
  */
1962
1962
 
@@ -1987,7 +1987,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1987
1987
  *
1988
1988
  * @private still in development [🏢]
1989
1989
  */
1990
- const JsonFormatDefinition = {
1990
+ const JsonFormatParser = {
1991
1991
  formatName: 'JSON',
1992
1992
  mimeType: 'application/json',
1993
1993
  isValid(value, settings, schema) {
@@ -1999,28 +1999,28 @@ const JsonFormatDefinition = {
1999
1999
  heal(value, settings, schema) {
2000
2000
  throw new Error('Not implemented');
2001
2001
  },
2002
- subvalueDefinitions: [],
2002
+ subvalueParsers: [],
2003
2003
  };
2004
2004
  /**
2005
2005
  * TODO: [🧠] Maybe propper instance of object
2006
2006
  * TODO: [0] Make string_serialized_json
2007
2007
  * TODO: [1] Make type for JSON Settings and Schema
2008
2008
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
2009
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
2010
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
2011
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
2012
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
2009
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
2010
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
2011
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
2012
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
2013
2013
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
2014
2014
  */
2015
2015
 
2016
2016
  /**
2017
2017
  * Definition for any text - this will be always valid
2018
2018
  *
2019
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
2019
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
2020
2020
  *
2021
2021
  * @public exported from `@promptbook/core`
2022
2022
  */
2023
- const TextFormatDefinition = {
2023
+ const TextFormatParser = {
2024
2024
  formatName: 'TEXT',
2025
2025
  isValid(value) {
2026
2026
  return typeof value === 'string';
@@ -2029,9 +2029,9 @@ const TextFormatDefinition = {
2029
2029
  return typeof partialValue === 'string';
2030
2030
  },
2031
2031
  heal() {
2032
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
2032
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
2033
2033
  },
2034
- subvalueDefinitions: [
2034
+ subvalueParsers: [
2035
2035
  {
2036
2036
  subvalueName: 'LINE',
2037
2037
  async mapValues(value, outputParameterName, settings, mapCallback) {
@@ -2051,10 +2051,10 @@ const TextFormatDefinition = {
2051
2051
  /**
2052
2052
  * TODO: [1] Make type for XML Text and Schema
2053
2053
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
2054
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
2055
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
2056
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
2057
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
2054
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
2055
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
2056
+ * TODO: [🍓] In `TextFormatParser` implement `heal
2057
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
2058
2058
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
2059
2059
  */
2060
2060
 
@@ -2087,7 +2087,7 @@ function isValidXmlString(value) {
2087
2087
  *
2088
2088
  * @private still in development [🏢]
2089
2089
  */
2090
- const XmlFormatDefinition = {
2090
+ const XmlFormatParser = {
2091
2091
  formatName: 'XML',
2092
2092
  mimeType: 'application/xml',
2093
2093
  isValid(value, settings, schema) {
@@ -2099,17 +2099,17 @@ const XmlFormatDefinition = {
2099
2099
  heal(value, settings, schema) {
2100
2100
  throw new Error('Not implemented');
2101
2101
  },
2102
- subvalueDefinitions: [],
2102
+ subvalueParsers: [],
2103
2103
  };
2104
2104
  /**
2105
2105
  * TODO: [🧠] Maybe propper instance of object
2106
2106
  * TODO: [0] Make string_serialized_xml
2107
2107
  * TODO: [1] Make type for XML Settings and Schema
2108
2108
  * TODO: [🧠] What to use for validating XMLs - XSD,...
2109
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
2110
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
2111
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
2112
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
2109
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
2110
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
2111
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
2112
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
2113
2113
  * TODO: [🏢] Allow to expect something inside XML and other formats
2114
2114
  */
2115
2115
 
@@ -2118,12 +2118,7 @@ const XmlFormatDefinition = {
2118
2118
  *
2119
2119
  * @private internal index of `...` <- TODO [🏢]
2120
2120
  */
2121
- const FORMAT_DEFINITIONS = [
2122
- JsonFormatDefinition,
2123
- XmlFormatDefinition,
2124
- TextFormatDefinition,
2125
- CsvFormatDefinition,
2126
- ];
2121
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
2127
2122
  /**
2128
2123
  * Note: [💞] Ignore a discrepancy between file name and entity name
2129
2124
  */
@@ -2688,14 +2683,14 @@ const foreachCommandParser = {
2688
2683
  `));
2689
2684
  // <- TODO: [🏢] List all supported format names
2690
2685
  }
2691
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(subformatName));
2692
- if (subvalueDefinition === undefined) {
2686
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
2687
+ if (subvalueParser === undefined) {
2693
2688
  throw new ParseError(spaceTrim$1((block) => `
2694
2689
  Unsupported subformat name "${subformatName}" for format "${formatName}"
2695
2690
 
2696
2691
  Available subformat names for format "${formatDefinition.formatName}":
2697
- ${block(formatDefinition.subvalueDefinitions
2698
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
2692
+ ${block(formatDefinition.subvalueParsers
2693
+ .map((subvalueParser) => subvalueParser.subvalueName)
2699
2694
  .map((subvalueName) => `- ${subvalueName}`)
2700
2695
  .join('\n'))}
2701
2696
  `));