@promptbook/remote-server 0.85.0-8 → 0.85.0-9
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
|
@@ -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-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
|
|
@@ -2009,18 +2009,16 @@ 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().substring(0, 4), "-").concat($randomToken(8 /* <- TODO:
|
|
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
2017
|
finalResultPromise
|
|
2018
2018
|
.catch(function (error) {
|
|
2019
|
-
// console.error('!!!!! Task failed:', error);
|
|
2020
2019
|
partialResultSubject.error(error);
|
|
2021
2020
|
})
|
|
2022
2021
|
.then(function (value) {
|
|
2023
|
-
// console.error('!!!!! Task finished:', value);
|
|
2024
2022
|
if (value) {
|
|
2025
2023
|
try {
|
|
2026
2024
|
assertsTaskSuccessful(value);
|
|
@@ -2042,9 +2040,7 @@ function createTask(options) {
|
|
|
2042
2040
|
return [4 /*yield*/, finalResultPromise];
|
|
2043
2041
|
case 1:
|
|
2044
2042
|
finalResult = _b.sent();
|
|
2045
|
-
console.error('!!!!! finalResult:', finalResult);
|
|
2046
2043
|
if (isCrashedOnError) {
|
|
2047
|
-
console.error('!!!!! isCrashedOnError:', finalResult);
|
|
2048
2044
|
assertsTaskSuccessful(finalResult);
|
|
2049
2045
|
}
|
|
2050
2046
|
return [2 /*return*/, finalResult];
|
|
@@ -6897,6 +6893,57 @@ function startRemoteServer(options) {
|
|
|
6897
6893
|
.filter(function (part) { return part !== ''; })
|
|
6898
6894
|
.join('/');
|
|
6899
6895
|
var startupDate = new Date();
|
|
6896
|
+
function getExecutionToolsFromIdentification(identification) {
|
|
6897
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
6898
|
+
var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
|
|
6899
|
+
var _a;
|
|
6900
|
+
return __generator(this, function (_b) {
|
|
6901
|
+
switch (_b.label) {
|
|
6902
|
+
case 0:
|
|
6903
|
+
if (identification === null || identification === undefined) {
|
|
6904
|
+
throw new Error("Identification is not provided");
|
|
6905
|
+
}
|
|
6906
|
+
isAnonymous = identification.isAnonymous;
|
|
6907
|
+
if (isAnonymous === true && !isAnonymousModeAllowed) {
|
|
6908
|
+
throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
6909
|
+
}
|
|
6910
|
+
if (isAnonymous === false && !isApplicationModeAllowed) {
|
|
6911
|
+
throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
6912
|
+
}
|
|
6913
|
+
if (!(isAnonymous === true)) return [3 /*break*/, 1];
|
|
6914
|
+
llmToolsConfiguration = identification.llmToolsConfiguration;
|
|
6915
|
+
llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
|
|
6916
|
+
return [3 /*break*/, 4];
|
|
6917
|
+
case 1:
|
|
6918
|
+
if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
|
|
6919
|
+
appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
|
|
6920
|
+
return [4 /*yield*/, createLlmExecutionTools({
|
|
6921
|
+
appId: appId,
|
|
6922
|
+
userId: userId,
|
|
6923
|
+
customOptions: customOptions,
|
|
6924
|
+
})];
|
|
6925
|
+
case 2:
|
|
6926
|
+
llm = _b.sent();
|
|
6927
|
+
return [3 /*break*/, 4];
|
|
6928
|
+
case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
|
|
6929
|
+
case 4:
|
|
6930
|
+
fs = $provideFilesystemForNode();
|
|
6931
|
+
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
6932
|
+
case 5:
|
|
6933
|
+
executables = _b.sent();
|
|
6934
|
+
_a = {
|
|
6935
|
+
llm: llm,
|
|
6936
|
+
fs: fs
|
|
6937
|
+
};
|
|
6938
|
+
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
6939
|
+
case 6:
|
|
6940
|
+
tools = (_a.scrapers = _b.sent(),
|
|
6941
|
+
_a);
|
|
6942
|
+
return [2 /*return*/, tools];
|
|
6943
|
+
}
|
|
6944
|
+
});
|
|
6945
|
+
});
|
|
6946
|
+
}
|
|
6900
6947
|
var app = express();
|
|
6901
6948
|
app.use(express.json());
|
|
6902
6949
|
app.use(function (request, response, next) {
|
|
@@ -6990,13 +7037,12 @@ function startRemoteServer(options) {
|
|
|
6990
7037
|
});
|
|
6991
7038
|
}); });
|
|
6992
7039
|
app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
|
|
6993
|
-
var
|
|
6994
|
-
var _a;
|
|
7040
|
+
var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
|
|
6995
7041
|
return __generator(this, function (_b) {
|
|
6996
7042
|
switch (_b.label) {
|
|
6997
7043
|
case 0:
|
|
6998
|
-
_b.trys.push([0,
|
|
6999
|
-
|
|
7044
|
+
_b.trys.push([0, 4, , 5]);
|
|
7045
|
+
_a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
|
|
7000
7046
|
pipelineUrl = request.body.pipelineUrl || request.body.book;
|
|
7001
7047
|
return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
|
|
7002
7048
|
case 1:
|
|
@@ -7005,43 +7051,27 @@ function startRemoteServer(options) {
|
|
|
7005
7051
|
response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
|
|
7006
7052
|
return [2 /*return*/];
|
|
7007
7053
|
}
|
|
7008
|
-
return [4 /*yield*/,
|
|
7009
|
-
appId: '!!!!',
|
|
7010
|
-
userId: '!!!!',
|
|
7011
|
-
customOptions: {},
|
|
7012
|
-
})];
|
|
7054
|
+
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
7013
7055
|
case 2:
|
|
7014
|
-
|
|
7015
|
-
fs = $provideFilesystemForNode();
|
|
7016
|
-
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
7017
|
-
case 3:
|
|
7018
|
-
executables = _b.sent();
|
|
7019
|
-
_a = {
|
|
7020
|
-
llm: llm,
|
|
7021
|
-
fs: fs
|
|
7022
|
-
};
|
|
7023
|
-
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
7024
|
-
case 4:
|
|
7025
|
-
tools = (_a.scrapers = _b.sent(),
|
|
7026
|
-
_a);
|
|
7056
|
+
tools = _b.sent();
|
|
7027
7057
|
pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
|
|
7028
7058
|
executionTask = pipelineExecutor(inputParameters);
|
|
7029
7059
|
runningExecutionTasks.push(executionTask);
|
|
7030
7060
|
return [4 /*yield*/, forTime(10)];
|
|
7031
|
-
case
|
|
7061
|
+
case 3:
|
|
7032
7062
|
_b.sent();
|
|
7033
7063
|
// <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
|
|
7034
7064
|
// <- TODO: Put this into configuration
|
|
7035
7065
|
response.send(executionTask);
|
|
7036
|
-
return [3 /*break*/,
|
|
7037
|
-
case
|
|
7066
|
+
return [3 /*break*/, 5];
|
|
7067
|
+
case 4:
|
|
7038
7068
|
error_1 = _b.sent();
|
|
7039
7069
|
if (!(error_1 instanceof Error)) {
|
|
7040
7070
|
throw error_1;
|
|
7041
7071
|
}
|
|
7042
7072
|
response.status(400).send({ error: serializeError(error_1) });
|
|
7043
|
-
return [3 /*break*/,
|
|
7044
|
-
case
|
|
7073
|
+
return [3 /*break*/, 5];
|
|
7074
|
+
case 5: return [2 /*return*/];
|
|
7045
7075
|
}
|
|
7046
7076
|
});
|
|
7047
7077
|
}); });
|
|
@@ -7058,55 +7088,9 @@ function startRemoteServer(options) {
|
|
|
7058
7088
|
if (isVerbose) {
|
|
7059
7089
|
console.info(colors.gray("Client connected"), socket.id);
|
|
7060
7090
|
}
|
|
7061
|
-
var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
|
|
7062
|
-
var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
|
|
7063
|
-
var _a;
|
|
7064
|
-
return __generator(this, function (_b) {
|
|
7065
|
-
switch (_b.label) {
|
|
7066
|
-
case 0:
|
|
7067
|
-
isAnonymous = identification.isAnonymous;
|
|
7068
|
-
if (isAnonymous === true && !isAnonymousModeAllowed) {
|
|
7069
|
-
throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
7070
|
-
}
|
|
7071
|
-
if (isAnonymous === false && !isApplicationModeAllowed) {
|
|
7072
|
-
throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
|
|
7073
|
-
}
|
|
7074
|
-
if (!(isAnonymous === true)) return [3 /*break*/, 1];
|
|
7075
|
-
llmToolsConfiguration = identification.llmToolsConfiguration;
|
|
7076
|
-
llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
|
|
7077
|
-
return [3 /*break*/, 4];
|
|
7078
|
-
case 1:
|
|
7079
|
-
if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
|
|
7080
|
-
appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
|
|
7081
|
-
return [4 /*yield*/, createLlmExecutionTools({
|
|
7082
|
-
appId: appId,
|
|
7083
|
-
userId: userId,
|
|
7084
|
-
customOptions: customOptions,
|
|
7085
|
-
})];
|
|
7086
|
-
case 2:
|
|
7087
|
-
llm = _b.sent();
|
|
7088
|
-
return [3 /*break*/, 4];
|
|
7089
|
-
case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
|
|
7090
|
-
case 4:
|
|
7091
|
-
fs = $provideFilesystemForNode();
|
|
7092
|
-
return [4 /*yield*/, $provideExecutablesForNode()];
|
|
7093
|
-
case 5:
|
|
7094
|
-
executables = _b.sent();
|
|
7095
|
-
_a = {
|
|
7096
|
-
llm: llm,
|
|
7097
|
-
fs: fs
|
|
7098
|
-
};
|
|
7099
|
-
return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
|
|
7100
|
-
case 6:
|
|
7101
|
-
tools = (_a.scrapers = _b.sent(),
|
|
7102
|
-
_a);
|
|
7103
|
-
return [2 /*return*/, tools];
|
|
7104
|
-
}
|
|
7105
|
-
});
|
|
7106
|
-
}); };
|
|
7107
7091
|
// -----------
|
|
7108
7092
|
socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7109
|
-
var identification, prompt,
|
|
7093
|
+
var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
|
|
7110
7094
|
return __generator(this, function (_c) {
|
|
7111
7095
|
switch (_c.label) {
|
|
7112
7096
|
case 0:
|
|
@@ -7119,8 +7103,8 @@ function startRemoteServer(options) {
|
|
|
7119
7103
|
_c.trys.push([1, 13, 14, 15]);
|
|
7120
7104
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
7121
7105
|
case 2:
|
|
7122
|
-
|
|
7123
|
-
llm =
|
|
7106
|
+
tools = _c.sent();
|
|
7107
|
+
llm = tools.llm;
|
|
7124
7108
|
_a = identification.isAnonymous === false &&
|
|
7125
7109
|
collection !== null;
|
|
7126
7110
|
if (!_a) return [3 /*break*/, 4];
|
|
@@ -7191,7 +7175,7 @@ function startRemoteServer(options) {
|
|
|
7191
7175
|
// -----------
|
|
7192
7176
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
7193
7177
|
socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7194
|
-
var identification,
|
|
7178
|
+
var identification, tools, llm, models, error_3;
|
|
7195
7179
|
return __generator(this, function (_a) {
|
|
7196
7180
|
switch (_a.label) {
|
|
7197
7181
|
case 0:
|
|
@@ -7204,8 +7188,8 @@ function startRemoteServer(options) {
|
|
|
7204
7188
|
_a.trys.push([1, 4, 5, 6]);
|
|
7205
7189
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
7206
7190
|
case 2:
|
|
7207
|
-
|
|
7208
|
-
llm =
|
|
7191
|
+
tools = _a.sent();
|
|
7192
|
+
llm = tools.llm;
|
|
7209
7193
|
return [4 /*yield*/, llm.listModels()];
|
|
7210
7194
|
case 3:
|
|
7211
7195
|
models = _a.sent();
|
|
@@ -7228,7 +7212,7 @@ function startRemoteServer(options) {
|
|
|
7228
7212
|
// -----------
|
|
7229
7213
|
// TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
|
|
7230
7214
|
socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
7231
|
-
var identification, pipeline,
|
|
7215
|
+
var identification, pipeline, tools, preparedPipeline, error_4;
|
|
7232
7216
|
return __generator(this, function (_a) {
|
|
7233
7217
|
switch (_a.label) {
|
|
7234
7218
|
case 0:
|
|
@@ -7241,8 +7225,8 @@ function startRemoteServer(options) {
|
|
|
7241
7225
|
_a.trys.push([1, 4, 5, 6]);
|
|
7242
7226
|
return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
|
|
7243
7227
|
case 2:
|
|
7244
|
-
|
|
7245
|
-
return [4 /*yield*/, preparePipeline(pipeline,
|
|
7228
|
+
tools = _a.sent();
|
|
7229
|
+
return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
|
|
7246
7230
|
case 3:
|
|
7247
7231
|
preparedPipeline = _a.sent();
|
|
7248
7232
|
socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
|
|
@@ -7291,8 +7275,7 @@ function startRemoteServer(options) {
|
|
|
7291
7275
|
};
|
|
7292
7276
|
}
|
|
7293
7277
|
/**
|
|
7294
|
-
* TODO:
|
|
7295
|
-
* TODO: !!!!!!! Allow to pass tokem here
|
|
7278
|
+
* TODO: !! Add CORS and security - probbably via `helmet`
|
|
7296
7279
|
* TODO: [👩🏾🤝🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
|
|
7297
7280
|
* TODO: Split this file into multiple functions - handler for each request
|
|
7298
7281
|
* TODO: Maybe use `$exportJson`
|