@promptbook/remote-server 0.85.0-7 → 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.
@@ -8,7 +8,6 @@ import type { Command as Program } from 'commander';
8
8
  */
9
9
  export declare function $initializeAboutCommand(program: Program): void;
10
10
  /**
11
- * TODO: !!! Test this in `deno`
12
11
  * TODO: [🗽] Unite branding and make single place for it
13
12
  * Note: [💞] Ignore a discrepancy between file name and entity name
14
13
  * Note: [🟡] Code in this file should never be published outside of `@promptbook/cli`
@@ -11,8 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
- * TODO: !!!!!!! CORS and security
15
- * TODO: !!!!!!! Allow to pass tokem here
14
+ * TODO: !! Add CORS and security - probbably via `helmet`
16
15
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
17
16
  * TODO: Split this file into multiple functions - handler for each request
18
17
  * TODO: Maybe use `$exportJson`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.85.0-7",
3
+ "version": "0.85.0-9",
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.85.0-7"
50
+ "@promptbook/core": "0.85.0-9"
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
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-6';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.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
@@ -2006,18 +2006,16 @@
2006
2006
  */
2007
2007
  function createTask(options) {
2008
2008
  var taskType = options.taskType, taskProcessCallback = options.taskProcessCallback;
2009
- var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: !!! To global config + Use Base58 to avoid simmilar char conflicts */));
2009
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2010
2010
  var partialResultSubject = new rxjs.BehaviorSubject({});
2011
2011
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2012
2012
  partialResultSubject.next(newOngoingResult);
2013
2013
  });
2014
2014
  finalResultPromise
2015
2015
  .catch(function (error) {
2016
- // console.error('!!!!! Task failed:', error);
2017
2016
  partialResultSubject.error(error);
2018
2017
  })
2019
2018
  .then(function (value) {
2020
- // console.error('!!!!! Task finished:', value);
2021
2019
  if (value) {
2022
2020
  try {
2023
2021
  assertsTaskSuccessful(value);
@@ -2039,9 +2037,7 @@
2039
2037
  return [4 /*yield*/, finalResultPromise];
2040
2038
  case 1:
2041
2039
  finalResult = _b.sent();
2042
- console.error('!!!!! finalResult:', finalResult);
2043
2040
  if (isCrashedOnError) {
2044
- console.error('!!!!! isCrashedOnError:', finalResult);
2045
2041
  assertsTaskSuccessful(finalResult);
2046
2042
  }
2047
2043
  return [2 /*return*/, finalResult];
@@ -6894,6 +6890,57 @@
6894
6890
  .filter(function (part) { return part !== ''; })
6895
6891
  .join('/');
6896
6892
  var startupDate = new Date();
6893
+ function getExecutionToolsFromIdentification(identification) {
6894
+ return __awaiter(this, void 0, void 0, function () {
6895
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
6896
+ var _a;
6897
+ return __generator(this, function (_b) {
6898
+ switch (_b.label) {
6899
+ case 0:
6900
+ if (identification === null || identification === undefined) {
6901
+ throw new Error("Identification is not provided");
6902
+ }
6903
+ isAnonymous = identification.isAnonymous;
6904
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
6905
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
6906
+ }
6907
+ if (isAnonymous === false && !isApplicationModeAllowed) {
6908
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
6909
+ }
6910
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
6911
+ llmToolsConfiguration = identification.llmToolsConfiguration;
6912
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
6913
+ return [3 /*break*/, 4];
6914
+ case 1:
6915
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
6916
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
6917
+ return [4 /*yield*/, createLlmExecutionTools({
6918
+ appId: appId,
6919
+ userId: userId,
6920
+ customOptions: customOptions,
6921
+ })];
6922
+ case 2:
6923
+ llm = _b.sent();
6924
+ return [3 /*break*/, 4];
6925
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
6926
+ case 4:
6927
+ fs = $provideFilesystemForNode();
6928
+ return [4 /*yield*/, $provideExecutablesForNode()];
6929
+ case 5:
6930
+ executables = _b.sent();
6931
+ _a = {
6932
+ llm: llm,
6933
+ fs: fs
6934
+ };
6935
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
6936
+ case 6:
6937
+ tools = (_a.scrapers = _b.sent(),
6938
+ _a);
6939
+ return [2 /*return*/, tools];
6940
+ }
6941
+ });
6942
+ });
6943
+ }
6897
6944
  var app = express__default["default"]();
6898
6945
  app.use(express__default["default"].json());
6899
6946
  app.use(function (request, response, next) {
@@ -6987,13 +7034,12 @@
6987
7034
  });
6988
7035
  }); });
