@promptbook/remote-server 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.
@@ -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/remote-server",
3
- "version": "0.88.0-1",
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/remote-server.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.88.0-1"
50
+ "@promptbook/core": "0.88.0-11"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -28,7 +28,7 @@
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-11';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1718,6 +1718,57 @@
1718
1718
  * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1719
1719
  */
1720
1720
 
1721
+ /**
1722
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1723
+ *
1724
+ * @public exported from `@promptbook/utils`
1725
+ */
1726
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1727
+ try {
1728
+ JSON.parse(value);
1729
+ return true;
1730
+ }
1731
+ catch (error) {
1732
+ if (!(error instanceof Error)) {
1733
+ throw error;
1734
+ }
1735
+ if (error.message.includes('Unexpected token')) {
1736
+ return false;
1737
+ }
1738
+ return false;
1739
+ }
1740
+ }
1741
+
1742
+ /**
1743
+ * Recursively converts JSON strings to JSON objects
1744
+
1745
+ * @public exported from `@promptbook/utils`
1746
+ */
1747
+ function jsonStringsToJsons(object) {
1748
+ if (object === null) {
1749
+ return object;
1750
+ }
1751
+ if (Array.isArray(object)) {
1752
+ return object.map(jsonStringsToJsons);
1753
+ }
1754
+ if (typeof object !== 'object') {
1755
+ return object;
1756
+ }
1757
+ const newObject = { ...object };
1758
+ for (const [key, value] of Object.entries(object)) {
1759
+ if (typeof value === 'string' && isValidJsonString(value)) {
1760
+ newObject[key] = JSON.parse(value);
1761
+ }
1762
+ else {
1763
+ newObject[key] = jsonStringsToJsons(value);
1764
+ }
1765
+ }
1766
+ return newObject;
1767
+ }
1768
+ /**
1769
+ * TODO: Type the return type correctly
1770
+ */
1771
+
1721
1772
  /**
1722
1773
  * Deserializes the error object
1723
1774
  *
@@ -1790,21 +1841,43 @@
1790
1841
  function createTask(options) {
1791
1842
  const { taskType, taskProcessCallback } = options;
1792
1843
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1793
- const partialResultSubject = new rxjs.BehaviorSubject({});
1844
+ let status = 'RUNNING';
1845
+ const createdAt = new Date();
1846
+ let updatedAt = createdAt;
1847
+ const errors = [];
1848
+ const warnings = [];
1849
+ let currentValue = {};
1850
+ const partialResultSubject = new rxjs.Subject();
1851
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1794
1852
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1853
+ Object.assign(currentValue, newOngoingResult);
1854
+ // <- TODO: assign deep
1795
1855
  partialResultSubject.next(newOngoingResult);
1796
1856
  });
1797
1857
  finalResultPromise
1798
1858
  .catch((error) => {
1859
+ errors.push(error);
1799
1860
  partialResultSubject.error(error);
1800
1861
  })
1801
- .then((value) => {
1802
- if (value) {
1862
+ .then((executionResult) => {
1863
+ if (executionResult) {
1803
1864
  try {
1804
- assertsTaskSuccessful(value);
1805
- partialResultSubject.next(value);
1865
+ updatedAt = new Date();
1866
+ errors.push(...executionResult.errors);
1867
+ warnings.push(...executionResult.warnings);
1868
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
1869
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
1870
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
1871
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
1872
+ assertsTaskSuccessful(executionResult);
1873
+ status = 'FINISHED';
1874
+ currentValue = jsonStringsToJsons(executionResult);
1875
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1876
+ partialResultSubject.next(executionResult);
1806
1877
  }
1807
1878
  catch (error) {
1879
+ status = 'ERROR';
1880
+ errors.push(error);
1808
1881
  partialResultSubject.error(error);
1809
1882
  }
1810
1883
  }
@@ -1821,12 +1894,33 @@
1821
1894
  return {
1822
1895
  taskType,
1823
1896
  taskId,
1897
+ get status() {
1898
+ return status;
1899
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
1900
+ },
1901
+ get createdAt() {
1902
+ return createdAt;
1903
+ // <- Note: [1]
1904
+ },
1905
+ get updatedAt() {
1906
+ return updatedAt;
1907
+ // <- Note: [1]
1908
+ },
1824
1909
  asPromise,
1825
1910
  asObservable() {
1826
1911
  return partialResultSubject.asObservable();
1827
1912
  },
1913
+ get errors() {
1914
+ return errors;
1915
+ // <- Note: [1]
1916
+ },
1917
+ get warnings() {
1918
+ return warnings;
1919
+ // <- Note: [1]
1920
+ },
1828
1921
  get currentValue() {
1829
- return partialResultSubject.value;
1922
+ return currentValue;
1923
+ // <- Note: [1]
1830
1924
  },
1831
1925
  };
1832
1926
  }
@@ -1901,27 +1995,6 @@
1901
1995
  * TODO: [🍏] Implement for MacOs
1902
1996
  */
