@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
package/esm/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ import { forTime } from 'waitasecond';
|
|
|
7
7
|
import { spawn } from 'child_process';
|
|
8
8
|
import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
|
|
9
9
|
import { join, basename, dirname } from 'path';
|
|
10
|
-
import {
|
|
10
|
+
import { Subject } from 'rxjs';
|
|
11
11
|
import { randomBytes } from 'crypto';
|
|
12
12
|
import { format } from 'prettier';
|
|
13
13
|
import parserHtml from 'prettier/parser-html';
|
|
@@ -31,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
31
31
|
* @generated
|
|
32
32
|
* @see https://github.com/webgptorg/promptbook
|
|
33
33
|
*/
|
|
34
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
|
|
35
35
|
/**
|
|
36
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
37
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1793,21 +1793,41 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
1793
1793
|
function createTask(options) {
|
|
1794
1794
|
const { taskType, taskProcessCallback } = options;
|
|
1795
1795
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1796
|
-
|
|
1796
|
+
let status = 'RUNNING';
|
|
1797
|
+
const createdAt = new Date();
|
|
1798
|
+
let updatedAt = createdAt;
|
|
1799
|
+
const errors = [];
|
|
1800
|
+
const warnings = [];
|
|
1801
|
+
const currentValue = {};
|
|
1802
|
+
const partialResultSubject = new Subject();
|
|
1803
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1797
1804
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
1805
|
+
Object.assign(currentValue, newOngoingResult);
|
|
1798
1806
|
partialResultSubject.next(newOngoingResult);
|
|
1799
1807
|
});
|
|
1800
1808
|
finalResultPromise
|
|
1801
1809
|
.catch((error) => {
|
|
1810
|
+
errors.push(error);
|
|
1802
1811
|
partialResultSubject.error(error);
|
|
1803
1812
|
})
|
|
1804
|
-
.then((
|
|
1805
|
-
if (
|
|
1813
|
+
.then((executionResult) => {
|
|
1814
|
+
if (executionResult) {
|
|
1806
1815
|
try {
|
|
1807
|
-
|
|
1808
|
-
|
|
1816
|
+
updatedAt = new Date();
|
|
1817
|
+
errors.push(...executionResult.errors);
|
|
1818
|
+
warnings.push(...executionResult.warnings);
|
|
1819
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
1820
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1821
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1822
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1823
|
+
assertsTaskSuccessful(executionResult);
|
|
1824
|
+
status = 'FINISHED';
|
|
1825
|
+
Object.assign(currentValue, executionResult);
|
|
1826
|
+
partialResultSubject.next(executionResult);
|
|
1809
1827
|
}
|
|
1810
1828
|
catch (error) {
|
|
1829
|
+
status = 'ERROR';
|
|
1830
|
+
errors.push(error);
|
|
1811
1831
|
partialResultSubject.error(error);
|
|
1812
1832
|
}
|
|
1813
1833
|
}
|
|
@@ -1824,12 +1844,33 @@ function createTask(options) {
|
|
|
1824
1844
|
return {
|
|
1825
1845
|
taskType,
|
|
1826
1846
|
taskId,
|
|
1847
|
+
get status() {
|
|
1848
|
+
return status;
|
|
1849
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
1850
|
+
},
|
|
1851
|
+
get createdAt() {
|
|
1852
|
+
return createdAt;
|
|
1853
|
+
// <- Note: [1]
|
|
1854
|
+
},
|
|
1855
|
+
get updatedAt() {
|
|
1856
|
+
return updatedAt;
|
|
1857
|
+
// <- Note: [1]
|
|
1858
|
+
},
|
|
1827
1859
|
asPromise,
|
|
1828
1860
|
asObservable() {
|
|
1829
1861
|
return partialResultSubject.asObservable();
|
|
1830
1862
|
},
|
|
1863
|
+
get errors() {
|
|
1864
|
+
return errors;
|
|
1865
|
+
// <- Note: [1]
|
|
1866
|
+
},
|
|
1867
|
+
get warnings() {
|
|
1868
|
+
return warnings;
|
|
1869
|
+
// <- Note: [1]
|
|
1870
|
+
},
|
|
1831
1871
|
get currentValue() {
|
|
1832
|
-
return
|
|
1872
|
+
return currentValue;
|
|
1873
|
+
// <- Note: [1]
|
|
1833
1874
|
},
|
|
1834
1875
|
};
|
|
1835
1876
|
}
|
|
@@ -5053,7 +5094,7 @@ async function executeAttempts(options) {
|
|
|
5053
5094
|
Last result:
|
|
5054
5095
|
${block($ongoingTaskResult.$resultString === null
|
|
5055
5096
|
? 'null'
|
|
5056
|
-
: $ongoingTaskResult.$resultString
|
|
5097
|
+
: spaceTrim($ongoingTaskResult.$resultString)
|
|
5057
5098
|
.split('\n')
|
|
5058
5099
|
.map((line) => `> ${line}`)
|
|
5059
5100
|
.join('\n'))}
|
|
@@ -6740,8 +6781,35 @@ function startRemoteServer(options) {
|
|
|
6740
6781
|
.send({ error: serializeError(error) });
|
|
6741
6782
|
}
|
|
6742
6783
|
});
|
|
6784
|
+
function exportExecutionTask(executionTask, isFull) {
|
|
6785
|
+
// <- TODO: [🧠] This should be maybe method of `ExecutionTask` itself
|
|
6786
|
+
const { taskType, taskId, status, errors, warnings, createdAt, updatedAt, currentValue } = executionTask;
|
|
6787
|
+
if (isFull) {
|
|
6788
|
+
return {
|
|
6789
|
+
nonce: '✨',
|
|
6790
|
+
taskId,
|
|
6791
|
+
taskType,
|
|
6792
|
+
status,
|
|
6793
|
+
errors: errors.map(serializeError),
|
|
6794
|
+
warnings: warnings.map(serializeError),
|
|
6795
|
+
createdAt,
|
|
6796
|
+
updatedAt,
|
|
6797
|
+
currentValue,
|
|
6798
|
+
};
|
|
6799
|
+
}
|
|
6800
|
+
else {
|
|
6801
|
+
return {
|
|
6802
|
+
nonce: '✨',
|
|
6803
|
+
taskId,
|
|
6804
|
+
taskType,
|
|
6805
|
+
status,
|
|
6806
|
+
createdAt,
|
|
6807
|
+
updatedAt,
|
|
6808
|
+
};
|
|
6809
|
+
}
|
|
6810
|
+
}
|
|
6743
6811
|
app.get(`${rootPath}/executions`, async (request, response) => {
|
|
6744
|
-
response.send(runningExecutionTasks);
|
|
6812
|
+
response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
|
|
6745
6813
|
});
|
|
6746
6814
|
app.get(`${rootPath}/executions/last`, async (request, response) => {
|
|
6747
6815
|
// TODO: [🤬] Filter only for user
|
|
@@ -6749,20 +6817,20 @@ function startRemoteServer(options) {
|
|
|
6749
6817
|
response.status(404).send('No execution tasks found');
|
|
6750
6818
|
return;
|
|
6751
6819
|
}
|
|
6752
|
-
const
|
|
6753
|
-
response.send(
|
|
6820
|
+
const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
|
|
6821
|
+
response.send(exportExecutionTask(lastExecutionTask, true));
|
|
6754
6822
|
});
|
|
6755
6823
|
app.get(`${rootPath}/executions/:taskId`, async (request, response) => {
|
|
6756
6824
|
const { taskId } = request.params;
|
|
6757
6825
|
// TODO: [🤬] Filter only for user
|
|
6758
|
-
const
|
|
6759
|
-
if (
|
|
6826
|
+
const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
|
|
6827
|
+
if (executionTask === undefined) {
|
|
6760
6828
|
response
|
|
6761
6829
|
.status(404)
|
|
6762
6830
|
.send(`Execution "${taskId}" not found`);
|
|
6763
6831
|
return;
|
|
6764
6832
|
}
|
|
6765
|
-
response.send(
|
|
6833
|
+
response.send(exportExecutionTask(executionTask, true));
|
|
6766
6834
|
});
|
|
6767
6835
|
app.post(`${rootPath}/executions/new`, async (request, response) => {
|
|
6768
6836
|
try {
|