@promptbook/markdown-utils 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 +79 -18
- 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 +1 -1
- package/umd/index.umd.js +82 -21
- 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
package/umd/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, spaceTrim, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('path'), require('crypto-js'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/enc-hex', 'crypto-js/sha256', 'path', 'crypto-js', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-markdown-utils"] = {}, global.spaceTrim, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.hexEncoder, global.sha256, global.path, global.cryptoJs, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, spaceTrim, prettier, parserHtml, crypto, rxjs, waitasecond, hexEncoder, sha256, path, cryptoJs, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -659,7 +659,7 @@
|
|
|
659
659
|
*
|
|
660
660
|
* @public exported from `@promptbook/core`
|
|
661
661
|
*/
|
|
662
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
662
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
663
663
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
664
664
|
/**
|
|
665
665
|
* Where to store the temporary downloads
|
|
@@ -1676,6 +1676,21 @@
|
|
|
1676
1676
|
}
|
|
1677
1677
|
}
|
|
1678
1678
|
|
|
1679
|
+
/**
|
|
1680
|
+
* Generates random token
|
|
1681
|
+
*
|
|
1682
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
1683
|
+
*
|
|
1684
|
+
* @private internal helper function
|
|
1685
|
+
* @returns secure random token
|
|
1686
|
+
*/
|
|
1687
|
+
function $randomToken(randomness) {
|
|
1688
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
1692
|
+
*/
|
|
1693
|
+
|
|
1679
1694
|
/**
|
|
1680
1695
|
* This error indicates errors during the execution of the pipeline
|
|
1681
1696
|
*
|
|
@@ -1683,11 +1698,17 @@
|
|
|
1683
1698
|
*/
|
|
1684
1699
|
class PipelineExecutionError extends Error {
|
|
1685
1700
|
constructor(message) {
|
|
1701
|
+
// Added id parameter
|
|
1686
1702
|
super(message);
|
|
1687
1703
|
this.name = 'PipelineExecutionError';
|
|
1704
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
1705
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1688
1706
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
1689
1707
|
}
|
|
1690
1708
|
}
|
|
1709
|
+
/**
|
|
1710
|
+
* TODO: !!!!!! Add id to all errors
|
|
1711
|
+
*/
|
|
1691
1712
|
|
|
1692
1713
|
/**
|
|
1693
1714
|
* Determine if the pipeline is fully prepared
|
|
@@ -1727,18 +1748,33 @@
|
|
|
1727
1748
|
*/
|
|
1728
1749
|
|
|
1729
1750
|
/**
|
|
1730
|
-
*
|
|
1731
|
-
|
|
1732
|
-
*
|
|
1733
|
-
*
|
|
1734
|
-
* @private internal helper function
|
|
1735
|
-
* @returns secure random token
|
|
1751
|
+
* Recursively converts JSON strings to JSON objects
|
|
1752
|
+
|
|
1753
|
+
* @public exported from `@promptbook/utils`
|
|
1736
1754
|
*/
|
|
1737
|
-
function
|
|
1738
|
-
|
|
1755
|
+
function jsonStringsToJsons(object) {
|
|
1756
|
+
if (object === null) {
|
|
1757
|
+
return object;
|
|
1758
|
+
}
|
|
1759
|
+
if (Array.isArray(object)) {
|
|
1760
|
+
return object.map(jsonStringsToJsons);
|
|
1761
|
+
}
|
|
1762
|
+
if (typeof object !== 'object') {
|
|
1763
|
+
return object;
|
|
1764
|
+
}
|
|
1765
|
+
const newObject = { ...object };
|
|
1766
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1767
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
1768
|
+
newObject[key] = JSON.parse(value);
|
|
1769
|
+
}
|
|
1770
|
+
else {
|
|
1771
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return newObject;
|
|
1739
1775
|
}
|
|
1740
1776
|
/**
|
|
1741
|
-
* TODO:
|
|
1777
|
+
* TODO: Type the return type correctly
|
|
1742
1778
|
*/
|
|
1743
1779
|
|
|
1744
1780
|
/**
|
|
@@ -1927,7 +1963,7 @@
|
|
|
1927
1963
|
* @public exported from `@promptbook/utils`
|
|
1928
1964
|
*/
|
|
1929
1965
|
function deserializeError(error) {
|
|
1930
|
-
const { name, stack } = error;
|
|
1966
|
+
const { name, stack, id } = error; // Added id
|
|
1931
1967
|
let { message } = error;
|
|
1932
1968
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
1933
1969
|
if (ErrorClass === undefined) {
|
|
@@ -1942,7 +1978,9 @@
|
|
|
1942
1978
|
${block(stack || '')}
|
|
1943
1979
|
`);
|
|
1944
1980
|
}
|
|
1945
|
-
|
|
1981
|
+
const deserializedError = new ErrorClass(message);
|
|
1982
|
+
deserializedError.id = id; // Assign id to the error object
|
|
1983
|
+
return deserializedError;
|
|
1946
1984
|
}
|
|
1947
1985
|
|
|
1948
1986
|
/**
|
|
@@ -1992,17 +2030,19 @@
|
|
|
1992
2030
|
*/
|
|
1993
2031
|
function createTask(options) {
|
|
1994
2032
|
const { taskType, taskProcessCallback } = options;
|
|
2033
|
+
// TODO: [🐙] DRY
|
|
1995
2034
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1996
2035
|
let status = 'RUNNING';
|
|
1997
2036
|
const createdAt = new Date();
|
|
1998
2037
|
let updatedAt = createdAt;
|
|
1999
2038
|
const errors = [];
|
|
2000
2039
|
const warnings = [];
|
|
2001
|
-
|
|
2040
|
+
let currentValue = {};
|
|
2002
2041
|
const partialResultSubject = new rxjs.Subject();
|
|
2003
2042
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2004
2043
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2005
2044
|
Object.assign(currentValue, newOngoingResult);
|
|
2045
|
+
// <- TODO: assign deep
|
|
2006
2046
|
partialResultSubject.next(newOngoingResult);
|
|
2007
2047
|
});
|
|
2008
2048
|
finalResultPromise
|
|
@@ -2022,7 +2062,8 @@
|
|
|
2022
2062
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2023
2063
|
assertsTaskSuccessful(executionResult);
|
|
2024
2064
|
status = 'FINISHED';
|
|
2025
|
-
|
|
2065
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
2066
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2026
2067
|
partialResultSubject.next(executionResult);
|
|
2027
2068
|
}
|
|
2028
2069
|
catch (error) {
|
|
@@ -2086,19 +2127,21 @@
|
|
|
2086
2127
|
*/
|
|
2087
2128
|
function serializeError(error) {
|
|
2088
2129
|
const { name, message, stack } = error;
|
|
2130
|
+
const { id } = error;
|
|
2089
2131
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2090
2132
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2091
|
-
|
|
2133
|
+
|
|
2092
2134
|
Cannot serialize error with name "${name}"
|
|
2093
2135
|
|
|
2094
2136
|
${block(stack || message)}
|
|
2095
|
-
|
|
2137
|
+
|
|
2096
2138
|
`));
|
|
2097
2139
|
}
|
|
2098
2140
|
return {
|
|
2099
2141
|
name: name,
|
|
2100
2142
|
message,
|
|
2101
2143
|
stack,
|
|
2144
|
+
id, // Include id in the serialized object
|
|
2102
2145
|
};
|
|
2103
2146
|
}
|
|
2104
2147
|
|
|
@@ -4294,6 +4337,9 @@
|
|
|
4294
4337
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4295
4338
|
return text.length;
|
|
4296
4339
|
}
|
|
4340
|
+
/**
|
|
4341
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4342
|
+
*/
|
|
4297
4343
|
|
|
4298
4344
|
/**
|
|
4299
4345
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4325,6 +4371,9 @@
|
|
|
4325
4371
|
const lines = text.split('\n');
|
|
4326
4372
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4327
4373
|
}
|
|
4374
|
+
/**
|
|
4375
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4376
|
+
*/
|
|
4328
4377
|
|
|
4329
4378
|
/**
|
|
4330
4379
|
* Counts number of pages in the text
|
|
@@ -4336,6 +4385,9 @@
|
|
|
4336
4385
|
function countPages(text) {
|
|
4337
4386
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4338
4387
|
}
|
|
4388
|
+
/**
|
|
4389
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4390
|
+
*/
|
|
4339
4391
|
|
|
4340
4392
|
/**
|
|
4341
4393
|
* Counts number of paragraphs in the text
|
|
@@ -4345,6 +4397,9 @@
|
|
|
4345
4397
|
function countParagraphs(text) {
|
|
4346
4398
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4347
4399
|
}
|
|
4400
|
+
/**
|
|
4401
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4402
|
+
*/
|
|
4348
4403
|
|
|
4349
4404
|
/**
|
|
4350
4405
|
* Split text into sentences
|
|
@@ -4362,6 +4417,9 @@
|
|
|
4362
4417
|
function countSentences(text) {
|
|
4363
4418
|
return splitIntoSentences(text).length;
|
|
4364
4419
|
}
|
|
4420
|
+
/**
|
|
4421
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4422
|
+
*/
|
|
4365
4423
|
|
|
4366
4424
|
/**
|
|
4367
4425
|
* Counts number of words in the text
|
|
@@ -4375,6 +4433,9 @@
|
|
|
4375
4433
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4376
4434
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4377
4435
|
}
|
|
4436
|
+
/**
|
|
4437
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4438
|
+
*/
|
|
4378
4439
|
|
|
4379
4440
|
/**
|
|
4380
4441
|
* Index of all counter functions
|