@promptbook/editable 0.92.0-11 → 0.92.0-12

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
@@ -17,7 +17,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
17
17
  * @generated
18
18
  * @see https://github.com/webgptorg/promptbook
19
19
  */
20
- const PROMPTBOOK_ENGINE_VERSION = '0.92.0-11';
20
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-12';
21
21
  /**
22
22
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
23
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -727,6 +727,24 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
727
727
  // encoding: 'utf-8',
728
728
  });
729
729
 
730
+ /**
731
+ * Converts a CSV string into an object
732
+ *
733
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
734
+ *
735
+ * @private - for now until `@promptbook/csv` is released
736
+ */
737
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
738
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
739
+ // Note: Autoheal invalid '\n' characters
740
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
741
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
742
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
743
+ }
744
+ const csv = parse(value, settings);
745
+ return csv;
746
+ }
747
+
730
748
  /**
731
749
  * Function to check if a string is valid CSV
732
750
  *
@@ -749,31 +767,13 @@ function isValidCsvString(value) {
749
767
  }
750
768
  }
751
769
 
752
- /**
753
- * Converts a CSV string into an object
754
- *
755
- * Note: This is wrapper around `papaparse.parse()` with better autohealing
756
- *
757
- * @private - for now until `@promptbook/csv` is released
758
- */
759
- function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
760
- settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
761
- // Note: Autoheal invalid '\n' characters
762
- if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
763
- console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
764
- value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
765
- }
766
- const csv = parse(value, settings);
767
- return csv;
768
- }
769
-
770
770
  /**
771
771
  * Definition for CSV spreadsheet
772
772
  *
773
773
  * @public exported from `@promptbook/core`
774
774
  * <- TODO: [🏢] Export from package `@promptbook/csv`
775
775
  */
