@promptbook/documents 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 +2 -2
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/documents",
|
|
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/documents.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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('child_process'), require('colors'), require('waitasecond'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'child_process', 'colors', 'waitasecond', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-documents"] = {}, global.promises, global.spaceTrim, global.child_process, global.colors, global.waitasecond, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, child_process, colors, waitasecond, cryptoJs, hexEncoder, path, prettier, parserHtml, crypto, rxjs, sha256, mimeTypes, papaparse) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
*
|
|
159
159
|
* @public exported from `@promptbook/core`
|
|
160
160
|
*/
|
|
161
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
161
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
162
162
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
163
163
|
/**
|
|
164
164
|
* Where to store the temporary downloads
|
|
@@ -2171,6 +2171,21 @@
|
|
|
2171
2171
|
return new SimplePipelineCollection(...promptbooks);
|
|
2172
2172
|
}
|
|
2173
2173
|
|
|
2174
|
+
/**
|
|
2175
|
+
* Generates random token
|
|
2176
|
+
*
|
|
2177
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2178
|
+
*
|
|
2179
|
+
* @private internal helper function
|
|
2180
|
+
* @returns secure random token
|
|
2181
|
+
*/
|
|
2182
|
+
function $randomToken(randomness) {
|
|
2183
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2187
|
+
*/
|
|
2188
|
+
|
|
2174
2189
|
/**
|
|
2175
2190
|
* This error indicates errors during the execution of the pipeline
|
|
2176
2191
|
*
|
|
@@ -2178,11 +2193,17 @@
|
|
|
2178
2193
|
*/
|
|
2179
2194
|
class PipelineExecutionError extends Error {
|
|
2180
2195
|
constructor(message) {
|
|
2196
|
+
// Added id parameter
|
|
2181
2197
|
super(message);
|
|
2182
2198
|
this.name = 'PipelineExecutionError';
|
|
2199
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
2200
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2183
2201
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
2184
2202
|
}
|
|
2185
2203
|
}
|
|
2204
|
+
/**
|
|
2205
|
+
* TODO: !!!!!! Add id to all errors
|
|
2206
|
+
*/
|
|
2186
2207
|
|
|
2187
2208
|
/**
|
|
2188
2209
|
* Determine if the pipeline is fully prepared
|
|
@@ -2222,18 +2243,33 @@
|
|
|
2222
2243
|
*/
|
|
2223
2244
|
|
|
2224
2245
|
/**
|
|
2225
|
-
*
|
|
2226
|
-
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
2229
|
-
* @private internal helper function
|
|
2230
|
-
* @returns secure random token
|
|
2246
|
+
* Recursively converts JSON strings to JSON objects
|
|
2247
|
+
|
|
2248
|
+
* @public exported from `@promptbook/utils`
|
|
2231
2249
|
*/
|
|
2232
|
-
function
|
|
2233
|
-
|
|
2250
|
+
function jsonStringsToJsons(object) {
|
|
2251
|
+
if (object === null) {
|
|
2252
|
+
return object;
|
|
2253
|
+
}
|
|
2254
|
+
if (Array.isArray(object)) {
|
|
2255
|
+
return object.map(jsonStringsToJsons);
|
|
2256
|
+
}
|
|
2257
|
+
if (typeof object !== 'object') {
|
|
2258
|
+
return object;
|
|
2259
|
+
}
|
|
2260
|
+
const newObject = { ...object };
|
|
2261
|
+
for (const [key, value] of Object.entries(object)) {
|
|
2262
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2263
|
+
newObject[key] = JSON.parse(value);
|
|
2264
|
+
}
|
|
2265
|
+
else {
|
|
2266
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return newObject;
|
|
2234
2270
|
}
|
|
2235
2271
|
/**
|
|
2236
|
-
* TODO:
|
|
2272
|
+
* TODO: Type the return type correctly
|
|
2237
2273
|
*/
|
|
2238
2274
|
|
|
2239
2275
|
/**
|
|
@@ -2396,7 +2432,7 @@
|
|
|
2396
2432
|
* @public exported from `@promptbook/utils`
|
|
2397
2433
|
*/
|
|
2398
2434
|
function deserializeError(error) {
|
|
2399
|
-
const { name, stack } = error;
|
|
2435
|
+
const { name, stack, id } = error; // Added id
|
|
2400
2436
|
let { message } = error;
|
|
2401
2437
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2402
2438
|
if (ErrorClass === undefined) {
|
|
@@ -2411,7 +2447,9 @@
|
|
|
2411
2447
|
${block(stack || '')}
|
|
2412
2448
|
`);
|
|
2413
2449
|
}
|
|
2414
|
-
|
|
2450
|
+
const deserializedError = new ErrorClass(message);
|
|
2451
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2452
|
+
return deserializedError;
|
|
2415
2453
|
}
|
|
2416
2454
|
|
|
2417
2455
|
/**
|
|
@@ -2461,17 +2499,19 @@
|
|
|
2461
2499
|
*/
|
|
2462
2500
|
function createTask(options) {
|
|
2463
2501
|
const { taskType, taskProcessCallback } = options;
|
|
2502
|
+
// TODO: [🐙] DRY
|
|
2464
2503
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2465
2504
|
let status = 'RUNNING';
|
|
2466
2505
|
const createdAt = new Date();
|
|
2467
2506
|
let updatedAt = createdAt;
|
|
2468
2507
|
const errors = [];
|
|
2469
2508
|
const warnings = [];
|
|
2470
|
-
|
|
2509
|
+
let currentValue = {};
|
|
2471
2510
|
const partialResultSubject = new rxjs.Subject();
|
|
2472
2511
|
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2473
2512
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2474
2513
|
Object.assign(currentValue, newOngoingResult);
|
|
2514
|
+
// <- TODO: assign deep
|
|
2475
2515
|
partialResultSubject.next(newOngoingResult);
|
|
2476
2516
|
});
|
|
2477
2517
|
finalResultPromise
|
|
@@ -2491,7 +2531,8 @@
|
|
|
2491
2531
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2492
2532
|
assertsTaskSuccessful(executionResult);
|
|
2493
2533
|
status = 'FINISHED';
|
|
2494
|
-
|
|
2534
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
2535
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2495
2536
|
partialResultSubject.next(executionResult);
|
|
2496
2537
|
}
|
|
2497
2538
|
catch (error) {
|
|
@@ -2555,19 +2596,21 @@
|
|
|
2555
2596
|
*/
|
|
2556
2597
|
function serializeError(error) {
|
|
2557
2598
|
const { name, message, stack } = error;
|
|
2599
|
+
const { id } = error;
|
|
2558
2600
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2559
2601
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2560
|
-
|
|
2602
|
+
|
|
2561
2603
|
Cannot serialize error with name "${name}"
|
|
2562
2604
|
|
|
2563
2605
|
${block(stack || message)}
|
|
2564
|
-
|
|
2606
|
+
|
|
2565
2607
|
`));
|
|
2566
2608
|
}
|
|
2567
2609
|
return {
|
|
2568
2610
|
name: name,
|
|
2569
2611
|
message,
|
|
2570
2612
|
stack,
|
|
2613
|
+
id, // Include id in the serialized object
|
|
2571
2614
|
};
|
|
2572
2615
|
}
|
|
2573
2616
|
|
|
@@ -4469,6 +4512,9 @@
|
|
|
4469
4512
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4470
4513
|
return text.length;
|
|
4471
4514
|
}
|
|
4515
|
+
/**
|
|
4516
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4517
|
+
*/
|
|
4472
4518
|
|
|
4473
4519
|
/**
|
|
4474
4520
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4500,6 +4546,9 @@
|
|
|
4500
4546
|
const lines = text.split('\n');
|
|
4501
4547
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4502
4548
|
}
|
|
4549
|
+
/**
|
|
4550
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4551
|
+
*/
|
|
4503
4552
|
|
|
4504
4553
|
/**
|
|
4505
4554
|
* Counts number of pages in the text
|
|
@@ -4511,6 +4560,9 @@
|
|
|
4511
4560
|
function countPages(text) {
|
|
4512
4561
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4513
4562
|
}
|
|
4563
|
+
/**
|
|
4564
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4565
|
+
*/
|
|
4514
4566
|
|
|
4515
4567
|
/**
|
|
4516
4568
|
* Counts number of paragraphs in the text
|
|
@@ -4520,6 +4572,9 @@
|
|
|
4520
4572
|
function countParagraphs(text) {
|
|
4521
4573
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4522
4574
|
}
|
|
4575
|
+
/**
|
|
4576
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4577
|
+
*/
|
|
4523
4578
|
|
|
4524
4579
|
/**
|
|
4525
4580
|
* Split text into sentences
|
|
@@ -4537,6 +4592,9 @@
|
|
|
4537
4592
|
function countSentences(text) {
|
|
4538
4593
|
return splitIntoSentences(text).length;
|
|
4539
4594
|
}
|
|
4595
|
+
/**
|
|
4596
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4597
|
+
*/
|
|
4540
4598
|
|
|
4541
4599
|
/**
|
|
4542
4600
|
* Counts number of words in the text
|
|
@@ -4550,6 +4608,9 @@
|
|
|
4550
4608
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4551
4609
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4552
4610
|
}
|
|
4611
|
+
/**
|
|
4612
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4613
|
+
*/
|
|
4553
4614
|
|
|
4554
4615
|
/**
|
|
4555
4616
|
* Index of all counter functions
|