@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.
- 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
|
@@ -62,6 +62,7 @@ import { PromptbookFetchError } from '../errors/PromptbookFetchError';
|
|
|
62
62
|
import { UnexpectedError } from '../errors/UnexpectedError';
|
|
63
63
|
import { WrappedError } from '../errors/WrappedError';
|
|
64
64
|
import { createPipelineExecutor } from '../execution/createPipelineExecutor/00-createPipelineExecutor';
|
|
65
|
+
import { computeCosineSimilarity } from '../execution/createPipelineExecutor/computeCosineSimilarity';
|
|
65
66
|
import { embeddingVectorToString } from '../execution/embeddingVectorToString';
|
|
66
67
|
import { executionReportJsonToString } from '../execution/execution-report/executionReportJsonToString';
|
|
67
68
|
import type { ExecutionReportStringOptions } from '../execution/execution-report/ExecutionReportStringOptions';
|
|
@@ -74,10 +75,10 @@ import { ZERO_USAGE } from '../execution/utils/usage-constants';
|
|
|
74
75
|
import { UNCERTAIN_USAGE } from '../execution/utils/usage-constants';
|
|
75
76
|
import { usageToHuman } from '../execution/utils/usageToHuman';
|
|
76
77
|
import { usageToWorktime } from '../execution/utils/usageToWorktime';
|
|
77
|
-
import { CsvFormatDefinition } from '../formats/csv/CsvFormatDefinition';
|
|
78
78
|
import { CsvFormatError } from '../formats/csv/CsvFormatError';
|
|
79
|
+
import { CsvFormatParser } from '../formats/csv/CsvFormatParser';
|
|
79
80
|
import { MANDATORY_CSV_SETTINGS } from '../formats/csv/CsvSettings';
|
|
80
|
-
import {
|
|
81
|
+
import { TextFormatParser } from '../formats/text/TextFormatParser';
|
|
81
82
|
import { BoilerplateFormfactorDefinition } from '../formfactors/_boilerplate/BoilerplateFormfactorDefinition';
|
|
82
83
|
import { ChatbotFormfactorDefinition } from '../formfactors/chatbot/ChatbotFormfactorDefinition';
|
|
83
84
|
import { GeneratorFormfactorDefinition } from '../formfactors/generator/GeneratorFormfactorDefinition';
|
|
@@ -203,6 +204,7 @@ export { PromptbookFetchError };
|
|
|
203
204
|
export { UnexpectedError };
|
|
204
205
|
export { WrappedError };
|
|
205
206
|
export { createPipelineExecutor };
|
|
207
|
+
export { computeCosineSimilarity };
|
|
206
208
|
export { embeddingVectorToString };
|
|
207
209
|
export { executionReportJsonToString };
|
|
208
210
|
export type { ExecutionReportStringOptions };
|
|
@@ -215,10 +217,10 @@ export { ZERO_USAGE };
|
|
|
215
217
|
export { UNCERTAIN_USAGE };
|
|
216
218
|
export { usageToHuman };
|
|
217
219
|
export { usageToWorktime };
|
|
218
|
-
export { CsvFormatDefinition };
|
|
219
220
|
export { CsvFormatError };
|
|
221
|
+
export { CsvFormatParser };
|
|
220
222
|
export { MANDATORY_CSV_SETTINGS };
|
|
221
|
-
export {
|
|
223
|
+
export { TextFormatParser };
|
|
222
224
|
export { BoilerplateFormfactorDefinition };
|
|
223
225
|
export { ChatbotFormfactorDefinition };
|
|
224
226
|
export { GeneratorFormfactorDefinition };
|
|
@@ -61,7 +61,7 @@ import type { Usage } from '../execution/Usage';
|
|
|
61
61
|
import type { UsageCounts } from '../execution/Usage';
|
|
62
62
|
import type { UserInterfaceTools } from '../execution/UserInterfaceTools';
|
|
63
63
|
import type { UserInterfaceToolsPromptDialogOptions } from '../execution/UserInterfaceTools';
|
|
64
|
-
import type {
|
|
64
|
+
import type { FormatSubvalueParser } from '../formats/_common/FormatSubvalueParser';
|
|
65
65
|
import type { CsvSettings } from '../formats/csv/CsvSettings';
|
|
66
66
|
import type { AbstractFormfactorDefinition } from '../formfactors/_common/AbstractFormfactorDefinition';
|
|
67
67
|
import type { FormfactorDefinition } from '../formfactors/_common/FormfactorDefinition';
|
|
@@ -357,7 +357,7 @@ export type { Usage };
|
|
|
357
357
|
export type { UsageCounts };
|
|
358
358
|
export type { UserInterfaceTools };
|
|
359
359
|
export type { UserInterfaceToolsPromptDialogOptions };
|
|
360
|
-
export type {
|
|
360
|
+
export type { FormatSubvalueParser };
|
|
361
361
|
export type { CsvSettings };
|
|
362
362
|
export type { AbstractFormfactorDefinition };
|
|
363
363
|
export type { FormfactorDefinition };
|
|
@@ -22,8 +22,10 @@ export type PipelineExecutorResult = AbstractTaskResult & {
|
|
|
22
22
|
readonly usage: ReadonlyDeep<Usage>;
|
|
23
23
|
/**
|
|
24
24
|
* The report of the execution with all details
|
|
25
|
+
*
|
|
26
|
+
* Note: If the execution fails unexpectedly, this will be `null`
|
|
25
27
|
*/
|
|
26
|
-
readonly executionReport: ReadonlyDeep<ExecutionReportJson
|
|
28
|
+
readonly executionReport: ReadonlyDeep<ExecutionReportJson> | null;
|
|
27
29
|
/**
|
|
28
30
|
* The prepared pipeline that was used for the execution
|
|
29
31
|
*
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EmbeddingVector } from '../EmbeddingVector';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the cosine similarity between two embedding vectors
|
|
4
|
+
*
|
|
5
|
+
* Note: This is helping function for RAG (retrieval-augmented generation)
|
|
6
|
+
*
|
|
7
|
+
* @param embeddingVector1
|
|
8
|
+
* @param embeddingVector2
|
|
9
|
+
* @returns Cosine similarity between the two vectors
|
|
10
|
+
*
|
|
11
|
+
* @public exported from `@promptbook/core`
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeCosineSimilarity(embeddingVector1: EmbeddingVector, embeddingVector2: EmbeddingVector): number;
|
|
@@ -24,6 +24,6 @@ export declare function checkExpectations(expectations: Expectations, value: str
|
|
|
24
24
|
export declare function isPassingExpectations(expectations: Expectations, value: string): boolean;
|
|
25
25
|
/**
|
|
26
26
|
* TODO: [💝] Unite object for expecting amount and format
|
|
27
|
-
* TODO: [🧠][🤠] This should be part of `
|
|
27
|
+
* TODO: [🧠][🤠] This should be part of `TextFormatParser`
|
|
28
28
|
* Note: [💝] and [🤠] are interconnected together
|
|
29
29
|
*/
|
|
@@ -2,7 +2,7 @@ import type { string_mime_type } from '../../types/typeAliases';
|
|
|
2
2
|
import type { string_name } from '../../types/typeAliases';
|
|
3
3
|
import type { string_SCREAMING_CASE } from '../../utils/normalization/normalizeTo_SCREAMING_CASE';
|
|
4
4
|
import type { empty_object } from '../../utils/organization/empty_object';
|
|
5
|
-
import type {
|
|
5
|
+
import type { FormatSubvalueParser } from './FormatSubvalueParser';
|
|
6
6
|
/**
|
|
7
7
|
* A format definition is a set of functions that define how to validate, heal and convert response from LLM
|
|
8
8
|
*
|
|
@@ -11,7 +11,7 @@ import type { FormatSubvalueDefinition } from './FormatSubvalueDefinition';
|
|
|
11
11
|
* @see https://github.com/webgptorg/promptbook/discussions/36
|
|
12
12
|
* @private still in development [🏢]
|
|
13
13
|
*/
|
|
14
|
-
export type
|
|
14
|
+
export type FormatParser<TValue extends TPartialValue, TPartialValue extends string, TSettings extends empty_object, TSchema extends empty_object> = {
|
|
15
15
|
/**
|
|
16
16
|
* The name of the format used in .book.md files
|
|
17
17
|
*
|
|
@@ -58,7 +58,7 @@ export type FormatDefinition<TValue extends TPartialValue, TPartialValue extends
|
|
|
58
58
|
/**
|
|
59
59
|
* @@@
|
|
60
60
|
*/
|
|
61
|
-
readonly
|
|
61
|
+
readonly subvalueParsers: ReadonlyArray<FormatSubvalueParser<TValue, TSettings>>;
|
|
62
62
|
};
|
|
63
63
|
/**
|
|
64
64
|
* TODO: [♏] Add some prepare hook to modify prompt according to the format
|
package/esm/typings/src/formats/_common/{FormatSubvalueDefinition.d.ts → FormatSubvalueParser.d.ts}
RENAMED
|
@@ -7,7 +7,7 @@ import type { empty_object } from '../../utils/organization/empty_object';
|
|
|
7
7
|
/**
|
|
8
8
|
* @@@
|
|
9
9
|
*/
|
|
10
|
-
export type
|
|
10
|
+
export type FormatSubvalueParser<TValue extends string, TSettings extends empty_object> = {
|
|
11
11
|
/**
|
|
12
12
|
* The name of the format used in .book.md files
|
|
13
13
|
*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
2
|
+
import type { FormatParser } from '../_common/FormatParser';
|
|
3
|
+
import type { CsvSettings } from './CsvSettings';
|
|
4
|
+
/**
|
|
5
|
+
* Definition for CSV spreadsheet
|
|
6
|
+
*
|
|
7
|
+
* @public exported from `@promptbook/core`
|
|
8
|
+
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
9
|
+
*/
|
|
10
|
+
export declare const CsvFormatParser: FormatParser<string, string, CsvSettings, TODO_any>;
|
|
11
|
+
/**
|
|
12
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
13
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
14
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
15
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
16
|
+
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
17
|
+
*/
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @private internal index of `...` <- TODO [🏢]
|
|
5
5
|
*/
|
|
6
|
-
export declare const FORMAT_DEFINITIONS: readonly [import("./_common/
|
|
6
|
+
export declare const FORMAT_DEFINITIONS: readonly [import("./_common/FormatParser").FormatParser<string, string, any, any>, import("./_common/FormatParser").FormatParser<string, string, any, any>, import("./_common/FormatParser").FormatParser<string, string, any, any>, import("./_common/FormatParser").FormatParser<string, string, import("./csv/CsvSettings").CsvSettings, any>];
|
|
7
7
|
/**
|
|
8
8
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
9
|
-
*/
|
|
9
|
+
*/
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FormatParser } from '../_common/FormatParser';
|
|
3
3
|
/**
|
|
4
4
|
* Definition for JSON format
|
|
5
5
|
*
|
|
6
6
|
* @private still in development [🏢]
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const JsonFormatParser: FormatParser<string, string, TODO_any, TODO_any>;
|
|
9
9
|
/**
|
|
10
10
|
* TODO: [🧠] Maybe propper instance of object
|
|
11
11
|
* TODO: [0] Make string_serialized_json
|
|
12
12
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
13
13
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
14
|
-
* TODO: [🍓] In `
|
|
15
|
-
* TODO: [🍓] In `
|
|
16
|
-
* TODO: [🍓] In `
|
|
17
|
-
* TODO: [🍓] In `
|
|
14
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
15
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
16
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
17
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
18
18
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
19
19
|
*/
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FormatParser } from '../_common/FormatParser';
|
|
3
3
|
/**
|
|
4
4
|
* Definition for any text - this will be always valid
|
|
5
5
|
*
|
|
6
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
6
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
7
7
|
*
|
|
8
8
|
* @public exported from `@promptbook/core`
|
|
9
9
|
*/
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const TextFormatParser: FormatParser<string, string, TODO_any, TODO_any>;
|
|
11
11
|
/**
|
|
12
12
|
* TODO: [1] Make type for XML Text and Schema
|
|
13
13
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
14
|
-
* TODO: [🍓] In `
|
|
15
|
-
* TODO: [🍓] In `
|
|
16
|
-
* TODO: [🍓] In `
|
|
17
|
-
* TODO: [🍓] In `
|
|
14
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
15
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
16
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
17
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
18
18
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
19
19
|
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TODO_any } from '../../utils/organization/TODO_any';
|
|
2
|
+
import type { FormatParser } from '../_common/FormatParser';
|
|
3
|
+
/**
|
|
4
|
+
* Definition for XML format
|
|
5
|
+
*
|
|
6
|
+
* @private still in development [🏢]
|
|
7
|
+
*/
|
|
8
|
+
export declare const XmlFormatParser: FormatParser<string, string, TODO_any, TODO_any>;
|
|
9
|
+
/**
|
|
10
|
+
* TODO: [🧠] Maybe propper instance of object
|
|
11
|
+
* TODO: [0] Make string_serialized_xml
|
|
12
|
+
* TODO: [1] Make type for XML Settings and Schema
|
|
13
|
+
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
14
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
15
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
16
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
17
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
18
|
+
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
19
|
+
*/
|
|
@@ -21,5 +21,5 @@ import type { really_unknown } from '../../utils/organization/really_unknown';
|
|
|
21
21
|
export declare function extractJsonBlock(markdown: string_markdown): string_json<really_unknown>;
|
|
22
22
|
/**
|
|
23
23
|
* TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
|
|
24
|
-
* TODO: [🏢] Make this logic part of `
|
|
24
|
+
* TODO: [🏢] Make this logic part of `JsonFormatParser` or `isValidJsonString`
|
|
25
25
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PromptbookStorage } from '../_common/PromptbookStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Gets wrapper around IndexedDB which can be used as PromptbookStorage
|
|
4
|
+
*
|
|
5
|
+
* @public exported from `@promptbook/browser`
|
|
6
|
+
*/
|
|
7
|
+
export declare function getIndexedDbStorage<TItem>(): PromptbookStorage<TItem>;
|
|
8
|
+
/**
|
|
9
|
+
* Note: [🔵] Code in this file should never be published outside of `@promptbook/browser`
|
|
10
|
+
*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PromptbookStorage } from '../../_common/PromptbookStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a PromptbookStorage backed by IndexedDB.
|
|
4
|
+
* Uses a single object store named 'promptbook'.
|
|
5
|
+
* @private for `getIndexedDbStorage`
|
|
6
|
+
*/
|
|
7
|
+
export declare function makePromptbookStorageFromIndexedDb<TValue>(dbName?: string, storeName?: string): PromptbookStorage<TValue>;
|
|
@@ -7,6 +7,6 @@ import type { ExpectationUnit } from '../../pipeline/PipelineJson/Expectations';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const CountUtils: Record<ExpectationUnit, (text: string) => ExpectationAmount>;
|
|
9
9
|
/**
|
|
10
|
-
* TODO: [🧠][🤠] This should be probbably as part of `
|
|
10
|
+
* TODO: [🧠][🤠] This should be probbably as part of `TextFormatParser`
|
|
11
11
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
12
12
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-client",
|
|
3
|
-
"version": "0.92.0-
|
|
3
|
+
"version": "0.92.0-13",
|
|
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,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"module": "./esm/index.es.js",
|
|
52
52
|
"typings": "./esm/typings/src/_packages/remote-client.index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@promptbook/core": "0.92.0-
|
|
54
|
+
"@promptbook/core": "0.92.0-13"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"crypto": "1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-13';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1837,6 +1837,24 @@
|
|
|
1837
1837
|
// encoding: 'utf-8',
|
|
1838
1838
|
});
|
|
1839
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Converts a CSV string into an object
|
|
1842
|
+
*
|
|
1843
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
1844
|
+
*
|
|
1845
|
+
* @private - for now until `@promptbook/csv` is released
|
|
1846
|
+
*/
|
|
1847
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
1848
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
1849
|
+
// Note: Autoheal invalid '\n' characters
|
|
1850
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
1851
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
1852
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
1853
|
+
}
|
|
1854
|
+
const csv = papaparse.parse(value, settings);
|
|
1855
|
+
return csv;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1840
1858
|
/**
|
|
1841
1859
|
* Function to check if a string is valid CSV
|
|
1842
1860
|
*
|
|
@@ -1859,31 +1877,13 @@
|
|
|
1859
1877
|
}
|
|
1860
1878
|
}
|
|
1861
1879
|
|
|
1862
|
-
/**
|
|
1863
|
-
* Converts a CSV string into an object
|
|
1864
|
-
*
|
|
1865
|
-
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
1866
|
-
*
|
|
1867
|
-
* @private - for now until `@promptbook/csv` is released
|
|
1868
|
-
*/
|
|
1869
|
-
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
1870
|
-
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
1871
|
-
// Note: Autoheal invalid '\n' characters
|
|
1872
|
-
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
1873
|
-
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
1874
|
-
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
1875
|
-
}
|
|
1876
|
-
const csv = papaparse.parse(value, settings);
|
|
1877
|
-
return csv;
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
1880
|
/**
|
|
1881
1881
|
* Definition for CSV spreadsheet
|
|
1882
1882
|
*
|
|
1883
1883
|
* @public exported from `@promptbook/core`
|
|
1884
1884
|
* <- TODO: [🏢] Export from package `@promptbook/csv`
|
|
1885
1885
|
*/
|
|
1886
|
-
const
|
|
1886
|
+
const CsvFormatParser = {
|
|
1887
1887
|
formatName: 'CSV',
|
|
1888
1888
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
1889
1889
|
isValid(value, settings, schema) {
|
|
@@ -1895,7 +1895,7 @@
|
|
|
1895
1895
|
heal(value, settings, schema) {
|
|
1896
1896
|
throw new Error('Not implemented');
|
|
1897
1897
|
},
|
|
1898
|
-
|
|
1898
|
+
subvalueParsers: [
|
|
1899
1899
|
{
|
|
1900
1900
|
subvalueName: 'ROW',
|
|
1901
1901
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -1956,10 +1956,10 @@
|
|
|
1956
1956
|
],
|
|
1957
1957
|
};
|
|
1958
1958
|
/**
|
|
1959
|
-
* TODO: [🍓] In `
|
|
1960
|
-
* TODO: [🍓] In `
|
|
1961
|
-
* TODO: [🍓] In `
|
|
1962
|
-
* TODO: [🍓] In `
|
|
1959
|
+
* TODO: [🍓] In `CsvFormatParser` implement simple `isValid`
|
|
1960
|
+
* TODO: [🍓] In `CsvFormatParser` implement partial `canBeValid`
|
|
1961
|
+
* TODO: [🍓] In `CsvFormatParser` implement `heal
|
|
1962
|
+
* TODO: [🍓] In `CsvFormatParser` implement `subvalueParsers`
|
|
1963
1963
|
* TODO: [🏢] Allow to expect something inside CSV objects and other formats
|
|
1964
1964
|
*/
|
|
1965
1965
|
|
|
@@ -1990,7 +1990,7 @@
|
|
|
1990
1990
|
*
|
|
1991
1991
|
* @private still in development [🏢]
|
|
1992
1992
|
*/
|
|
1993
|
-
const
|
|
1993
|
+
const JsonFormatParser = {
|
|
1994
1994
|
formatName: 'JSON',
|
|
1995
1995
|
mimeType: 'application/json',
|
|
1996
1996
|
isValid(value, settings, schema) {
|
|
@@ -2002,28 +2002,28 @@
|
|
|
2002
2002
|
heal(value, settings, schema) {
|
|
2003
2003
|
throw new Error('Not implemented');
|
|
2004
2004
|
},
|
|
2005
|
-
|
|
2005
|
+
subvalueParsers: [],
|
|
2006
2006
|
};
|
|
2007
2007
|
/**
|
|
2008
2008
|
* TODO: [🧠] Maybe propper instance of object
|
|
2009
2009
|
* TODO: [0] Make string_serialized_json
|
|
2010
2010
|
* TODO: [1] Make type for JSON Settings and Schema
|
|
2011
2011
|
* TODO: [🧠] What to use for validating JSONs - JSON Schema, ZoD, typescript types/interfaces,...?
|
|
2012
|
-
* TODO: [🍓] In `
|
|
2013
|
-
* TODO: [🍓] In `
|
|
2014
|
-
* TODO: [🍓] In `
|
|
2015
|
-
* TODO: [🍓] In `
|
|
2012
|
+
* TODO: [🍓] In `JsonFormatParser` implement simple `isValid`
|
|
2013
|
+
* TODO: [🍓] In `JsonFormatParser` implement partial `canBeValid`
|
|
2014
|
+
* TODO: [🍓] In `JsonFormatParser` implement `heal
|
|
2015
|
+
* TODO: [🍓] In `JsonFormatParser` implement `subvalueParsers`
|
|
2016
2016
|
* TODO: [🏢] Allow to expect something inside JSON objects and other formats
|
|
2017
2017
|
*/
|
|
2018
2018
|
|
|
2019
2019
|
/**
|
|
2020
2020
|
* Definition for any text - this will be always valid
|
|
2021
2021
|
*
|
|
2022
|
-
* Note: This is not useful for validation, but for splitting and mapping with `
|
|
2022
|
+
* Note: This is not useful for validation, but for splitting and mapping with `subvalueParsers`
|
|
2023
2023
|
*
|
|
2024
2024
|
* @public exported from `@promptbook/core`
|
|
2025
2025
|
*/
|
|
2026
|
-
const
|
|
2026
|
+
const TextFormatParser = {
|
|
2027
2027
|
formatName: 'TEXT',
|
|
2028
2028
|
isValid(value) {
|
|
2029
2029
|
return typeof value === 'string';
|
|
@@ -2032,9 +2032,9 @@
|
|
|
2032
2032
|
return typeof partialValue === 'string';
|
|
2033
2033
|
},
|
|
2034
2034
|
heal() {
|
|
2035
|
-
throw new UnexpectedError('It does not make sense to call `
|
|
2035
|
+
throw new UnexpectedError('It does not make sense to call `TextFormatParser.heal`');
|
|
2036
2036
|
},
|
|
2037
|
-
|
|
2037
|
+
subvalueParsers: [
|
|
2038
2038
|
{
|
|
2039
2039
|
subvalueName: 'LINE',
|
|
2040
2040
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
@@ -2054,10 +2054,10 @@
|
|
|
2054
2054
|
/**
|
|
2055
2055
|
* TODO: [1] Make type for XML Text and Schema
|
|
2056
2056
|
* TODO: [🧠][🤠] Here should be all words, characters, lines, paragraphs, pages available as subvalues
|
|
2057
|
-
* TODO: [🍓] In `
|
|
2058
|
-
* TODO: [🍓] In `
|
|
2059
|
-
* TODO: [🍓] In `
|
|
2060
|
-
* TODO: [🍓] In `
|
|
2057
|
+
* TODO: [🍓] In `TextFormatParser` implement simple `isValid`
|
|
2058
|
+
* TODO: [🍓] In `TextFormatParser` implement partial `canBeValid`
|
|
2059
|
+
* TODO: [🍓] In `TextFormatParser` implement `heal
|
|
2060
|
+
* TODO: [🍓] In `TextFormatParser` implement `subvalueParsers`
|
|
2061
2061
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
2062
2062
|
*/
|
|
2063
2063
|
|
|
@@ -2090,7 +2090,7 @@
|
|
|
2090
2090
|
*
|
|
2091
2091
|
* @private still in development [🏢]
|
|
2092
2092
|
*/
|
|
2093
|
-
const
|
|
2093
|
+
const XmlFormatParser = {
|
|
2094
2094
|
formatName: 'XML',
|
|
2095
2095
|
mimeType: 'application/xml',
|
|
2096
2096
|
isValid(value, settings, schema) {
|
|
@@ -2102,17 +2102,17 @@
|
|
|
2102
2102
|
heal(value, settings, schema) {
|
|
2103
2103
|
throw new Error('Not implemented');
|
|
2104
2104
|
},
|
|
2105
|
-
|
|
2105
|
+
subvalueParsers: [],
|
|
2106
2106
|
};
|
|
2107
2107
|
/**
|
|
2108
2108
|
* TODO: [🧠] Maybe propper instance of object
|
|
2109
2109
|
* TODO: [0] Make string_serialized_xml
|
|
2110
2110
|
* TODO: [1] Make type for XML Settings and Schema
|
|
2111
2111
|
* TODO: [🧠] What to use for validating XMLs - XSD,...
|
|
2112
|
-
* TODO: [🍓] In `
|
|
2113
|
-
* TODO: [🍓] In `
|
|
2114
|
-
* TODO: [🍓] In `
|
|
2115
|
-
* TODO: [🍓] In `
|
|
2112
|
+
* TODO: [🍓] In `XmlFormatParser` implement simple `isValid`
|
|
2113
|
+
* TODO: [🍓] In `XmlFormatParser` implement partial `canBeValid`
|
|
2114
|
+
* TODO: [🍓] In `XmlFormatParser` implement `heal
|
|
2115
|
+
* TODO: [🍓] In `XmlFormatParser` implement `subvalueParsers`
|
|
2116
2116
|
* TODO: [🏢] Allow to expect something inside XML and other formats
|
|
2117
2117
|
*/
|
|
2118
2118
|
|
|
@@ -2121,12 +2121,7 @@
|
|
|
2121
2121
|
*
|
|
2122
2122
|
* @private internal index of `...` <- TODO [🏢]
|
|
2123
2123
|
*/
|
|
2124
|
-
const FORMAT_DEFINITIONS = [
|
|
2125
|
-
JsonFormatDefinition,
|
|
2126
|
-
XmlFormatDefinition,
|
|
2127
|
-
TextFormatDefinition,
|
|
2128
|
-
CsvFormatDefinition,
|
|
2129
|
-
];
|
|
2124
|
+
const FORMAT_DEFINITIONS = [JsonFormatParser, XmlFormatParser, TextFormatParser, CsvFormatParser];
|
|
2130
2125
|
/**
|
|
2131
2126
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
2132
2127
|
*/
|
|
@@ -2691,14 +2686,14 @@
|
|
|
2691
2686
|
`));
|
|
2692
2687
|
// <- TODO: [🏢] List all supported format names
|
|
2693
2688
|
}
|
|
2694
|
-
const
|
|
2695
|
-
if (
|
|
2689
|
+
const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
|
|
2690
|
+
if (subvalueParser === undefined) {
|
|
2696
2691
|
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
2697
2692
|
Unsupported subformat name "${subformatName}" for format "${formatName}"
|
|
2698
2693
|
|
|
2699
2694
|
Available subformat names for format "${formatDefinition.formatName}":
|
|
2700
|
-
${block(formatDefinition.
|
|
2701
|
-
.map((
|
|
2695
|
+
${block(formatDefinition.subvalueParsers
|
|
2696
|
+
.map((subvalueParser) => subvalueParser.subvalueName)
|
|
2702
2697
|
.map((subvalueName) => `- ${subvalueName}`)
|
|
2703
2698
|
.join('\n'))}
|
|
2704
2699
|
`));
|