@promptbook/pdf 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.
@@ -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 = 3;
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,9 @@
1
+ /**
2
+ * Recursively converts JSON strings to JSON objects
3
+
4
+ * @public exported from `@promptbook/utils`
5
+ */
6
+ export declare function jsonStringsToJsons<T>(object: T): T;
7
+ /**
8
+ * TODO: Type the return type correctly
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/pdf",
3
- "version": "0.88.0-8",
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-8"
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('rxjs'), require('crypto'), 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', 'rxjs', 'crypto', '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.rxjs, global.crypto, global.waitasecond, global.sha256, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, promises, spaceTrim, cryptoJs, hexEncoder, path, prettier, parserHtml, rxjs, crypto, waitasecond, sha256, mimeTypes, papaparse) { 'use strict';
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-8';
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 = 3; // <- TODO: [🤹‍♂️]
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
@@ -2066,18 +2087,33 @@
2066
2087
  */
2067
2088
 
2068
2089
  /**
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
2090
+ * Recursively converts JSON strings to JSON objects
2091
+
2092
+ * @public exported from `@promptbook/utils`
2075
2093
  */
2076
- function $randomToken(randomness) {
2077
- return crypto.randomBytes(randomness).toString('hex');
2094
+ function jsonStringsToJsons(object) {
2095
+ if (object === null) {
2096
+ return object;
2097
+ }
2098
+ if (Array.isArray(object)) {
2099
+ return object.map(jsonStringsToJsons);
2100
+ }
2101
+ if (typeof object !== 'object') {
2102
+ return object;
2103
+ }
2104
+ const newObject = { ...object };
2105
+ for (const [key, value] of Object.entries(object)) {
2106
+ if (typeof value === 'string' && isValidJsonString(value)) {
2107
+ newObject[key] = JSON.parse(value);
2108
+ }
2109
+ else {
2110
+ newObject[key] = jsonStringsToJsons(value);
2111
+ }
2112
+ }
2113
+ return newObject;
2078
2114
  }
2079
2115
  /**
2080
- * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2116
+ * TODO: Type the return type correctly
2081
2117
  */
2082
2118
 
2083
2119
  /**
@@ -2240,7 +2276,7 @@
2240
2276
  * @public exported from `@promptbook/utils`
2241
2277
  */
2242
2278
  function deserializeError(error) {
2243
- const { name, stack } = error;
2279
+ const { name, stack, id } = error; // Added id
2244
2280
  let { message } = error;
2245
2281
  let ErrorClass = ALL_ERRORS[error.name];
2246
2282
  if (ErrorClass === undefined) {
@@ -2255,7 +2291,9 @@
2255
2291
  ${block(stack || '')}
2256
2292
  `);
2257
2293
  }
2258
- return new ErrorClass(message);
2294
+ const deserializedError = new ErrorClass(message);
2295
+ deserializedError.id = id; // Assign id to the error object
2296
+ return deserializedError;
2259
2297
  }
2260
2298
 
2261
2299
  /**
@@ -2305,17 +2343,19 @@
2305
2343
  */
2306
2344
  function createTask(options) {
2307
2345
  const { taskType, taskProcessCallback } = options;
2346
+ // TODO: [🐙] DRY
2308
2347
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2309
2348
  let status = 'RUNNING';
2310
2349
  const createdAt = new Date();
2311
2350
  let updatedAt = createdAt;
2312
2351
  const errors = [];
2313
2352
  const warnings = [];
2314
- const currentValue = {};
2353
+ let currentValue = {};
2315
2354
  const partialResultSubject = new rxjs.Subject();
2316
2355
  // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2317
2356
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2318
2357
  Object.assign(currentValue, newOngoingResult);
2358
+ // <- TODO: assign deep
2319
2359
  partialResultSubject.next(newOngoingResult);
2320
2360
  });
2321
2361
  finalResultPromise
@@ -2335,7 +2375,8 @@
2335
2375
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2336
2376
  assertsTaskSuccessful(executionResult);
2337
2377
  status = 'FINISHED';
2338
- Object.assign(currentValue, executionResult);
2378
+ currentValue = jsonStringsToJsons(executionResult);
2379
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
2339
2380
  partialResultSubject.next(executionResult);
2340
2381
  }
2341
2382
  catch (error) {
@@ -2399,19 +2440,21 @@
2399
2440
  */
2400
2441
  function serializeError(error) {
2401
2442
  const { name, message, stack } = error;
2443
+ const { id } = error;
2402
2444
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2403
2445
  console.error(spaceTrim__default["default"]((block) => `
2404
-
2446
+
2405
2447
  Cannot serialize error with name "${name}"
2406
2448
 
2407
2449
  ${block(stack || message)}
2408
-
2450
+
2409
2451
  `));
2410
2452
  }
2411
2453
  return {
2412
2454
  name: name,
2413
2455
  message,
2414
2456
  stack,
2457
+ id, // Include id in the serialized object
2415
2458
  };
2416
2459
  }
2417
2460
 
@@ -4323,6 +4366,9 @@
4323
4366
  text = text.replace(/\p{Extended_Pictographic}(\u{200D}\p{Extended_Pictographic})*/gu, '-');
4324
4367
  return text.length;
4325
4368
  }
4369
+ /**
4370
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4371
+ */
4326
4372
 
4327
4373
  /**
4328
4374
  * Number of characters per standard line with 11pt Arial font size.
@@ -4354,6 +4400,9 @@
4354
4400
  const lines = text.split('\n');
4355
4401
  return lines.reduce((count, line) => count + Math.ceil(line.length / CHARACTERS_PER_STANDARD_LINE), 0);
4356
4402
  }
4403
+ /**
4404
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4405
+ */
4357
4406
 
4358
4407
  /**
4359
4408
  * Counts number of pages in the text
@@ -4365,6 +4414,9 @@
4365
4414
  function countPages(text) {
4366
4415
  return Math.ceil(countLines(text) / LINES_PER_STANDARD_PAGE);
4367
4416
  }
4417
+ /**
4418
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4419
+ */
4368
4420
 
4369
4421
  /**
4370
4422
  * Counts number of paragraphs in the text
@@ -4374,6 +4426,9 @@
4374
4426
  function countParagraphs(text) {
4375
4427
  return text.split(/\n\s*\n/).filter((paragraph) => paragraph.trim() !== '').length;
4376
4428
  }
4429
+ /**
4430
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4431
+ */
4377
4432
 
4378
4433
  /**
4379
4434
  * Split text into sentences
@@ -4391,6 +4446,9 @@
4391
4446
  function countSentences(text) {
4392
4447
  return splitIntoSentences(text).length;
4393
4448
  }
4449
+ /**
4450
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4451
+ */
4394
4452
 
4395
4453
  /**
4396
4454
  * Counts number of words in the text
@@ -4404,6 +4462,9 @@
4404
4462
  text = text.replace(/([a-z])([A-Z])/g, '$1 $2');
4405
4463
  return text.split(/[^a-zа-я0-9]+/i).filter((word) => word.length > 0).length;
4406
4464
  }
4465
+ /**
4466
+ * TODO: [🥴] Implement counting in formats - like JSON, CSV, XML,...
4467
+ */
4407
4468
 
4408
4469
  /**
4409
4470
  * Index of all counter functions