@promptbook/documents 0.88.0-9 → 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 +35 -18
- package/esm/index.es.js +52 -23
- package/esm/index.es.js.map +1 -1
- 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/package.json +2 -2
- package/umd/index.umd.js +55 -26
- package/umd/index.umd.js.map +1 -1
|
@@ -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
|
+
*/
|
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
|
|
@@ -2221,21 +2242,6 @@
|
|
|
2221
2242
|
* - [♨] Are tasks prepared
|
|
2222
2243
|
*/
|
|
2223
2244
|
|
|
2224
|
-
/**
|
|
2225
|
-
* Generates random token
|
|
2226
|
-
*
|
|
2227
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2228
|
-
*
|
|
2229
|
-
* @private internal helper function
|
|
2230
|
-
* @returns secure random token
|
|
2231
|
-
*/
|
|
2232
|
-
function $randomToken(randomness) {
|
|
2233
|
-
return crypto.randomBytes(randomness).toString('hex');
|
|
2234
|
-
}
|
|
2235
|
-
/**
|
|
2236
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2237
|
-
*/
|
|
2238
|
-
|
|
2239
2245
|
/**
|
|
2240
2246
|
* Recursively converts JSON strings to JSON objects
|
|
2241
2247
|
|
|
@@ -2426,7 +2432,7 @@
|
|
|
2426
2432
|
* @public exported from `@promptbook/utils`
|
|
2427
2433
|
*/
|
|
2428
2434
|
function deserializeError(error) {
|
|
2429
|
-
const { name, stack } = error;
|
|
2435
|
+
const { name, stack, id } = error; // Added id
|
|
2430
2436
|
let { message } = error;
|
|
2431
2437
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2432
2438
|
if (ErrorClass === undefined) {
|
|
@@ -2441,7 +2447,9 @@
|
|
|
2441
2447
|
${block(stack || '')}
|
|
2442
2448
|
`);
|
|
2443
2449
|
}
|
|
2444
|
-
|
|
2450
|
+
const deserializedError = new ErrorClass(message);
|
|
2451
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2452
|
+
return deserializedError;
|
|
2445
2453
|
}
|
|
2446
2454
|
|
|
2447
2455
|
/**
|
|
@@ -2491,6 +2499,7 @@
|
|
|
2491
2499
|
*/
|
|
2492
2500
|
function createTask(options) {
|
|
2493
2501
|
const { taskType, taskProcessCallback } = options;
|
|
2502
|
+
// TODO: [🐙] DRY
|
|
2494
2503
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2495
2504
|
let status = 'RUNNING';
|
|
2496
2505
|
const createdAt = new Date();
|
|
@@ -2523,7 +2532,7 @@
|
|
|
2523
2532
|
assertsTaskSuccessful(executionResult);
|
|
2524
2533
|
status = 'FINISHED';
|
|
2525
2534
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2526
|
-
// <- TODO:
|
|
2535
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2527
2536
|
partialResultSubject.next(executionResult);
|
|
2528
2537
|
}
|
|
2529
2538
|
catch (error) {
|
|
@@ -2587,19 +2596,21 @@
|
|
|
2587
2596
|
*/
|
|
2588
2597
|
function serializeError(error) {
|
|
2589
2598
|
const { name, message, stack } = error;
|
|
2599
|
+
const { id } = error;
|
|
2590
2600
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2591
2601
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2592
|
-
|
|
2602
|
+
|
|
2593
2603
|
Cannot serialize error with name "${name}"
|
|
2594
2604
|
|
|
2595
2605
|
${block(stack || message)}
|
|
2596
|
-
|
|
2606
|
+
|
|
2597
2607
|
`));
|
|
2598
2608
|
}
|
|
2599
2609
|
return {
|
|
2600
2610
|
name: name,
|
|
2601
2611
|
message,
|
|
2602
2612
|
stack,
|
|
2613
|
+
id, // Include id in the serialized object
|
|
2603
2614
|
};
|
|
2604
2615
|
}
|
|
2605
2616
|
|
|
@@ -4501,6 +4512,9 @@
|
|
|
4501
4512
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4502
4513
|
return text.length;
|
|
4503
4514
|
}
|
|
4515
|
+
/**
|
|
4516
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4517
|
+
*/
|
|
4504
4518
|
|
|
4505
4519
|
/**
|
|
4506
4520
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4532,6 +4546,9 @@
|
|
|
4532
4546
|
const lines = text.split('\n');
|
|
4533
4547
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4534
4548
|
}
|
|
4549
|
+
/**
|
|
4550
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4551
|
+
*/
|
|
4535
4552
|
|
|
4536
4553
|
/**
|
|
4537
4554
|
* Counts number of pages in the text
|
|
@@ -4543,6 +4560,9 @@
|
|
|
4543
4560
|
function countPages(text) {
|
|
4544
4561
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4545
4562
|
}
|
|
4563
|
+
/**
|
|
4564
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4565
|
+
*/
|
|
4546
4566
|
|
|
4547
4567
|
/**
|
|
4548
4568
|
* Counts number of paragraphs in the text
|
|
@@ -4552,6 +4572,9 @@
|
|
|
4552
4572
|
function countParagraphs(text) {
|
|
4553
4573
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4554
4574
|
}
|
|
4575
|
+
/**
|
|
4576
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4577
|
+
*/
|
|
4555
4578
|
|
|
4556
4579
|
/**
|
|
4557
4580
|
* Split text into sentences
|
|
@@ -4569,6 +4592,9 @@
|
|
|
4569
4592
|
function countSentences(text) {
|
|
4570
4593
|
return splitIntoSentences(text).length;
|
|
4571
4594
|
}
|
|
4595
|
+
/**
|
|
4596
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4597
|
+
*/
|
|
4572
4598
|
|
|
4573
4599
|
/**
|
|
4574
4600
|
* Counts number of words in the text
|
|
@@ -4582,6 +4608,9 @@
|
|
|
4582
4608
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4583
4609
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4584
4610
|
}
|
|
4611
|
+
/**
|
|
4612
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4613
|
+
*/
|
|
4585
4614
|
|
|
4586
4615
|
/**
|
|
4587
4616
|
* Index of all counter functions
|