@promptbook/remote-server 0.85.0-8 → 0.85.0

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`
@@ -6,7 +6,7 @@ import type { PipelineCollection } from '../PipelineCollection';
6
6
  /**
7
7
  * Options for `createCollectionFromDirectory` function
8
8
  *
9
- * Note: `rootDirname` is not needed because it is the folder in which `.book.md` file is located
9
+ * Note: `rootDirname` is not needed because it is the folder in which `.book` or `.book.md` file is located
10
10
  * This is not same as `path` which is the first argument of `createCollectionFromDirectory` - it can be a subfolder
11
11
  */
12
12
  type CreatePipelineCollectionFromDirectoryOptions = Omit<PrepareAndScrapeOptions, 'rootDirname'> & {
@@ -51,13 +51,13 @@ type CreatePipelineCollectionFromDirectoryOptions = Omit<PrepareAndScrapeOptions
51
51
  *
52
52
  * Note: Works only in Node.js environment because it reads the file system
53
53
  *
54
- * @param path - path to the directory with pipelines
54
+ * @param rootPath - path to the directory with pipelines
55
55
  * @param tools - Execution tools to be used for pipeline preparation if needed - If not provided, `$provideExecutionToolsForNode` will be used
56
56
  * @param options - Options for the collection creation
57
57
  * @returns PipelineCollection
58
58
  * @public exported from `@promptbook/node`
59
59
  */
60
- export declare function createCollectionFromDirectory(path: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
60
+ export declare function createCollectionFromDirectory(rootPath: string_dirname, tools?: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options?: CreatePipelineCollectionFromDirectoryOptions): Promise<PipelineCollection>;
61
61
  export {};
62
62
  /**
63
63
  * TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
@@ -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-8",
3
+ "version": "0.85.0",
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,
@@ -42,12 +42,12 @@
42
42
  "bugs": {
43
43
  "url": "https://github.com/webgptorg/promptbook/issues"
44
44
  },
45
- "homepage": "https://www.npmjs.com/package/@promptbook/core",
45
+ "homepage": "https://ptbk.io/",
46
46
  "main": "./umd/index.umd.js",
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-8"
50
+ "@promptbook/core": "0.85.0"
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-7';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
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
@@ -1488,57 +1488,6 @@
1488
1488
  return true;
1489
1489
  }
1490
1490
 
1491
- /**
1492
- * Checks if an URL is reserved for private networks or localhost.
1493
- *
1494
- * Note: There are two simmilar functions:
1495
- * - `isUrlOnPrivateNetwork` which tests full URL
1496
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
1497
- *
1498
- * @public exported from `@promptbook/utils`
1499
- */
1500
- function isHostnameOnPrivateNetwork(hostname) {
1501
- if (hostname === 'example.com' ||
1502
- hostname === 'localhost' ||
1503
- hostname.endsWith('.localhost') ||
1504
- hostname.endsWith('.local') ||
1505
- hostname.endsWith('.test') ||
1506
- hostname === '127.0.0.1' ||
1507
- hostname === '::1') {
1508
- return true;
1509
- }
1510
- if (hostname.includes(':')) {
1511
- // IPv6
1512
- var ipParts = hostname.split(':');
1513
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
1514
- }
1515
- else {
1516
- // IPv4
1517
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
1518
- return (ipParts[0] === 10 ||
1519
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
1520
- (ipParts[0] === 192 && ipParts[1] === 168));
1521
- }
1522
- }
1523
-
1524
- /**
1525
- * Checks if an IP address or hostname is reserved for private networks or localhost.
1526
- *
1527
- * Note: There are two simmilar functions:
1528
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
1529
- * - `isHostnameOnPrivateNetwork` which tests just hostname
1530
- *
1531
- * @param {string} ipAddress - The IP address to check.
1532
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
1533
- * @public exported from `@promptbook/utils`
1534
- */
1535
- function isUrlOnPrivateNetwork(url) {
1536
- if (typeof url === 'string') {
1537
- url = new URL(url);
1538
- }
1539
- return isHostnameOnPrivateNetwork(url.hostname);
1540
- }
1541
-
1542
1491
  /**
1543
1492
  * Tests if given string is valid URL.
1544
1493
  *
@@ -1581,16 +1530,19 @@
1581
1530
  if (!isValidUrl(url)) {
1582
1531
  return false;
1583
1532
  }
1584
- if (!url.startsWith('https://')) {
1533
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
1585
1534
  return false;
1586
1535
  }
1587
1536
  if (url.includes('#')) {
1588
1537
  // TODO: [🐠]
1589
1538
  return false;
1590
1539
  }
1540
+ /*
1541
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
1591
1542
  if (isUrlOnPrivateNetwork(url)) {
1592
1543
  return false;
1593
1544
  }
1545
+ */
1594
1546
  return true;
1595
1547
  }
1596
1548
  /**
@@ -2006,18 +1958,16 @@
2006
1958
  */
2007
1959
  function createTask(options) {
2008
1960
  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 */));
1961
+ var taskId = "".concat(taskType.toLowerCase().substring(0, 4), "-").concat($randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */));
2010
1962
  var partialResultSubject = new rxjs.BehaviorSubject({});
2011
1963
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2012
1964
  partialResultSubject.next(newOngoingResult);
2013
1965
  });
2014
1966
  finalResultPromise
2015
1967
  .catch(function (error) {
2016
- // console.error('!!!!! Task failed:', error);
2017
1968
  partialResultSubject.error(error);
2018
1969
  })
2019
1970
  .then(function (value) {
2020
- // console.error('!!!!! Task finished:', value);
2021
1971
  if (value) {
2022
1972
  try {
2023
1973
  assertsTaskSuccessful(value);
@@ -2039,9 +1989,7 @@
2039
1989
  return [4 /*yield*/, finalResultPromise];
2040
1990
  case 1:
2041
1991
  finalResult = _b.sent();
2042
- console.error('!!!!! finalResult:', finalResult);
2043
1992
  if (isCrashedOnError) {
2044
- console.error('!!!!! isCrashedOnError:', finalResult);
2045
1993
  assertsTaskSuccessful(finalResult);
2046
1994
  }
2047
1995
  return [2 /*return*/, finalResult];
@@ -6894,6 +6842,57 @@
6894
6842
  .filter(function (part) { return part !== ''; })
6895
6843
  .join('/');
6896
6844
  var startupDate = new Date();
6845
+ function getExecutionToolsFromIdentification(identification) {
6846
+ return __awaiter(this, void 0, void 0, function () {
6847
+ var isAnonymous, llm, llmToolsConfiguration, appId, userId, customOptions, fs, executables, tools;
6848
+ var _a;
6849
+ return __generator(this, function (_b) {
6850
+ switch (_b.label) {
6851
+ case 0:
6852
+ if (identification === null || identification === undefined) {
6853
+ throw new Error("Identification is not provided");
6854
+ }
6855
+ isAnonymous = identification.isAnonymous;
6856
+ if (isAnonymous === true && !isAnonymousModeAllowed) {
6857
+ throw new PipelineExecutionError("Anonymous mode is not allowed"); // <- TODO: [main] !!3 Test
6858
+ }
6859
+ if (isAnonymous === false && !isApplicationModeAllowed) {
6860
+ throw new PipelineExecutionError("Application mode is not allowed"); // <- TODO: [main] !!3 Test
6861
+ }
6862
+ if (!(isAnonymous === true)) return [3 /*break*/, 1];
6863
+ llmToolsConfiguration = identification.llmToolsConfiguration;
6864
+ llm = createLlmToolsFromConfiguration(llmToolsConfiguration, { isVerbose: isVerbose });
6865
+ return [3 /*break*/, 4];
6866
+ case 1:
6867
+ if (!(isAnonymous === false && createLlmExecutionTools !== null)) return [3 /*break*/, 3];
6868
+ appId = identification.appId, userId = identification.userId, customOptions = identification.customOptions;
6869
+ return [4 /*yield*/, createLlmExecutionTools({
6870
+ appId: appId,
6871
+ userId: userId,
6872
+ customOptions: customOptions,
6873
+ })];
6874
+ case 2:
6875
+ llm = _b.sent();
6876
+ return [3 /*break*/, 4];
6877
+ case 3: throw new PipelineExecutionError("You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured");
6878
+ case 4:
6879
+ fs = $provideFilesystemForNode();
6880
+ return [4 /*yield*/, $provideExecutablesForNode()];
6881
+ case 5:
6882
+ executables = _b.sent();
6883
+ _a = {
6884
+ llm: llm,
6885
+ fs: fs
6886
+ };
6887
+ return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables })];
6888
+ case 6:
6889
+ tools = (_a.scrapers = _b.sent(),
6890
+ _a);
6891
+ return [2 /*return*/, tools];
6892
+ }
6893
+ });
6894
+ });
6895
+ }
6897
6896
  var app = express__default["default"]();
6898
6897
  app.use(express__default["default"].json());
6899
6898
  app.use(function (request, response, next) {
@@ -6967,6 +6966,46 @@
6967
6966
  }
6968
6967
  });
6969
6968
  }); });
6969
+ // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
6970
+ app.get("".concat(rootPath, "/books/*"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6971
+ var pipelines, fullUrl, pipelineUrl, pipeline, source, error_1;
6972
+ return __generator(this, function (_a) {
6973
+ switch (_a.label) {
6974
+ case 0:
6975
+ _a.trys.push([0, 3, , 4]);
6976
+ if (collection === null) {
6977
+ response.status(500).send('No collection nor books available');
6978
+ return [2 /*return*/];
6979
+ }
6980
+ return [4 /*yield*/, collection.listPipelines()];
6981
+ case 1:
6982
+ pipelines = _a.sent();
6983
+ fullUrl = request.protocol + '://' + request.get('host') + request.originalUrl;
6984
+ pipelineUrl = pipelines.find(function (pipelineUrl) { return pipelineUrl.endsWith(request.originalUrl); }) || fullUrl;
6985
+ return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
6986
+ case 2:
6987
+ pipeline = _a.sent();
6988
+ source = pipeline.sources[0];
6989
+ if (source === undefined || source.type !== 'BOOK') {
6990
+ throw new Error('Pipeline source is not a book');
6991
+ }
6992
+ response
6993
+ .type('text/markdown')
6994
+ .send(source.content);
6995
+ return [3 /*break*/, 4];
6996
+ case 3:
6997
+ error_1 = _a.sent();
6998
+ if (!(error_1 instanceof Error)) {
6999
+ throw error_1;
7000
+ }
7001
+ response
7002
+ .status(404)
7003
+ .send({ error: serializeError(error_1) });
7004
+ return [3 /*break*/, 4];
7005
+ case 4: return [2 /*return*/];
7006
+ }
7007
+ });
7008
+ }); });
6970
7009
  app.get("".concat(rootPath, "/executions"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6971
7010
  return __generator(this, function (_a) {
6972
7011
  response.send(runningExecutionTasks);
@@ -6979,7 +7018,9 @@
6979
7018
  taskId = request.params.taskId;
6980
7019
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
6981
7020
  if (execution === undefined) {
6982
- response.status(404).send("Execution \"".concat(taskId, "\" not found"));
7021
+ response
7022
+ .status(404)
7023
+ .send("Execution \"".concat(taskId, "\" not found"));
6983
7024
  return [2 /*return*/];
6984
7025
  }
6985
7026
  response.send(execution.currentValue);
@@ -6987,13 +7028,12 @@
6987
7028
  });
6988
7029
  }); });
6989
7030
  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;
7031
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_2;
6992
7032
  return __generator(this, function (_b) {
6993
7033
  switch (_b.label) {
6994
7034
  case 0:
6995
- _b.trys.push([0, 6, , 7]);
6996
- inputParameters = request.body.inputParameters;
7035
+ _b.trys.push([0, 4, , 5]);
7036
+ _a = request.body, inputParameters = _a.inputParameters, identification = _a.identification;
6997
7037
  pipelineUrl = request.body.pipelineUrl || request.body.book;
6998
7038
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
6999
7039
  case 1:
@@ -7002,43 +7042,27 @@
7002
7042
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
7003
7043
  return [2 /*return*/];
7004
7044
  }
7005
- return [4 /*yield*/, createLlmExecutionTools({
7006
- appId: '!!!!',
7007
- userId: '!!!!',
7008
- customOptions: {},
7009
- })];
7045
+ return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7010
7046
  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);
7047
+ tools = _b.sent();
7024
7048
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
7025
7049
  executionTask = pipelineExecutor(inputParameters);
7026
7050
  runningExecutionTasks.push(executionTask);
7027
7051
  return [4 /*yield*/, waitasecond.forTime(10)];
7028
- case 5:
7052
+ case 3:
7029
7053
  _b.sent();
7030
7054
  // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
7031
7055
  // <- TODO: Put this into configuration
7032
7056
  response.send(executionTask);
7033
- return [3 /*break*/, 7];
7034
- case 6:
7035
- error_1 = _b.sent();
7036
- if (!(error_1 instanceof Error)) {
7037
- throw error_1;
7057
+ return [3 /*break*/, 5];
7058
+ case 4:
7059
+ error_2 = _b.sent();
7060
+ if (!(error_2 instanceof Error)) {
7061
+ throw error_2;
7038
7062
  }
7039
- response.status(400).send({ error: serializeError(error_1) });
7040
- return [3 /*break*/, 7];
7041
- case 7: return [2 /*return*/];
7063
+ response.status(400).send({ error: serializeError(error_2) });
7064
+ return [3 /*break*/, 5];
7065
+ case 5: return [2 /*return*/];
7042
7066
  }
7043
7067
  });
7044
7068
  }); });
@@ -7055,55 +7079,9 @@
7055
7079
  if (isVerbose) {
7056
7080
  console.info(colors__default["default"].gray("Client connected"), socket.id);
7057
7081
  }
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
7082
  // -----------
7105
7083
  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;
7084
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_3;
7107
7085
  return __generator(this, function (_c) {
7108
7086
  switch (_c.label) {
7109
7087
  case 0:
@@ -7116,8 +7094,8 @@
7116
7094
  _c.trys.push([1, 13, 14, 15]);
7117
7095
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7118
7096
  case 2:
7119
- executionTools = _c.sent();
7120
- llm = executionTools.llm;
7097
+ tools = _c.sent();
7098
+ llm = tools.llm;
7121
7099
  _a = identification.isAnonymous === false &&
7122
7100
  collection !== null;
7123
7101
  if (!_a) return [3 /*break*/, 4];
@@ -7172,11 +7150,11 @@
7172
7150
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
7173
7151
  return [3 /*break*/, 15];
7174
7152
  case 13:
7175
- error_2 = _c.sent();
7176
- if (!(error_2 instanceof Error)) {
7177
- throw error_2;
7153
+ error_3 = _c.sent();
7154
+ if (!(error_3 instanceof Error)) {
7155
+ throw error_3;
7178
7156
  }
7179
- socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
7157
+ socket.emit('error', serializeError(error_3) /* <- Note: [🤛] */);
7180
7158
  return [3 /*break*/, 15];
7181
7159
  case 14:
7182
7160
  socket.disconnect();
@@ -7188,7 +7166,7 @@
7188
7166
  // -----------
7189
7167
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7190
7168
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7191
- var identification, executionTools, llm, models, error_3;
7169
+ var identification, tools, llm, models, error_4;
7192
7170
  return __generator(this, function (_a) {
7193
7171
  switch (_a.label) {
7194
7172
  case 0:
@@ -7201,19 +7179,19 @@
7201
7179
  _a.trys.push([1, 4, 5, 6]);
7202
7180
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7203
7181
  case 2:
7204
- executionTools = _a.sent();
7205
- llm = executionTools.llm;
7182
+ tools = _a.sent();
7183
+ llm = tools.llm;
7206
7184
  return [4 /*yield*/, llm.listModels()];
7207
7185
  case 3:
7208
7186
  models = _a.sent();
7209
7187
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
7210
7188
  return [3 /*break*/, 6];
7211
7189
  case 4:
7212
- error_3 = _a.sent();
7213
- if (!(error_3 instanceof Error)) {
7214
- throw error_3;
7190
+ error_4 = _a.sent();
7191
+ if (!(error_4 instanceof Error)) {
7192
+ throw error_4;
7215
7193
  }
7216
- socket.emit('error', serializeError(error_3));
7194
+ socket.emit('error', serializeError(error_4));
7217
7195
  return [3 /*break*/, 6];
7218
7196
  case 5:
7219
7197
  socket.disconnect();
@@ -7225,7 +7203,7 @@
7225
7203
  // -----------
7226
7204
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7227
7205
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7228
- var identification, pipeline, executionTools, preparedPipeline, error_4;
7206
+ var identification, pipeline, tools, preparedPipeline, error_5;
7229
7207
  return __generator(this, function (_a) {
7230
7208
  switch (_a.label) {
7231
7209
  case 0:
@@ -7238,18 +7216,18 @@
7238
7216
  _a.trys.push([1, 4, 5, 6]);
7239
7217
  return [4 /*yield*/, getExecutionToolsFromIdentification(identification)];
7240
7218
  case 2:
7241
- executionTools = _a.sent();
7242
- return [4 /*yield*/, preparePipeline(pipeline, executionTools, options)];
7219
+ tools = _a.sent();
7220
+ return [4 /*yield*/, preparePipeline(pipeline, tools, options)];
7243
7221
  case 3:
7244
7222
  preparedPipeline = _a.sent();
7245
7223
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
7246
7224
  return [3 /*break*/, 6];
7247
7225
  case 4:
7248
- error_4 = _a.sent();
7249
- if (!(error_4 instanceof Error)) {
7250
- throw error_4;
7226
+ error_5 = _a.sent();
7227
+ if (!(error_5 instanceof Error)) {
7228
+ throw error_5;
7251
7229
  }
7252
- socket.emit('error', serializeError(error_4));
7230
+ socket.emit('error', serializeError(error_5));
7253
7231
  return [3 /*break*/, 6];
7254
7232
  case 5:
7255
7233
  socket.disconnect();
@@ -7288,8 +7266,7 @@
7288
7266
  };
7289
7267
  }
7290
7268
  /**
7291
- * TODO: !!!!!!! CORS and security
7292
- * TODO: !!!!!!! Allow to pass tokem here
7269
+ * TODO: !! Add CORS and security - probbably via `helmet`
7293
7270
  * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
7294
7271
  * TODO: Split this file into multiple functions - handler for each request
7295
7272
  * TODO: Maybe use `$exportJson`