@promptbook/editable 0.92.0-10 → 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.
- package/esm/index.es.js +50 -55
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/browser.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -4
- package/esm/typings/src/_packages/types.index.d.ts +2 -2
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +3 -1
- package/esm/typings/src/execution/createPipelineExecutor/computeCosineSimilarity.d.ts +13 -0
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/formats/_common/{FormatDefinition.d.ts → FormatParser.d.ts} +3 -3
- package/esm/typings/src/formats/_common/{FormatSubvalueDefinition.d.ts → FormatSubvalueParser.d.ts} +1 -1
- package/esm/typings/src/formats/csv/CsvFormatParser.d.ts +17 -0
- package/esm/typings/src/formats/index.d.ts +2 -2
- package/esm/typings/src/formats/json/{JsonFormatDefinition.d.ts → JsonFormatParser.d.ts} +6 -6
- package/esm/typings/src/formats/text/{TextFormatDefinition.d.ts → TextFormatParser.d.ts} +7 -7
- package/esm/typings/src/formats/xml/XmlFormatParser.d.ts +19 -0
- package/esm/typings/src/postprocessing/utils/extractJsonBlock.d.ts +1 -1
- package/esm/typings/src/storage/local-storage/getIndexedDbStorage.d.ts +10 -0
- package/esm/typings/src/storage/local-storage/utils/makePromptbookStorageFromIndexedDb.d.ts +7 -0
- package/esm/typings/src/utils/expectation-counters/index.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +50 -55
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/formats/csv/CsvFormatDefinition.d.ts +0 -17
- 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-
|
|
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
|
|
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
|
-
|
|
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 `
|
|
850
|
-
* TODO: [🍓] In `
|
|
851
|
-
* TODO: [🍓] In `
|
|
852
|
-
* TODO: [🍓] In `
|
|
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
|
|
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
|
-
|
|
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 `
|
|
903
|
-
* TODO: [🍓] In `
|
|
904
|
-
* TODO: [🍓] In `
|
|
905
|
-
* TODO: [🍓] In `
|
|
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 `
|
|
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
|
|
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 `
|
|
925
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
926
926
|
},
|
|
927
|
-
|
|
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 `
|
|
948
|
-
* TODO: [🍓] In `
|
|
949
|
-
* TODO: [🍓] In `
|
|
950
|
-
* TODO: [🍓] In `
|
|
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
|
|
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
|
-
|
|
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 `
|
|
1003
|
-
* TODO: [🍓] In `
|
|
1004
|
-
* TODO: [🍓] In `
|
|
1005
|
-
* TODO: [🍓] In `
|
|
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
|
|
1832
|
-
if (
|
|
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.
|
|
1838
|
-
.map((
|
|
1832
|
+
${block(formatDefinition.subvalueParsers
|
|
1833
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
1839
1834
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
1840
1835
|
.join('\n'))}
|
|
1841
1836
|
`));
|