@promptbook/remote-server 0.88.0-1 → 0.88.0-8
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/esm/index.es.js +83 -15
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/types.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/package.json +2 -2
- package/umd/index.umd.js +82 -14
- 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 };
|
|
@@ -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 {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-server",
|
|
3
|
-
"version": "0.88.0-
|
|
3
|
+
"version": "0.88.0-8",
|
|
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-
|
|
50
|
+
"@promptbook/core": "0.88.0-8"
|
|
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-
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
|
|
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
|
|
@@ -1790,21 +1790,41 @@
|
|
|
1790
1790
|
function createTask(options) {
|
|
1791
1791
|
const { taskType, taskProcessCallback } = options;
|
|
1792
1792
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1793
|
-
|
|
1793
|
+
let status = 'RUNNING';
|
|
1794
|
+
const createdAt = new Date();
|
|
1795
|
+
let updatedAt = createdAt;
|
|
1796
|
+
const errors = [];
|
|
1797
|
+
const warnings = [];
|
|
1798
|
+
const currentValue = {};
|
|
1799
|
+
const partialResultSubject = new rxjs.Subject();
|
|
1800
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1794
1801
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
1802
|
+
Object.assign(currentValue, newOngoingResult);
|
|
1795
1803
|
partialResultSubject.next(newOngoingResult);
|
|
1796
1804
|
});
|
|
1797
1805
|
finalResultPromise
|
|
1798
1806
|
.catch((error) => {
|
|
1807
|
+
errors.push(error);
|
|
1799
1808
|
partialResultSubject.error(error);
|
|
1800
1809
|
})
|
|
1801
|
-
.then((
|
|
1802
|
-
if (
|
|
1810
|
+
.then((executionResult) => {
|
|
1811
|
+
if (executionResult) {
|
|
1803
1812
|
try {
|
|
1804
|
-
|
|
1805
|
-
|
|
1813
|
+
updatedAt = new Date();
|
|
1814
|
+
errors.push(...executionResult.errors);
|
|
1815
|
+
warnings.push(...executionResult.warnings);
|
|
1816
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
1817
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1818
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1819
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1820
|
+
assertsTaskSuccessful(executionResult);
|
|
1821
|
+
status = 'FINISHED';
|
|
1822
|
+
Object.assign(currentValue, executionResult);
|
|
1823
|
+
partialResultSubject.next(executionResult);
|
|
1806
1824
|
}
|
|
1807
1825
|
catch (error) {
|
|
1826
|
+
status = 'ERROR';
|
|
1827
|
+
errors.push(error);
|
|
1808
1828
|
partialResultSubject.error(error);
|
|
1809
1829
|
}
|
|
1810
1830
|
}
|
|
@@ -1821,12 +1841,33 @@
|
|
|
1821
1841
|
return {
|
|
1822
1842
|
taskType,
|
|
1823
1843
|
taskId,
|
|
1844
|
+
get status() {
|
|
1845
|
+
return status;
|
|
1846
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
1847
|
+
},
|
|
1848
|
+
get createdAt() {
|
|
1849
|
+
return createdAt;
|
|
1850
|
+
// <- Note: [1]
|
|
1851
|
+
},
|
|
1852
|
+
get updatedAt() {
|
|
1853
|
+
return updatedAt;
|
|
1854
|
+
// <- Note: [1]
|
|
1855
|
+
},
|
|
1824
1856
|
asPromise,
|
|
1825
1857
|
asObservable() {
|
|
1826
1858
|
return partialResultSubject.asObservable();
|
|
1827
1859
|
},
|
|
1860
|
+
get errors() {
|
|
1861
|
+
return errors;
|
|
1862
|
+
// <- Note: [1]
|
|
1863
|
+
},
|
|
1864
|
+
get warnings() {
|
|
1865
|
+
return warnings;
|
|
1866
|
+
// <- Note: [1]
|
|
1867
|
+
},
|
|
1828
1868
|
get currentValue() {
|
|
1829
|
-
return
|
|
1869
|
+
return currentValue;
|
|
1870
|
+
// <- Note: [1]
|
|
1830
1871
|
},
|
|
1831
1872
|
};
|
|
1832
1873
|
}
|
|
@@ -5050,7 +5091,7 @@
|
|
|
5050
5091
|
Last result:
|
|
5051
5092
|
${block($ongoingTaskResult.$resultString === null
|
|
5052
5093
|
? 'null'
|
|
5053
|
-
: $ongoingTaskResult.$resultString
|
|
5094
|
+
: spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
|
|
5054
5095
|
.split('\n')
|
|
5055
5096
|
.map((line) => `> ${line}`)
|
|
5056
5097
|
.join('\n'))}
|
|
@@ -6737,8 +6778,35 @@
|
|
|
6737
6778
|
.send({ error: serializeError(error) });
|
|
6738
6779
|
}
|
|
6739
6780
|
});
|
|
6781
|
+
function exportExecutionTask(executionTask, isFull) {
|
|
6782
|
+
// <- TODO: [🧠] This should be maybe method of `ExecutionTask` itself
|
|
6783
|
+
const { taskType, taskId, status, errors, warnings, createdAt, updatedAt, currentValue } = executionTask;
|
|
6784
|
+
if (isFull) {
|
|
6785
|
+
return {
|
|
6786
|
+
nonce: '✨',
|
|
6787
|
+
taskId,
|
|
6788
|
+
taskType,
|
|
6789
|
+
status,
|
|
6790
|
+
errors: errors.map(serializeError),
|
|
6791
|
+
warnings: warnings.map(serializeError),
|
|
6792
|
+
createdAt,
|
|
6793
|
+
updatedAt,
|
|
6794
|
+
currentValue,
|
|
6795
|
+
};
|
|
6796
|
+
}
|
|
6797
|
+
else {
|
|
6798
|
+
return {
|
|
6799
|
+
nonce: '✨',
|
|
6800
|
+
taskId,
|
|
6801
|
+
taskType,
|
|
6802
|
+
status,
|
|
6803
|
+
createdAt,
|
|
6804
|
+
updatedAt,
|
|
6805
|
+
};
|
|
6806
|
+
}
|
|
6807
|
+
}
|
|
6740
6808
|
app.get(`${rootPath}/executions`, async (request, response) => {
|
|
6741
|
-
response.send(runningExecutionTasks);
|
|
6809
|
+
response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
|
|
6742
6810
|
});
|
|
6743
6811
|
app.get(`${rootPath}/executions/last`, async (request, response) => {
|
|
6744
6812
|
// TODO: [🤬] Filter only for user
|
|
@@ -6746,20 +6814,20 @@
|
|
|
6746
6814
|
response.status(404).send('No execution tasks found');
|
|
6747
6815
|
return;
|
|
6748
6816
|
}
|
|
6749
|
-
const
|
|
6750
|
-
response.send(
|
|
6817
|
+
const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
|
|
6818
|
+
response.send(exportExecutionTask(lastExecutionTask, true));
|
|
6751
6819
|
});
|
|
6752
6820
|
app.get(`${rootPath}/executions/:taskId`, async (request, response) => {
|
|
6753
6821
|
const { taskId } = request.params;
|
|
6754
6822
|
// TODO: [🤬] Filter only for user
|
|
6755
|
-
const
|
|
6756
|
-
if (
|
|
6823
|
+
const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
|
|
6824
|
+
if (executionTask === undefined) {
|
|
6757
6825
|
response
|
|
6758
6826
|
.status(404)
|
|
6759
6827
|
.send(`Execution "${taskId}" not found`);
|
|
6760
6828
|
return;
|
|
6761
6829
|
}
|
|
6762
|
-
response.send(
|
|
6830
|
+
response.send(exportExecutionTask(executionTask, true));
|
|
6763
6831
|
});
|
|
6764
6832
|
app.post(`${rootPath}/executions/new`, async (request, response) => {
|
|
6765
6833
|
try {
|