6989
7036
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6990
- var inputParameters, pipelineUrl, pipeline, llm, fs, executables, tools, pipelineExecutor, executionTask, error_1;
6991
- var _a;
7037
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
6992
7038
  return __generator(this, function (_b) {
6993
7039
  switch (_b.label) {
6994
7040
  case 0:
6995
- _b.trys.push([0, 6, , 7]);
6996
- inputParameters = request.body.inputParameters;
7041
+ _b.trys.push([0, 4, , 5]);
7042
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
6997
7043
  pipelineUrl = request.body.pipelineUrl || request.body.book;
6998
7044
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
6999
7045
  case 1:
@@ -7002,43 +7048,27 @@
7002
7048
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
7003
7049
  return [2 /*return*/];
7004
7050
  }
7005
- return [4 /*yield*/, createLlmExecutionTools({
7006
- appId: '!!!!',
7007
- userId: '!!!!',
7008
- customOptions: {},
7009
- })];
7051
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7010
7052
  case 2:
7011
- llm = _b.sent();
7012
- fs = $provideFilesystemForNode();
7013
- return [4 /*yield*/, $provideExecutablesForNode()];
7014
- case 3:
7015
- executables = _b.sent();
7016
- _a = {
7017
- llm: llm,
7018
- fs: fs
7019
- };
7020
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
7021
- case 4:
7022
- tools = (_a.scrapers = _b.sent(),
7023
- _a);
7053
+ tools = _b.sent();
7024
7054
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
7025
7055
  executionTask = pipelineExecutor(inputParameters);
7026
7056
  runningExecutionTasks.push(executionTask);
7027
7057
  return [4 /*yield*/, waitasecond.forTime(10)];
7028
- case 5:
7058
+ case 3:
7029
7059
  _b.sent();
7030
7060
  // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
7031
7061
  // <- TODO: Put this into configuration
7032
7062
  response.send(executionTask);
7033
- return [3 /*break*/, 7];
7034
- case 6:
7063
+ return [3 /*break*/, 5];
7064
+ case 4:
7035
7065
  error_1 = _b.sent();
7036
7066
  if (!(error_1 instanceof Error)) {
7037
7067
  throw error_1;
7038
7068
  }
7039
7069
  response.status(400).send({ error: serializeError(error_1) });
7040
- return [3 /*break*/, 7];
7041
- case 7: return [2 /*return*/];
7070
+ return [3 /*break*/, 5];
7071
+ case 5: return [2 /*return*/];
7042
7072
  }
7043
7073
  });
7044
7074
  }); });
@@ -7055,55 +7085,9 @@
7055
7085
  if (isVerbose) {
7056
7086
  console.info(colors__default["default"].gray("Client connected"), socket.id);
7057
7087
  }
