@promptbook/pdf 0.88.0-1 → 0.88.0-11
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 +17 -24
- package/esm/index.es.js +82 -9
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/common/handleActionErrors.d.ts +11 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +24 -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 +81 -8
- package/umd/index.umd.js.map +1 -1
|
@@ -40,6 +40,7 @@ import type { ExecutionReportString } from '../execution/execution-report/Execut
|
|
|
40
40
|
import type { ExecutionReportStringOptions } from '../execution/execution-report/ExecutionReportStringOptions';
|
|
41
41
|
import type { ExecutionTask } from '../execution/ExecutionTask';
|
|
42
42
|
import type { PreparationTask } from '../execution/ExecutionTask';
|
|
43
|
+
import type { task_status } from '../execution/ExecutionTask';
|
|
43
44
|
import type { AbstractTask } from '../execution/ExecutionTask';
|
|
44
45
|
import type { Task } from '../execution/ExecutionTask';
|
|
45
46
|
import type { ExecutionTools } from '../execution/ExecutionTools';
|
|
@@ -322,6 +323,7 @@ export type { ExecutionReportString };
|
|
|
322
323
|
export type { ExecutionReportStringOptions };
|
|
323
324
|
export type { ExecutionTask };
|
|
324
325
|
export type { PreparationTask };
|
|
326
|
+
export type { task_status };
|
|
325
327
|
export type { AbstractTask };
|
|
326
328
|
export type { Task };
|
|
327
329
|
export type { ExecutionTools };
|
|
@@ -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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command as Program } from 'commander';
|
|
2
|
+
type actionCallbackFunction = Parameters<Program['action']>[0];
|
|
3
|
+
/**
|
|
4
|
+
* Wraps action to handle error console logging and exit process with error code
|
|
5
|
+
*
|
|
6
|
+
* @param action Action to be wrapped in error handling
|
|
7
|
+
* @returns Wrapped action
|
|
8
|
+
* @private internal helper function for CLI commands
|
|
9
|
+
*/
|
|
10
|
+
export declare function handleActionErrors(action: actionCallbackFunction): actionCallbackFunction;
|
|
11
|
+
export {};
|
|
@@ -40,6 +40,10 @@ export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
|
|
|
40
40
|
readonly taskType: 'PREPARATION';
|
|
41
41
|
readonly taskId: `prep-${task_id}`;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Status of a task
|
|
45
|
+
*/
|
|
46
|
+
export type task_status = 'RUNNING' | 'FINISHED' | 'ERROR';
|
|
43
47
|
/**
|
|
44
48
|
* Base interface for all task types
|
|
45
49
|
*/
|
|
@@ -52,6 +56,18 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
|
|
|
52
56
|
* Unique identifier for the task
|
|
53
57
|
*/
|
|
54
58
|
readonly taskId: task_id;
|
|
59
|
+
/**
|
|
60
|
+
* Status of the task
|
|
61
|
+
*/
|
|
62
|
+
readonly status: task_status;
|
|
63
|
+
/**
|
|
64
|
+
* Date when the task was created
|
|
65
|
+
*/
|
|
66
|
+
readonly createdAt: Date;
|
|
67
|
+
/**
|
|
68
|
+
* Date when the task was last updated
|
|
69
|
+
*/
|
|
70
|
+
readonly updatedAt: Date;
|
|
55
71
|
/**
|
|
56
72
|
* Gets a promise that resolves with the task result
|
|
57
73
|
*/
|
|
@@ -66,6 +82,14 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
|
|
|
66
82
|
* Gets just the current value which is mutated during the task processing
|
|
67
83
|
*/
|
|
68
84
|
currentValue: PartialDeep<TTaskResult>;
|
|
85
|
+
/**
|
|
86
|
+
* List of errors that occurred during the task processing
|
|
87
|
+
*/
|
|
88
|
+
readonly errors: Array<Error>;
|
|
89
|
+
/**
|
|
90
|
+
* List of warnings that occurred during the task processing
|
|
91
|
+
*/
|
|
92
|
+
readonly warnings: Array<Error>;
|
|
69
93
|
};
|
|
70
94
|
export type Task = ExecutionTask | PreparationTask;
|
|
71
95
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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-11",
|
|
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-11"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"crypto": "^1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -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-11';
|
|
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
|
|
@@ -2080,6 +2080,36 @@
|
|
|
2080
2080
|
* TODO: Maybe use nanoid instead https://github.com/ai/nanoid
|
|
2081
2081
|
*/
|
|
2082
2082
|
|
|
2083
|
+
/**
|
|
2084
|
+
* Recursively converts JSON strings to JSON objects
|
|
2085
|
+
|
|
2086
|
+
* @public exported from `@promptbook/utils`
|
|
2087
|
+
*/
|
|
2088
|
+
function jsonStringsToJsons(object) {
|
|
2089
|
+
if (object === null) {
|
|
2090
|
+
return object;
|
|
2091
|
+
}
|
|
2092
|
+
if (Array.isArray(object)) {
|
|
2093
|
+
return object.map(jsonStringsToJsons);
|
|
2094
|
+
}
|
|
2095
|
+
if (typeof object !== 'object') {
|
|
2096
|
+
return object;
|
|
2097
|
+
}
|
|
2098
|
+
const newObject = { ...object };
|
|
2099
|
+
for (const [key, value] of Object.entries(object)) {
|
|
2100
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
2101
|
+
newObject[key] = JSON.parse(value);
|
|
2102
|
+
}
|
|
2103
|
+
else {
|
|
2104
|
+
newObject[key] = jsonStringsToJsons(value);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
return newObject;
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* TODO: Type the return type correctly
|
|
2111
|
+
*/
|
|
2112
|
+
|
|
2083
2113
|
/**
|
|
2084
2114
|
* This error indicates problems parsing the format value
|
|
2085
2115
|
*
|
|
@@ -2306,21 +2336,43 @@
|
|
|
2306
2336
|
function createTask(options) {
|
|
2307
2337
|
const { taskType, taskProcessCallback } = options;
|
|
2308
2338
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2309
|
-
|
|
2339
|
+
let status = 'RUNNING';
|
|
2340
|
+
const createdAt = new Date();
|
|
2341
|
+
let updatedAt = createdAt;
|
|
2342
|
+
const errors = [];
|
|
2343
|
+
const warnings = [];
|
|
2344
|
+
let currentValue = {};
|
|
2345
|
+
const partialResultSubject = new rxjs.Subject();
|
|
2346
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2310
2347
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2348
|
+
Object.assign(currentValue, newOngoingResult);
|
|
2349
|
+
// <- TODO: assign deep
|
|
2311
2350
|
partialResultSubject.next(newOngoingResult);
|
|
2312
2351
|
});
|
|
2313
2352
|
finalResultPromise
|
|
2314
2353
|
.catch((error) => {
|
|
2354
|
+
errors.push(error);
|
|
2315
2355
|
partialResultSubject.error(error);
|
|
2316
2356
|
})
|
|
2317
|
-
.then((
|
|
2318
|
-
if (
|
|
2357
|
+
.then((executionResult) => {
|
|
2358
|
+
if (executionResult) {
|
|
2319
2359
|
try {
|
|
2320
|
-
|
|
2321
|
-
|
|
2360
|
+
updatedAt = new Date();
|
|
2361
|
+
errors.push(...executionResult.errors);
|
|
2362
|
+
warnings.push(...executionResult.warnings);
|
|
2363
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
2364
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2365
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2366
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2367
|
+
assertsTaskSuccessful(executionResult);
|
|
2368
|
+
status = 'FINISHED';
|
|
2369
|
+
currentValue = jsonStringsToJsons(executionResult);
|
|
2370
|
+
// <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
|
|
2371
|
+
partialResultSubject.next(executionResult);
|
|
2322
2372
|
}
|
|
2323
2373
|
catch (error) {
|
|
2374
|
+
status = 'ERROR';
|
|
2375
|
+
errors.push(error);
|
|
2324
2376
|
partialResultSubject.error(error);
|
|
2325
2377
|
}
|
|
2326
2378
|
}
|
|
@@ -2337,12 +2389,33 @@
|
|
|
2337
2389
|
return {
|
|
2338
2390
|
taskType,
|
|
2339
2391
|
taskId,
|
|
2392
|
+
get status() {
|
|
2393
|
+
return status;
|
|
2394
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
2395
|
+
},
|
|
2396
|
+
get createdAt() {
|
|
2397
|
+
return createdAt;
|
|
2398
|
+
// <- Note: [1]
|
|
2399
|
+
},
|
|
2400
|
+
get updatedAt() {
|
|
2401
|
+
return updatedAt;
|
|
2402
|
+
// <- Note: [1]
|
|
2403
|
+
},
|
|
2340
2404
|
asPromise,
|
|
2341
2405
|
asObservable() {
|
|
2342
2406
|
return partialResultSubject.asObservable();
|
|
2343
2407
|
},
|
|
2408
|
+
get errors() {
|
|
2409
|
+
return errors;
|
|
2410
|
+
// <- Note: [1]
|
|
2411
|
+
},
|
|
2412
|
+
get warnings() {
|
|
2413
|
+
return warnings;
|
|
2414
|
+
// <- Note: [1]
|
|
2415
|
+
},
|
|
2344
2416
|
get currentValue() {
|
|
2345
|
-
return
|
|
2417
|
+
return currentValue;
|
|
2418
|
+
// <- Note: [1]
|
|
2346
2419
|
},
|
|
2347
2420
|
};
|
|
2348
2421
|
}
|
|
@@ -4717,7 +4790,7 @@
|
|
|
4717
4790
|
Last result:
|
|
4718
4791
|
${block($ongoingTaskResult.$resultString === null
|
|
4719
4792
|
? 'null'
|
|
4720
|
-
: $ongoingTaskResult.$resultString
|
|
4793
|
+
: spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
|
|
4721
4794
|
.split('\n')
|
|
4722
4795
|
.map((line) => `> ${line}`)
|
|
4723
4796
|
.join('\n'))}
|