776
- const CsvFormatDefinition = {
776
+ const CsvFormatParser = {
777
777
  formatName: 'CSV',
778
778
  aliases: ['SPREADSHEET', 'TABLE'],
779
779
  isValid(value, settings, schema) {
@@ -785,7 +785,7 @@ const CsvFormatDefinition = {
785
785
  heal(value, settings, schema) {
786
786
  throw new Error('Not implemented');
787
787
  },
788
- subvalueDefinitions: [
788
+ subvalueParsers: [
789
789
  {
790
790
  subvalueName: 'ROW',
791
791
  async mapValues(value, outputParameterName, settings, mapCallback) {
@@ -846,10 +846,10 @@ const CsvFormatDefinition = {
846
846
  ],
847
847
  };
848
848
  /**
849
- * TODO: [🍓] In `CsvFormatDefinition` implement simple `isValid`
850
- * TODO: [🍓] In `CsvFormatDefinition` implement partial `canBeValid`
851
- * TODO: [🍓] In `CsvFormatDefinition` implement `heal
852
- * TODO: [🍓] In `CsvFormatDefinition` implement `subvalueDefinitions`
849
+ * TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
850
+ * TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
851
+ * TODO: [🍓] In `CsvFormatParser` implement `heal
852
+ * TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
853
853
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
854
854
  */
855
855
 
@@ -880,7 +880,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
880
880
  *
881
881
  * @private still in development [🏢]
882
882
  */
883
- const JsonFormatDefinition = {
883
+ const JsonFormatParser = {
884
884
  formatName: 'JSON',
885
885
  mimeType: 'application/json',
886
886
  isValid(value, settings, schema) {
@@ -892,28 +892,28 @@ const JsonFormatDefinition = {
892
892
  heal(value, settings, schema) {
893
893
  throw new Error('Not implemented');
894
894
  },
895
- subvalueDefinitions: [],
895
+ subvalueParsers: [],
896
896
  };
897
897
  /**
898
898
  * TODO: [🧠] Maybe propper instance of object
899
899
  * TODO: [0] Make string_serialized_json
900
900
  * TODO: [1] Make type for JSON Settings and Schema
901
901
  * TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
902
- * TODO: [🍓] In `JsonFormatDefinition` implement simple `isValid`
903
- * TODO: [🍓] In `JsonFormatDefinition` implement partial `canBeValid`
904
- * TODO: [🍓] In `JsonFormatDefinition` implement `heal
905
- * TODO: [🍓] In `JsonFormatDefinition` implement `subvalueDefinitions`
902
+ * TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
903
+ * TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
904
+ * TODO: [🍓] In `JsonFormatParser` implement `heal
905
+ * TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
906
906
  * TODO: [🏢] Allow to expect something inside JSON objects and other formats
907
907
  */
908
908
 
909
909
  /**
910
910
  * Definition for any text - this will be always valid
911
911
  *
912
- * Note: This is not useful for validation, but for splitting and mapping with `subvalueDefinitions`
912
+ * Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
913
913
  *
914
914
  * @public exported from `@promptbook/core`
915
915
  */
916
- const TextFormatDefinition = {
916
+ const TextFormatParser = {
917
917
  formatName: 'TEXT',
918
918
  isValid(value) {
919
919
  return typeof value === 'string';
@@ -922,9 +922,9 @@ const TextFormatDefinition = {
922
922
  return typeof partialValue === 'string';
923
923
  },
924
924
  heal() {
925
- throw new UnexpectedError('It does not make sense to call `TextFormatDefinition.heal`');
925
+ throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
926
926
  },
927
- subvalueDefinitions: [
927
+ subvalueParsers: [
928
928
  {
929
929
  subvalueName: 'LINE',
930
930
  async mapValues(value, outputParameterName, settings, mapCallback) {
@@ -944,10 +944,10 @@ const TextFormatDefinition = {
944
944
  /**
945
945
  * TODO: [1] Make type for XML Text and Schema
946
946
  * TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
947
- * TODO: [🍓] In `TextFormatDefinition` implement simple `isValid`
948
- * TODO: [🍓] In `TextFormatDefinition` implement partial `canBeValid`
949
- * TODO: [🍓] In `TextFormatDefinition` implement `heal
950
- * TODO: [🍓] In `TextFormatDefinition` implement `subvalueDefinitions`
947
+ * TODO: [🍓] In `TextFormatParser` implement simple `isValid`
948
+ * TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
949
+ * TODO: [🍓] In `TextFormatParser` implement `heal
950
+ * TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
951
951
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
952
952
  */
953
953
 
@@ -980,7 +980,7 @@ function isValidXmlString(value) {
980
980
  *
981
981
  * @private still in development [🏢]
982
982
  */
983
- const XmlFormatDefinition = {
983
+ const XmlFormatParser = {
984
984
  formatName: 'XML',
985
985
  mimeType: 'application/xml',
986
986
  isValid(value, settings, schema) {
@@ -992,17 +992,17 @@ const XmlFormatDefinition = {
992
992
  heal(value, settings, schema) {
993
993
  throw new Error('Not implemented');
994
994
  },
995
- subvalueDefinitions: [],
995
+ subvalueParsers: [],
996
996
  };
997
997
  /**
998
998
  * TODO: [🧠] Maybe propper instance of object
999
999
  * TODO: [0] Make string_serialized_xml
1000
1000
  * TODO: [1] Make type for XML Settings and Schema
1001
1001
  * TODO: [🧠] What to use for validating XMLs - XSD,...
1002
- * TODO: [🍓] In `XmlFormatDefinition` implement simple `isValid`
1003
- * TODO: [🍓] In `XmlFormatDefinition` implement partial `canBeValid`
1004
- * TODO: [🍓] In `XmlFormatDefinition` implement `heal
1005
- * TODO: [🍓] In `XmlFormatDefinition` implement `subvalueDefinitions`
1002
+ * TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
1003
+ * TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
1004
+ * TODO: [🍓] In `XmlFormatParser` implement `heal
1005
+ * TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
1006
1006
  * TODO: [🏢] Allow to expect something inside XML and other formats
1007
1007
  */
1008
1008
 
@@ -1011,12 +1011,7 @@ const XmlFormatDefinition = {
1011
1011
  *
1012
1012
  * @private internal index of `...` <- TODO [🏢]
1013
1013
  */
1014
- const FORMAT_DEFINITIONS = [
1015
- JsonFormatDefinition,
1016
- XmlFormatDefinition,
1017
- TextFormatDefinition,
1018
- CsvFormatDefinition,
1019
- ];
1014
+ const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
1020
1015
  /**
1021
1016
  * Note: [💞] Ignore a discrepancy between file name and entity name
1022
1017
  */
@@ -1828,14 +1823,14 @@ const foreachCommandParser = {
1828
1823
  `));
1829
1824
  // <- TODO: [🏢] List all supported format names
1830
1825
  }
1831
- const subvalueDefinition = formatDefinition.subvalueDefinitions.find((subvalueDefinition) => [subvalueDefinition.subvalueName, ...(subvalueDefinition.aliases || [])].includes(subformatName));
1832
- if (subvalueDefinition === undefined) {
1826
+ const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
1827
+ if (subvalueParser === undefined) {
1833
1828
  throw new ParseError(spaceTrim((block) => `
1834
1829
  Unsupported subformat name "${subformatName}" for format "${formatName}"
1835
1830
 
1836
1831
  Available subformat names for format "${formatDefinition.formatName}":
1837
- ${block(formatDefinition.subvalueDefinitions
1838
- .map((subvalueDefinition) => subvalueDefinition.subvalueName)
1832
+ ${block(formatDefinition.subvalueParsers
1833
+ .map((subvalueParser) => subvalueParser.subvalueName)
1839
1834
  .map((subvalueName) => `- ${subvalueName}`)
1840
1835
  .join('\n'))}
1841
1836
  `));