1903
1997
 
1904
- /**
1905
- * Function isValidJsonString will tell you if the string is valid JSON or not
1906
- *
1907
- * @public exported from `@promptbook/utils`
1908
- */
1909
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
1910
- try {
1911
- JSON.parse(value);
1912
- return true;
1913
- }
1914
- catch (error) {
1915
- if (!(error instanceof Error)) {
1916
- throw error;
1917
- }
1918
- if (error.message.includes('Unexpected token')) {
1919
- return false;
1920
- }
1921
- return false;
1922
- }
1923
- }
1924
-
1925
1998
  /**
1926
1999
  * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1927
2000
  * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
@@ -5050,7 +5123,7 @@
5050
5123
  Last result:
5051
5124
  ${block($ongoingTaskResult.$resultString === null
5052
5125
  ? 'null'
5053
- : $ongoingTaskResult.$resultString
5126
+ : spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
5054
5127
  .split('\n')
5055
5128
  .map((line) => `> ${line}`)
5056
5129
  .join('\n'))}
@@ -6737,8 +6810,35 @@
6737
6810
  .send({ error: serializeError(error) });
6738
6811
  }
6739
6812
  });
6813
+ function exportExecutionTask(executionTask, isFull) {
6814
+ // <- TODO: [🧠] This should be maybe method of `ExecutionTask` itself
6815
+ const { taskType, taskId, status, errors, warnings, createdAt, updatedAt, currentValue } = executionTask;
6816
+ if (isFull) {
6817
+ return {
6818
+ nonce: '✨',
6819
+ taskId,
6820
+ taskType,
6821
+ status,
6822
+ errors: errors.map(serializeError),
6823
+ warnings: warnings.map(serializeError),
6824
+ createdAt,
6825
+ updatedAt,
6826
+ currentValue,
6827
+ };
6828
+ }
6829
+ else {
6830
+ return {
6831
+ nonce: '✨',
6832
+ taskId,
6833
+ taskType,
6834
+ status,
6835
+ createdAt,
6836
+ updatedAt,
6837
+ };
6838
+ }
6839
+ }
6740
6840
  app.get(`${rootPath}/executions`, async (request, response) => {
6741
- response.send(runningExecutionTasks);
6841
+ response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
6742
6842
  });
6743
6843
  app.get(`${rootPath}/executions/last`, async (request, response) => {
6744
6844
  // TODO: [🤬] Filter only for user
@@ -6746,20 +6846,20 @@
6746
6846
  response.status(404).send('No execution tasks found');
6747
6847
  return;
6748
6848
  }
6749
- const lastExecution = runningExecutionTasks[runningExecutionTasks.length - 1];
6750
- response.send(lastExecution);
6849
+ const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
6850
+ response.send(exportExecutionTask(lastExecutionTask, true));
6751
6851
  });
6752
6852
  app.get(`${rootPath}/executions/:taskId`, async (request, response) => {
6753
6853
  const { taskId } = request.params;
6754
6854
  // TODO: [🤬] Filter only for user
6755
- const execution = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
6756
- if (execution === undefined) {
6855
+ const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
6856
+ if (executionTask === undefined) {
6757
6857
  response
6758
6858
  .status(404)
6759
6859
  .send(`Execution "${taskId}" not found`);
6760
6860
  return;
6761
6861
  }
6762
- response.send(execution.currentValue);
6862
+ response.send(exportExecutionTask(executionTask, true));
6763
6863
  });
6764
6864
  app.post(`${rootPath}/executions/new`, async (request, response) => {
6765
6865
  try {