7058
- var getExecutionToolsFromIdentification = function (identification) { return __awaiter(_this, void 0, void 0, function () {
7059
- var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
7060
- var _a;
7061
- return __generator(this, function (_b) {
7062
- switch (_b.label) {
7063
- case 0:
7064
- isAnonymous = identification.isAnonymous;
7065
- if (isAnonymous === true && !isAnonymousModeAllowed) {
7066
- throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
7067
- }
7068
- if (isAnonymous === false && !isApplicationModeAllowed) {
7069
- throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
7070
- }
7071
- if (!(isAnonymous === true)) return [3 /*break*/, 1];
7072
- llmToolsConfiguration = identification.llmToolsConfiguration;
7073
- llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
7074
- return [3 /*break*/, 4];
7075
- case 1:
7076
- if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
7077
- appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
7078
- return [4 /*yield*/, createLlmExecutionTools({
7079
- appId: appId,
7080
- userId: userId,
7081
- customOptions: customOptions,
7082
- })];
7083
- case 2:
7084
- llm = _b.sent();
7085
- return [3 /*break*/, 4];
7086
- case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
7087
- case 4:
7088
- fs = $provideFilesystemForNode();
7089
- return [4 /*yield*/, $provideExecutablesForNode()];
7090
- case 5:
7091
- executables = _b.sent();
7092
- _a = {
7093
- llm: llm,
7094
- fs: fs
7095
- };
7096
- return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
7097
- case 6:
7098
- tools = (_a.scrapers = _b.sent(),
7099
- _a);
7100
- return [2 /*return*/, tools];
7101
- }
7102
- });
7103
- }); };
7104
7088
  // -----------
7105
7089
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7106
- var identification, prompt, executionTools, llm, _a, promptResult, _b, error_2;
7090
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
7107
7091
  return __generator(this, function (_c) {
7108
7092
  switch (_c.label) {
7109
7093
  case 0:
@@ -7116,8 +7100,8 @@
7116
7100
  _c.trys.push([1, 13, 14, 15]);
7117
7101
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7118
7102
  case 2:
7119
- executionTools = _c.sent();
7120
- llm = executionTools.llm;
7103
+ tools = _c.sent();
7104
+ llm = tools.llm;
7121
7105
  _a = identification.isAnonymous === false &&
7122
7106
  collection !== null;
7123
7107
  if (!_a) return [3 /*break*/, 4];
@@ -7188,7 +7172,7 @@
7188
7172
  // -----------
7189
7173
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7190
7174
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7191
- var identification, executionTools, llm, models, error_3;
7175
+ var identification, tools, llm, models, error_3;
7192
7176
  return __generator(this, function (_a) {
7193
7177
  switch (_a.label) {
7194
7178
  case 0:
@@ -7201,8 +7185,8 @@
7201
7185
  _a.trys.push([1, 4, 5, 6]);
7202
7186
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7203
7187
  case 2:
7204
- executionTools = _a.sent();
7205
- llm = executionTools.llm;
7188
+ tools = _a.sent();
7189
+ llm = tools.llm;
7206
7190
  return [4 /*yield*/, llm.listModels()];
7207
7191
  case 3:
7208
7192
  models = _a.sent();
@@ -7225,7 +7209,7 @@
7225
7209
  // -----------
7226
7210
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7227
7211
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7228
- var identification, pipeline, executionTools, preparedPipeline, error_4;
7212
+ var identification, pipeline, tools, preparedPipeline, error_4;
7229
7213
  return __generator(this, function (_a) {
7230
7214
  switch (_a.label) {
7231
7215
  case 0:
@@ -7238,8 +7222,8 @@
7238
7222
  _a.trys.push([1, 4, 5, 6]);
7239
7223
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7240
7224
  case 2:
7241
- executionTools = _a.sent();
7242
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
7225
+ tools = _a.sent();
7226
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
7243
7227
  case 3:
7244
7228
  preparedPipeline = _a.sent();
7245
7229
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
@@ -7288,8 +7272,7 @@
7288
7272
  };
7289
7273
  }
7290
7274
  /**
7291
- * TODO: !!!!!!! CORS and security
7292
- * TODO: !!!!!!! Allow to pass tokem here
7275
+ * TODO: !! Add CORS and security - probbably via `helmet`
7293
7276
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
7294
7277
  * TODO: Split this file into multiple functions - handler for each request
7295
7278
  * TODO: Maybe use `$exportJson`