@promptbook/pdf 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/pdf",
|
|
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/pdf.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
|
"crypto": "^1.0.1",
|
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('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', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.
|
|
5
|
-
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs/promises'), require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('path'), require('prettier'), require('prettier/parser-html'), require('crypto'), require('rxjs'), require('waitasecond'), require('crypto-js/sha256'), require('mime-types'), require('papaparse')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'fs/promises', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'path', 'prettier', 'prettier/parser-html', 'crypto', 'rxjs', 'waitasecond', 'crypto-js/sha256', 'mime-types', 'papaparse'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-pdf"] = {}, global.promises, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.path, global.prettier, global.parserHtml, global.crypto, global.rxjs, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
|
|
5
|
+
})(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, crypto, rxjs, waitasecond, 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
|
|
|
@@ -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
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
*
|
|
158
158
|
* @public exported from `@promptbook/core`
|
|
159
159
|
*/
|
|
160
|
-
const DEFAULT_MAX_EXECUTION_ATTEMPTS =
|
|
160
|
+
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
161
161
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
162
162
|
/**
|
|
163
163
|
* Where to store the temporary downloads
|
|
@@ -2015,6 +2015,21 @@
|
|
|
2015
2015
|
}
|
|
2016
2016
|
}
|
|
2017
2017
|
|
|
2018
|
+
/**
|
|
2019
|
+
* Generates random token
|
|
2020
|
+
*
|
|
2021
|
+
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2022
|
+
*
|
|
2023
|
+
* @private internal helper function
|
|
2024
|
+
* @returns secure random token
|
|
2025
|
+
*/
|
|
2026
|
+
function $randomToken(randomness) {
|
|
2027
|
+
return crypto.randomBytes(randomness).toString('hex');
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2031
|
+
*/
|
|
2032
|
+
|
|
2018
2033
|
/**
|
|
2019
2034
|
* This error indicates errors during the execution of the pipeline
|
|
2020
2035
|
*
|
|
@@ -2022,11 +2037,17 @@
|
|
|
2022
2037
|
*/
|
|
2023
2038
|
class PipelineExecutionError extends Error {
|
|
2024
2039
|
constructor(message) {
|
|
2040
|
+
// Added id parameter
|
|
2025
2041
|
super(message);
|
|
2026
2042
|
this.name = 'PipelineExecutionError';
|
|
2043
|
+
// TODO: [🐙] DRY - Maybe $randomId
|
|
2044
|
+
this.id = `error-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2027
2045
|
Object.setPrototypeOf(this, PipelineExecutionError.prototype);
|
|
2028
2046
|
}
|
|
2029
2047
|
}
|
|
2048
|
+
/**
|
|
2049
|
+
* TODO: !!!!!! Add id to all errors
|
|
2050
|
+
*/
|
|
2030
2051
|
|
|
2031
2052
|
/**
|
|
2032
2053
|
* Determine if the pipeline is fully prepared
|
|
@@ -2065,21 +2086,6 @@
|
|
|
2065
2086
|
* - [♨] Are tasks prepared
|
|
2066
2087
|
*/
|
|
2067
2088
|
|
|
2068
|
-
/**
|
|
2069
|
-
* Generates random token
|
|
2070
|
-
*
|
|
2071
|
-
* Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
|
|
2072
|
-
*
|
|
2073
|
-
* @private internal helper function
|
|
2074
|
-
* @returns secure random token
|
|
2075
|
-
*/
|
|
2076
|
-
function $randomToken(randomness) {
|
|
2077
|
-
return crypto.randomBytes(randomness).toString('hex');
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2081
|
-
*/
|
|
2082
|
-
|
|
2083
2089
|
/**
|
|
2084
2090
|
* Recursively converts JSON strings to JSON objects
|
|
2085
2091
|
|
|
@@ -2270,7 +2276,7 @@
|
|
|
2270
2276
|
* @public exported from `@promptbook/utils`
|
|
2271
2277
|
*/
|
|
2272
2278
|
function deserializeError(error) {
|
|
2273
|
-
const { name, stack } = error;
|
|
2279
|
+
const { name, stack, id } = error; // Added id
|
|
2274
2280
|
let { message } = error;
|
|
2275
2281
|
let ErrorClass = ALL_ERRORS[error.name];
|
|
2276
2282
|
if (ErrorClass === undefined) {
|
|
@@ -2285,7 +2291,9 @@
|
|
|
2285
2291
|
${block(stack || '')}
|
|
2286
2292
|
`);
|
|
2287
2293
|
}
|
|
2288
|
-
|
|
2294
|
+
const deserializedError = new ErrorClass(message);
|
|
2295
|
+
deserializedError.id = id; // Assign id to the error object
|
|
2296
|
+
return deserializedError;
|
|
2289
2297
|
}
|
|
2290
2298
|
|
|
2291
2299
|
/**
|
|
@@ -2335,6 +2343,7 @@
|
|
|
2335
2343
|
*/
|
|
2336
2344
|
function createTask(options) {
|
|
2337
2345
|
const { taskType, taskProcessCallback } = options;
|
|
2346
|
+
// TODO: [🐙] DRY
|
|
2338
2347
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2339
2348
|
let status = 'RUNNING';
|
|
2340
2349
|
const createdAt = new Date();
|
|
@@ -2367,7 +2376,7 @@
|
|
|
2367
2376
|
assertsTaskSuccessful(executionResult);
|
|
2368
2377
|
status = 'FINISHED';
|
|
2369
2378
|
currentValue = jsonStringsToJsons(executionResult);
|
|
2370
|
-
// <- TODO:
|
|
2379
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2371
2380
|
partialResultSubject.next(executionResult);
|
|
2372
2381
|
}
|
|
2373
2382
|
catch (error) {
|
|
@@ -2431,19 +2440,21 @@
|
|
|
2431
2440
|
*/
|
|
2432
2441
|
function serializeError(error) {
|
|
2433
2442
|
const { name, message, stack } = error;
|
|
2443
|
+
const { id } = error;
|
|
2434
2444
|
if (!Object.keys(ALL_ERRORS).includes(name)) {
|
|
2435
2445
|
console.error(spaceTrim__default["default"]((block) => `
|
|
2436
|
-
|
|
2446
|
+
|
|
2437
2447
|
Cannot serialize error with name "${name}"
|
|
2438
2448
|
|
|
2439
2449
|
${block(stack || message)}
|
|
2440
|
-
|
|
2450
|
+
|
|
2441
2451
|
`));
|
|
2442
2452
|
}
|
|
2443
2453
|
return {
|
|
2444
2454
|
name: name,
|
|
2445
2455
|
message,
|
|
2446
2456
|
stack,
|
|
2457
|
+
id, // Include id in the serialized object
|
|
2447
2458
|
};
|
|
2448
2459
|
}
|
|
2449
2460
|
|
|
@@ -4355,6 +4366,9 @@
|
|
|
4355
4366
|
text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
|
|
4356
4367
|
return text.length;
|
|
4357
4368
|
}
|
|
4369
|
+
/**
|
|
4370
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4371
|
+
*/
|
|
4358
4372
|
|
|
4359
4373
|
/**
|
|
4360
4374
|
* Number of characters per standard line with 11pt Arial font size.
|
|
@@ -4386,6 +4400,9 @@
|
|
|
4386
4400
|
const lines = text.split('\n');
|
|
4387
4401
|
return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
|
|
4388
4402
|
}
|
|
4403
|
+
/**
|
|
4404
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4405
|
+
*/
|
|
4389
4406
|
|
|
4390
4407
|
/**
|
|
4391
4408
|
* Counts number of pages in the text
|
|
@@ -4397,6 +4414,9 @@
|
|
|
4397
4414
|
function countPages(text) {
|
|
4398
4415
|
return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
|
|
4399
4416
|
}
|
|
4417
|
+
/**
|
|
4418
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4419
|
+
*/
|
|
4400
4420
|
|
|
4401
4421
|
/**
|
|
4402
4422
|
* Counts number of paragraphs in the text
|
|
@@ -4406,6 +4426,9 @@
|
|
|
4406
4426
|
function countParagraphs(text) {
|
|
4407
4427
|
return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
|
|
4408
4428
|
}
|
|
4429
|
+
/**
|
|
4430
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4431
|
+
*/
|
|
4409
4432
|
|
|
4410
4433
|
/**
|
|
4411
4434
|
* Split text into sentences
|
|
@@ -4423,6 +4446,9 @@
|
|
|
4423
4446
|
function countSentences(text) {
|
|
4424
4447
|
return splitIntoSentences(text).length;
|
|
4425
4448
|
}
|
|
4449
|
+
/**
|
|
4450
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4451
|
+
*/
|
|
4426
4452
|
|
|
4427
4453
|
/**
|
|
4428
4454
|
* Counts number of words in the text
|
|
@@ -4436,6 +4462,9 @@
|
|
|
4436
4462
|
text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
4437
4463
|
return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
|
|
4438
4464
|
}
|
|
4465
|
+
/**
|
|
4466
|
+
* TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
|
|
4467
|
+
*/
|
|
4439
4468
|
|
|
4440
4469
|
/**
|
|
4441
4470
|
* Index of all counter functions
|