@promptbook/documents 0.88.0-1 → 0.88.0-10

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.
@@ -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,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/documents",
3
- "version": "0.88.0-1",
3
+ "version": "0.88.0-10",
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-1"
50
+ "@promptbook/core": "0.88.0-10"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -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-1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-10';
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
@@ -2236,6 +2236,36 @@
2236
2236
  * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
2237
2237
  */
2238
2238
 
2239
+ /**
2240
+ * Recursively converts JSON strings to JSON objects
2241
+
2242
+ * @public exported from `@promptbook/utils`
2243
+ */
2244
+ function jsonStringsToJsons(object) {
2245
+ if (object === null) {
2246
+ return object;
2247
+ }
2248
+ if (Array.isArray(object)) {
2249
+ return object.map(jsonStringsToJsons);
2250
+ }
2251
+ if (typeof object !== 'object') {
2252
+ return object;
2253
+ }
2254
+ const newObject = { ...object };
2255
+ for (const [key, value] of Object.entries(object)) {
2256
+ if (typeof value === 'string' && isValidJsonString(value)) {
2257
+ newObject[key] = JSON.parse(value);
2258
+ }
2259
+ else {
2260
+ newObject[key] = jsonStringsToJsons(value);
2261
+ }
2262
+ }
2263
+ return newObject;
2264
+ }
2265
+ /**
2266
+ * TODO: Type the return type correctly
2267
+ */
2268
+
2239
2269
  /**
2240
2270
  * This error indicates problems parsing the format value
2241
2271
  *
@@ -2462,21 +2492,43 @@
2462
2492
  function createTask(options) {
2463
2493
  const { taskType, taskProcessCallback } = options;
2464
2494
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2465
- const partialResultSubject = new rxjs.BehaviorSubject({});
2495
+ let status = 'RUNNING';
2496
+ const createdAt = new Date();
2497
+ let updatedAt = createdAt;
2498
+ const errors = [];
2499
+ const warnings = [];
2500
+ let currentValue = {};
2501
+ const partialResultSubject = new rxjs.Subject();
2502
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2466
2503
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2504
+ Object.assign(currentValue, newOngoingResult);
2505
+ // <- TODO: assign deep
2467
2506
  partialResultSubject.next(newOngoingResult);
2468
2507
  });
2469
2508
  finalResultPromise
2470
2509
  .catch((error) => {
2510
+ errors.push(error);
2471
2511
  partialResultSubject.error(error);
2472
2512
  })
2473
- .then((value) => {
2474
- if (value) {
2513
+ .then((executionResult) => {
2514
+ if (executionResult) {
2475
2515
  try {
2476
- assertsTaskSuccessful(value);
2477
- partialResultSubject.next(value);
2516
+ updatedAt = new Date();
2517
+ errors.push(...executionResult.errors);
2518
+ warnings.push(...executionResult.warnings);
2519
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2520
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2521
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2522
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
2523
+ assertsTaskSuccessful(executionResult);
2524
+ status = 'FINISHED';
2525
+ currentValue = jsonStringsToJsons(executionResult);
2526
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
2527
+ partialResultSubject.next(executionResult);
2478
2528
  }
2479
2529
  catch (error) {
2530
+ status = 'ERROR';
2531
+ errors.push(error);
2480
2532
  partialResultSubject.error(error);
2481
2533
  }
2482
2534
  }
@@ -2493,12 +2545,33 @@
2493
2545
  return {
2494
2546
  taskType,
2495
2547
  taskId,
2548
+ get status() {
2549
+ return status;
2550
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
2551
+ },
2552
+ get createdAt() {
2553
+ return createdAt;
2554
+ // <- Note: [1]
2555
+ },
2556
+ get updatedAt() {
2557
+ return updatedAt;
2558
+ // <- Note: [1]
2559
+ },
2496
2560
  asPromise,
2497
2561
  asObservable() {
2498
2562
  return partialResultSubject.asObservable();
2499
2563
  },
2564
+ get errors() {
2565
+ return errors;
2566
+ // <- Note: [1]
2567
+ },
2568
+ get warnings() {
2569
+ return warnings;
2570
+ // <- Note: [1]
2571
+ },
2500
2572
  get currentValue() {
2501
- return partialResultSubject.value;
2573
+ return currentValue;
2574
+ // <- Note: [1]
2502
2575
  },
2503
2576
  };
2504
2577
  }
@@ -4863,7 +4936,7 @@
4863
4936
  Last result:
4864
4937
  ${block($ongoingTaskResult.$resultString === null
4865
4938
  ? 'null'
4866
- : $ongoingTaskResult.$resultString
4939
+ : spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
4867
4940
  .split('\n')
4868
4941
  .map((line) => `> ${line}`)
4869
4942
  .join('\n'))}