@promptbook/node 0.88.0-8 → 0.88.0
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/README.md +21 -27
- package/esm/index.es.js +69 -8
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/config.d.ts +1 -1
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +5 -0
- package/esm/typings/src/errors/utils/ErrorJson.d.ts +5 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +3 -0
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +3 -0
- package/esm/typings/src/utils/serialization/jsonStringsToJsons.d.ts +9 -0
- package/esm/typings/src/utils/serialization/jsonStringsToJsons.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +69 -8
- package/umd/index.umd.js.map +1 -1
|
@@ -62,6 +62,7 @@ import { clonePipeline } from '../utils/serialization/clonePipeline';
|
|
|
62
62
|
import { deepClone } from '../utils/serialization/deepClone';
|
|
63
63
|
import { exportJson } from '../utils/serialization/exportJson';
|
|
64
64
|
import { isSerializableAsJson } from '../utils/serialization/isSerializableAsJson';
|
|
65
|
+
import { jsonStringsToJsons } from '../utils/serialization/jsonStringsToJsons';
|
|
65
66
|
import { difference } from '../utils/sets/difference';
|
|
66
67
|
import { intersection } from '../utils/sets/intersection';
|
|
67
68
|
import { union } from '../utils/sets/union';
|
|
@@ -143,6 +144,7 @@ export { clonePipeline };
|
|
|
143
144
|
export { deepClone };
|
|
144
145
|
export { exportJson };
|
|
145
146
|
export { isSerializableAsJson };
|
|
147
|
+
export { jsonStringsToJsons };
|
|
146
148
|
export { difference };
|
|
147
149
|
export { intersection };
|
|
148
150
|
export { union };
|
|
@@ -162,7 +162,7 @@ export declare const DEFAULT_MAX_PARALLEL_COUNT = 5;
|
|
|
162
162
|
*
|
|
163
163
|
* @public exported from `@promptbook/core`
|
|
164
164
|
*/
|
|
165
|
-
export declare const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
165
|
+
export declare const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10;
|
|
166
166
|
/**
|
|
167
167
|
* @@@
|
|
168
168
|
* TODO: [🐝][main] !!3 Use
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { task_id } from '../types/typeAliases';
|
|
1
2
|
/**
|
|
2
3
|
* This error indicates errors during the execution of the pipeline
|
|
3
4
|
*
|
|
@@ -5,5 +6,9 @@
|
|
|
5
6
|
*/
|
|
6
7
|
export declare class PipelineExecutionError extends Error {
|
|
7
8
|
readonly name = "PipelineExecutionError";
|
|
9
|
+
readonly id?: task_id;
|
|
8
10
|
constructor(message: string);
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* TODO: !!!!!! Add id to all errors
|
|
14
|
+
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { task_id } from '../../types/typeAliases';
|
|
1
2
|
import type { ALL_ERRORS } from '../0-index';
|
|
2
3
|
/**
|
|
3
4
|
* Represents a serialized error or custom Promptbook error
|
|
@@ -5,6 +6,10 @@ import type { ALL_ERRORS } from '../0-index';
|
|
|
5
6
|
* Note: [🚉] This is fully serializable as JSON
|
|
6
7
|
*/
|
|
7
8
|
export type ErrorJson = {
|
|
9
|
+
/**
|
|
10
|
+
* The unique identifier of the error
|
|
11
|
+
*/
|
|
12
|
+
readonly id?: task_id;
|
|
8
13
|
/**
|
|
9
14
|
* The type of the error
|
|
10
15
|
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countCharacters(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countLines(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -7,3 +7,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
7
7
|
* @public exported from `@promptbook/utils`
|
|
8
8
|
*/
|
|
9
9
|
export declare function countPages(text: string): ExpectationAmount;
|
|
10
|
+
/**
|
|
11
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
12
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countParagraphs(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -11,3 +11,6 @@ export declare function splitIntoSentences(text: string): ReadonlyArray<string>;
|
|
|
11
11
|
* @public exported from `@promptbook/utils`
|
|
12
12
|
*/
|
|
13
13
|
export declare function countSentences(text: string): ExpectationAmount;
|
|
14
|
+
/**
|
|
15
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
16
|
+
*/
|
|
@@ -5,3 +5,6 @@ import type { ExpectationAmount } from '../../pipeline/PipelineJson/Expectations
|
|
|
5
5
|
* @public exported from `@promptbook/utils`
|
|
6
6
|
*/
|
|
7
7
|
export declare function countWords(text: string): ExpectationAmount;
|
|
8
|
+
/**
|
|
9
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
10
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.88.0
|
|
3
|
+
"version": "0.88.0",
|
|
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,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/node.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.88.0
|
|
50
|
+
"@promptbook/core": "0.88.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* @generated
|
|
47
47
|
* @see https://github.com/webgptorg/promptbook
|
|
48
48
|
*/
|
|
49
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0
|
|
49
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
|
|
50
50
|
/**
|
|
51
51
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
52
52
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
*
|
|
174
174
|
* @public exported from `@promptbook/core`
|
|
175
175
|
*/
|
|
176
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
176
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
177
177
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
178
178
|
/**
|
|
179
179
|
* Where to store the temporary downloads
|
|
@@ -1621,6 +1621,36 @@
|
|
|
1621
1621
|
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1622
1622
|
*/
|
|
1623
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* Recursively converts JSON strings to JSON objects
|
|
1626
|
+
|
|
1627
|
+
* @public exported from `@promptbook/utils`
|
|
1628
|
+
*/
|
|
1629
|
+
function jsonStringsToJsons(object) {
|
|
1630
|
+
if (object === null) {
|
|
1631
|
+
return object;
|
|
1632
|
+
}
|
|
1633
|
+
if (Array.isArray(object)) {
|
|
1634
|
+
return object.map(jsonStringsToJsons);
|
|
1635
|
+
}
|
|
1636
|
+
if (typeof object !== 'object') {
|
|
1637
|
+
return object;
|
|
1638
|
+
}
|
|
1639
|
+
const newObject = { ...object };
|
|
1640
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1641
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1642
|
+
newObject[key] = JSON.parse(value);
|
|
1643
|
+
}
|
|
1644
|
+
else {
|
|
1645
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return newObject;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* TODO: Type the return type correctly
|
|
1652
|
+
*/
|
|
1653
|
+
|
|
1624
1654
|
/**
|
|
1625
1655
|
* This error indicates errors during the execution of the pipeline
|
|
1626
1656
|
*
|
|
@@ -1628,11 +1658,17 @@
|
|
|
1628
1658
|
*/
|
|
1629
1659
|
class PipelineExecutionError extends Error {
|
|
1630
1660
|
constructor(message) {
|
|
1661
|
+
// Added id parameter
|
|
1631
1662
|
super(message);
|
|
1632
1663
|
this.name = 'PipelineExecutionError';
|
|
1664
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
1665
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1633
1666
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1634
1667
|
}
|
|
1635
1668
|
}
|
|
1669
|
+
/**
|
|
1670
|
+
* TODO: !!!!!! Add id to all errors
|
|
1671
|
+
*/
|
|
1636
1672
|
|
|
1637
1673
|
/**
|
|
1638
1674
|
* This error indicates problems parsing the format value
|
|
@@ -1820,7 +1856,7 @@
|
|
|
1820
1856
|
* @public exported from `@promptbook/utils`
|
|
1821
1857
|
*/
|
|
1822
1858
|
function deserializeError(error) {
|
|
1823
|
-
const { name, stack } = error;
|
|
1859
|
+
const { name, stack, id } = error; // Added id
|
|
1824
1860
|
let { message } = error;
|
|
1825
1861
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
1826
1862
|
if (ErrorClass === undefined) {
|
|
@@ -1835,7 +1871,9 @@
|
|
|
1835
1871
|
${block(stack || '')}
|
|
1836
1872
|
`);
|
|
1837
1873
|
}
|
|
1838
|
-
|
|
1874
|
+
const deserializedError = new ErrorClass(message);
|
|
1875
|
+
deserializedError.id = id; // Assign id to the error object
|
|
1876
|
+
return deserializedError;
|
|
1839
1877
|
}
|
|
1840
1878
|
|
|
1841
1879
|
/**
|
|
@@ -1885,17 +1923,19 @@
|
|
|
1885
1923
|
*/
|
|
1886
1924
|
function createTask(options) {
|
|
1887
1925
|
const { taskType, taskProcessCallback } = options;
|
|
1926
|
+
// TODO: [🐙] DRY
|
|
1888
1927
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1889
1928
|
let status = 'RUNNING';
|
|
1890
1929
|
const createdAt = new Date();
|
|
1891
1930
|
let updatedAt = createdAt;
|
|
1892
1931
|
const errors = [];
|
|
1893
1932
|
const warnings = [];
|
|
1894
|
-
|
|
1933
|
+
let currentValue = {};
|
|
1895
1934
|
const partialResultSubject = new rxjs.Subject();
|
|
1896
1935
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1897
1936
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
1898
1937
|
Object.assign(currentValue, newOngoingResult);
|
|
1938
|
+
// <- TODO: assign deep
|
|
1899
1939
|
partialResultSubject.next(newOngoingResult);
|
|
1900
1940
|
});
|
|
1901
1941
|
finalResultPromise
|
|
@@ -1915,7 +1955,8 @@
|
|
|
1915
1955
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1916
1956
|
assertsTaskSuccessful(executionResult);
|
|
1917
1957
|
status = 'FINISHED';
|
|
1918
|
-
|
|
1958
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
1959
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
1919
1960
|
partialResultSubject.next(executionResult);
|
|
1920
1961
|
}
|
|
1921
1962
|
catch (error) {
|
|
@@ -1979,19 +2020,21 @@
|
|
|
1979
2020
|
*/
|
|
1980
2021
|
function serializeError(error) {
|
|
1981
2022
|
const { name, message, stack } = error;
|
|
2023
|
+
const { id } = error;
|
|
1982
2024
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
1983
2025
|
console.error(spaceTrim__default["default"]((block) => `
|
|
1984
|
-
|
|
2026
|
+
|
|
1985
2027
|
Cannot serialize error with name "${name}"
|
|
1986
2028
|
|
|
1987
2029
|
${block(stack || message)}
|
|
1988
|
-
|
|
2030
|
+
|
|
1989
2031
|
`));
|
|
1990
2032
|
}
|
|
1991
2033
|
return {
|
|
1992
2034
|
name: name,
|
|
1993
2035
|
message,
|
|
1994
2036
|
stack,
|
|
2037
|
+
id, // Include id in the serialized object
|
|
1995
2038
|
};
|
|
1996
2039
|
}
|
|
1997
2040
|
|
|
@@ -3034,6 +3077,9 @@
|
|
|
3034
3077
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
3035
3078
|
return text.length;
|
|
3036
3079
|
}
|
|
3080
|
+
/**
|
|
3081
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3082
|
+
*/
|
|
3037
3083
|
|
|
3038
3084
|
/**
|
|
3039
3085
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -3065,6 +3111,9 @@
|
|
|
3065
3111
|
const lines = text.split('\n');
|
|
3066
3112
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
3067
3113
|
}
|
|
3114
|
+
/**
|
|
3115
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3116
|
+
*/
|
|
3068
3117
|
|
|
3069
3118
|
/**
|
|
3070
3119
|
* Counts number of pages in the text
|
|
@@ -3076,6 +3125,9 @@
|
|
|
3076
3125
|
function countPages(text) {
|
|
3077
3126
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
3078
3127
|
}
|
|
3128
|
+
/**
|
|
3129
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3130
|
+
*/
|
|
3079
3131
|
|
|
3080
3132
|
/**
|
|
3081
3133
|
* Counts number of paragraphs in the text
|
|
@@ -3085,6 +3137,9 @@
|
|
|
3085
3137
|
function countParagraphs(text) {
|
|
3086
3138
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
3087
3139
|
}
|
|
3140
|
+
/**
|
|
3141
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3142
|
+
*/
|
|
3088
3143
|
|
|
3089
3144
|
/**
|
|
3090
3145
|
* Split text into sentences
|
|
@@ -3102,6 +3157,9 @@
|
|
|
3102
3157
|
function countSentences(text) {
|
|
3103
3158
|
return splitIntoSentences(text).length;
|
|
3104
3159
|
}
|
|
3160
|
+
/**
|
|
3161
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3162
|
+
*/
|
|
3105
3163
|
|
|
3106
3164
|
const defaultDiacriticsRemovalMap = [
|
|
3107
3165
|
{
|
|
@@ -3376,6 +3434,9 @@
|
|
|
3376
3434
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
3377
3435
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
3378
3436
|
}
|
|
3437
|
+
/**
|
|
3438
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
3439
|
+
*/
|
|
3379
3440
|
|
|
3380
3441
|
/**
|
|
3381
3442
|
* Index of all counter functions
|