@promptbook/remote-server 0.85.0-3 → 0.85.0-5
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
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import colors from 'colors';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import http from '
|
|
3
|
+
import http from 'http';
|
|
4
4
|
import { Server } from 'socket.io';
|
|
5
5
|
import spaceTrim$1, { spaceTrim } from 'spacetrim';
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
7
6
|
import { forTime } from 'waitasecond';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { spawn } from 'child_process';
|
|
8
|
+
import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
|
|
9
|
+
import { join, basename, dirname } from 'path';
|
|
10
|
+
import { BehaviorSubject } 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 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
31
31
|
* @generated
|
|
32
32
|
* @see https://github.com/webgptorg/promptbook
|
|
33
33
|
*/
|
|
34
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-
|
|
34
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
|
|
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
|
|
@@ -2009,11 +2009,29 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2009
2009
|
*/
|
|
2010
2010
|
function createTask(options) {
|
|
2011
2011
|
var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
|
|
2012
|
-
var taskId = "".concat(taskType.toLowerCase(), "-").concat($randomToken(
|
|
2012
|
+
var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
|
|
2013
2013
|
var partialResultSubject = new BehaviorSubject({});
|
|
2014
2014
|
var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
|
|
2015
2015
|
partialResultSubject.next(newOngoingResult);
|
|
2016
2016
|
});
|
|
2017
|
+
finalResultPromise
|
|
2018
|
+
.catch(function (error) {
|
|
2019
|
+
// console.error('!!!!! Task failed:', error);
|
|
2020
|
+
partialResultSubject.error(error);
|
|
2021
|
+
})
|
|
2022
|
+
.then(function (value) {
|
|
2023
|
+
// console.error('!!!!! Task finished:', value);
|
|
2024
|
+
if (value) {
|
|
2025
|
+
try {
|
|
2026
|
+
assertsTaskSuccessful(value);
|
|
2027
|
+
partialResultSubject.next(value);
|
|
2028
|
+
}
|
|
2029
|
+
catch (error) {
|
|
2030
|
+
partialResultSubject.error(error);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
partialResultSubject.complete();
|
|
2034
|
+
});
|
|
2017
2035
|
function asPromise(options) {
|
|
2018
2036
|
return __awaiter(this, void 0, void 0, function () {
|
|
2019
2037
|
var _a, isCrashedOnError, finalResult;
|
|
@@ -2024,7 +2042,9 @@ function createTask(options) {
|
|
|
2024
2042
|
return [4 /*yield*/, finalResultPromise];
|
|
2025
2043
|
case 1:
|
|
2026
2044
|
finalResult = _b.sent();
|
|
2045
|
+
console.error('!!!!! finalResult:', finalResult);
|
|
2027
2046
|
if (isCrashedOnError) {
|
|
2047
|
+
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
2028
2048
|
assertsTaskSuccessful(finalResult);
|
|
2029
2049
|
}
|
|
2030
2050
|
return [2 /*return*/, finalResult];
|
|
@@ -2037,9 +2057,10 @@ function createTask(options) {
|
|
|
2037
2057
|
taskId: taskId,
|
|
2038
2058
|
asPromise: asPromise,
|
|
2039
2059
|
asObservable: function () {
|
|
2040
|
-
return
|
|
2041
|
-
|
|
2042
|
-
|
|
2060
|
+
return partialResultSubject.asObservable();
|
|
2061
|
+
},
|
|
2062
|
+
get currentValue() {
|
|
2063
|
+
return partialResultSubject.value;
|
|
2043
2064
|
},
|
|
2044
2065
|
};
|
|
2045
2066
|
}
|
|
@@ -6883,7 +6904,7 @@ function startRemoteServer(options) {
|
|
|
6883
6904
|
next();
|
|
6884
6905
|
});
|
|
6885
6906
|
var runningExecutionTasks = [];
|
|
6886
|
-
// TODO:
|
|
6907
|
+
// TODO: [🧠] Do here some garbage collection of finished tasks
|
|
6887
6908
|
app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
6888
6909
|
var _a, _b;
|
|
6889
6910
|
var _this = this;
|
|
@@ -6932,20 +6953,19 @@ function startRemoteServer(options) {
|
|
|
6932
6953
|
});
|
|
6933
6954
|
}); });
|
|
6934
6955
|
app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
6935
|
-
var
|
|
6936
|
-
return __generator(this, function (
|
|
6937
|
-
switch (
|
|
6956
|
+
var pipelines;
|
|
6957
|
+
return __generator(this, function (_a) {
|
|
6958
|
+
switch (_a.label) {
|
|
6938
6959
|
case 0:
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
case
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
_b.apply(_a, [_c]);
|
|
6960
|
+
if (collection === null) {
|
|
6961
|
+
response.status(500).send('No collection available');
|
|
6962
|
+
return [2 /*return*/];
|
|
6963
|
+
}
|
|
6964
|
+
return [4 /*yield*/, collection.listPipelines()];
|
|
6965
|
+
case 1:
|
|
6966
|
+
pipelines = _a.sent();
|
|
6967
|
+
// <- TODO: [🧠][👩🏾🤝🧑🏿] List `inputParameters` required for the execution
|
|
6968
|
+
response.send(pipelines);
|
|
6949
6969
|
return [2 /*return*/];
|
|
6950
6970
|
}
|
|
6951
6971
|
});
|
|
@@ -6959,22 +6979,23 @@ function startRemoteServer(options) {
|
|
|
6959
6979
|
app.get("".concat(rootPath, "/executions/:taskId"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
6960
6980
|
var taskId, execution;
|
|
6961
6981
|
return __generator(this, function (_a) {
|
|
6962
|
-
taskId = request.
|
|
6982
|
+
taskId = request.params.taskId;
|
|
6963
6983
|
execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
|
|
6964
6984
|
if (execution === undefined) {
|
|
6965
6985
|
response.status(404).send("Execution \"".concat(taskId, "\" not found"));
|
|
6966
6986
|
return [2 /*return*/];
|
|
6967
6987
|
}
|
|
6968
|
-
response.send(execution);
|
|
6988
|
+
response.send(execution.currentValue);
|
|
6969
6989
|
return [2 /*return*/];
|
|
6970
6990
|
});
|
|
6971
6991
|
}); });
|
|
6972
6992
|
app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
6973
|
-
var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask;
|
|
6993
|
+
var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask, error_1;
|
|
6974
6994
|
var _a;
|
|
6975
6995
|
return __generator(this, function (_b) {
|
|
6976
6996
|
switch (_b.label) {
|
|
6977
6997
|
case 0:
|
|
6998
|
+
_b.trys.push([0, 6, , 7]);
|
|
6978
6999
|
inputParameters = request.body.inputParameters;
|
|
6979
7000
|
pipelineUrl = request.body.pipelineUrl || request.body.book;
|
|
6980
7001
|
return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
|
|
@@ -7006,8 +7027,21 @@ function startRemoteServer(options) {
|
|
|
7006
7027
|
pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
|
|
7007
7028
|
executionTask = pipelineExecutor(inputParameters);
|
|
7008
7029
|
runningExecutionTasks.push(executionTask);
|
|
7030
|
+
return [4 /*yield*/, forTime(10)];
|
|
7031
|
+
case 5:
|
|
7032
|
+
_b.sent();
|
|
7033
|
+
// <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
|
|
7034
|
+
// <- TODO: Put this into configuration
|
|
7009
7035
|
response.send(executionTask);
|
|
7010
|
-
return [
|
|
7036
|
+
return [3 /*break*/, 7];
|
|
7037
|
+
case 6:
|
|
7038
|
+
error_1 = _b.sent();
|
|
7039
|
+
if (!(error_1 instanceof Error)) {
|
|
7040
|
+
throw error_1;
|
|
7041
|
+
}
|
|
7042
|
+
response.status(400).send({ error: serializeError(error_1) });
|
|
7043
|
+
return [3 /*break*/, 7];
|
|
7044
|
+
case 7: return [2 /*return*/];
|
|
7011
7045
|
}
|
|
7012
7046
|
});
|
|
7013
7047
|
}); });
|
|
@@ -7072,7 +7106,7 @@ function startRemoteServer(options) {
|
|
|
7072
7106
|
}); };
|
|
7073
7107
|
// -----------
|
|
7074
7108
|
socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7075
|
-
var identification, prompt, executionTools, llm, _a, promptResult, _b,
|
|
7109
|
+
var identification, prompt, executionTools, llm, _a, promptResult, _b, error_2;
|
|
7076
7110
|
return __generator(this, function (_c) {
|
|
7077
7111
|
switch (_c.label) {
|
|
7078
7112
|
case 0:
|
|
@@ -7141,11 +7175,11 @@ function startRemoteServer(options) {
|
|
|
7141
7175
|
socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
|
|
7142
7176
|
return [3 /*break*/, 15];
|
|
7143
7177
|
case 13:
|
|
7144
|
-
|
|
7145
|
-
if (!(
|
|
7146
|
-
throw
|
|
7178
|
+
error_2 = _c.sent();
|
|
7179
|
+
if (!(error_2 instanceof Error)) {
|
|
7180
|
+
throw error_2;
|
|
7147
7181
|
}
|
|
7148
|
-
socket.emit('error', serializeError(
|
|
7182
|
+
socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
|
|
7149
7183
|
return [3 /*break*/, 15];
|
|
7150
7184
|
case 14:
|
|
7151
7185
|
socket.disconnect();
|
|
@@ -7157,7 +7191,7 @@ function startRemoteServer(options) {
|
|
|
7157
7191
|
// -----------
|
|
7158
7192
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
7159
7193
|
socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7160
|
-
var identification, executionTools, llm, models,
|
|
7194
|
+
var identification, executionTools, llm, models, error_3;
|
|
7161
7195
|
return __generator(this, function (_a) {
|
|
7162
7196
|
switch (_a.label) {
|
|
7163
7197
|
case 0:
|
|
@@ -7178,11 +7212,11 @@ function startRemoteServer(options) {
|
|
|
7178
7212
|
socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
|
|
7179
7213
|
return [3 /*break*/, 6];
|
|
7180
7214
|
case 4:
|
|
7181
|
-
|
|
7182
|
-
if (!(
|
|
7183
|
-
throw
|
|
7215
|
+
error_3 = _a.sent();
|
|
7216
|
+
if (!(error_3 instanceof Error)) {
|
|
7217
|
+
throw error_3;
|
|
7184
7218
|
}
|
|
7185
|
-
socket.emit('error', serializeError(
|
|
7219
|
+
socket.emit('error', serializeError(error_3));
|
|
7186
7220
|
return [3 /*break*/, 6];
|
|
7187
7221
|
case 5:
|
|
7188
7222
|
socket.disconnect();
|
|
@@ -7194,7 +7228,7 @@ function startRemoteServer(options) {
|
|
|
7194
7228
|
// -----------
|
|
7195
7229
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
7196
7230
|
socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7197
|
-
var identification, pipeline, executionTools, preparedPipeline,
|
|
7231
|
+
var identification, pipeline, executionTools, preparedPipeline, error_4;
|
|
7198
7232
|
return __generator(this, function (_a) {
|
|
7199
7233
|
switch (_a.label) {
|
|
7200
7234
|
case 0:
|
|
@@ -7214,11 +7248,11 @@ function startRemoteServer(options) {
|
|
|
7214
7248
|
socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
|
|
7215
7249
|
return [3 /*break*/, 6];
|
|
7216
7250
|
case 4:
|
|
7217
|
-
|
|
7218
|
-
if (!(
|
|
7219
|
-
throw
|
|
7251
|
+
error_4 = _a.sent();
|
|
7252
|
+
if (!(error_4 instanceof Error)) {
|
|
7253
|
+
throw error_4;
|
|
7220
7254
|
}
|
|
7221
|
-
socket.emit('error', serializeError(
|
|
7255
|
+
socket.emit('error', serializeError(error_4));
|
|
7222
7256
|
return [3 /*break*/, 6];
|
|
7223
7257
|
case 5:
|
|
7224
7258
|
socket.disconnect();
|