@promptbook/remote-server 0.85.0-9 → 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.
package/README.md CHANGED
@@ -24,10 +24,6 @@
24
24
 
25
25
 
26
26
 
27
- <blockquote style="color: #ff8811">
28
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
29
- </blockquote>
30
-
31
27
  ## 📦 Package `@promptbook/remote-server`
32
28
 
33
29
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
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-8';
34
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-16';
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
@@ -1491,57 +1491,6 @@ function isValidPromptbookVersion(version) {
1491
1491
  return true;
1492
1492
  }
1493
1493
 
1494
- /**
1495
- * Checks if an URL is reserved for private networks or localhost.
1496
- *
1497
- * Note: There are two simmilar functions:
1498
- * - `isUrlOnPrivateNetwork` which tests full URL
1499
- * - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
1500
- *
1501
- * @public exported from `@promptbook/utils`
1502
- */
1503
- function isHostnameOnPrivateNetwork(hostname) {
1504
- if (hostname === 'example.com' ||
1505
- hostname === 'localhost' ||
1506
- hostname.endsWith('.localhost') ||
1507
- hostname.endsWith('.local') ||
1508
- hostname.endsWith('.test') ||
1509
- hostname === '127.0.0.1' ||
1510
- hostname === '::1') {
1511
- return true;
1512
- }
1513
- if (hostname.includes(':')) {
1514
- // IPv6
1515
- var ipParts = hostname.split(':');
1516
- return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
1517
- }
1518
- else {
1519
- // IPv4
1520
- var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
1521
- return (ipParts[0] === 10 ||
1522
- (ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
1523
- (ipParts[0] === 192 && ipParts[1] === 168));
1524
- }
1525
- }
1526
-
1527
- /**
1528
- * Checks if an IP address or hostname is reserved for private networks or localhost.
1529
- *
1530
- * Note: There are two simmilar functions:
1531
- * - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
1532
- * - `isHostnameOnPrivateNetwork` which tests just hostname
1533
- *
1534
- * @param {string} ipAddress - The IP address to check.
1535
- * @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
1536
- * @public exported from `@promptbook/utils`
1537
- */
1538
- function isUrlOnPrivateNetwork(url) {
1539
- if (typeof url === 'string') {
1540
- url = new URL(url);
1541
- }
1542
- return isHostnameOnPrivateNetwork(url.hostname);
1543
- }
1544
-
1545
1494
  /**
1546
1495
  * Tests if given string is valid URL.
1547
1496
  *
@@ -1584,16 +1533,19 @@ function isValidPipelineUrl(url) {
1584
1533
  if (!isValidUrl(url)) {
1585
1534
  return false;
1586
1535
  }
1587
- if (!url.startsWith('https://')) {
1536
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
1588
1537
  return false;
1589
1538
  }
1590
1539
  if (url.includes('#')) {
1591
1540
  // TODO: [🐠]
1592
1541
  return false;
1593
1542
  }
1543
+ /*
1544
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
1594
1545
  if (isUrlOnPrivateNetwork(url)) {
1595
1546
  return false;
1596
1547
  }
1548
+ */
1597
1549
  return true;
1598
1550
  }
1599
1551
  /**
@@ -7017,6 +6969,46 @@ function startRemoteServer(options) {
7017
6969
  }
7018
6970
  });
7019
6971
  }); });
6972
+ // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
6973
+ app.get("".concat(rootPath, "/books/*"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6974
+ var pipelines, fullUrl, pipelineUrl, pipeline, source, error_1;
6975
+ return __generator(this, function (_a) {
6976
+ switch (_a.label) {
6977
+ case 0:
6978
+ _a.trys.push([0, 3, , 4]);
6979
+ if (collection === null) {
6980
+ response.status(500).send('No collection nor books available');
6981
+ return [2 /*return*/];
6982
+ }
6983
+ return [4 /*yield*/, collection.listPipelines()];
6984
+ case 1:
6985
+ pipelines = _a.sent();
6986
+ fullUrl = request.protocol + '://' + request.get('host') + request.originalUrl;
6987
+ pipelineUrl = pipelines.find(function (pipelineUrl) { return pipelineUrl.endsWith(request.originalUrl); }) || fullUrl;
6988
+ return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
6989
+ case 2:
6990
+ pipeline = _a.sent();
6991
+ source = pipeline.sources[0];
6992
+ if (source === undefined || source.type !== 'BOOK') {
6993
+ throw new Error('Pipeline source is not a book');
6994
+ }
6995
+ response
6996
+ .type('text/markdown')
6997
+ .send(source.content);
6998
+ return [3 /*break*/, 4];
6999
+ case 3:
7000
+ error_1 = _a.sent();
7001
+ if (!(error_1 instanceof Error)) {
7002
+ throw error_1;
7003
+ }
7004
+ response
7005
+ .status(404)
7006
+ .send({ error: serializeError(error_1) });
7007
+ return [3 /*break*/, 4];
7008
+ case 4: return [2 /*return*/];
7009
+ }
7010
+ });
7011
+ }); });
7020
7012
  app.get("".concat(rootPath, "/executions"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
7021
7013
  return __generator(this, function (_a) {
7022
7014
  response.send(runningExecutionTasks);
@@ -7029,7 +7021,9 @@ function startRemoteServer(options) {
7029
7021
  taskId = request.params.taskId;
7030
7022
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
7031
7023
  if (execution === undefined) {
7032
- response.status(404).send("Execution \"".concat(taskId, "\" not found"));
7024
+ response
7025
+ .status(404)
7026
+ .send("Execution \"".concat(taskId, "\" not found"));
7033
7027
  return [2 /*return*/];
7034
7028
  }
7035
7029
  response.send(execution.currentValue);
@@ -7037,7 +7031,7 @@ function startRemoteServer(options) {
7037
7031
  });
7038
7032
  }); });
7039
7033
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
7040
- var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
7034
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_2;
7041
7035
  return __generator(this, function (_b) {
7042
7036
  switch (_b.label) {
7043
7037
  case 0:
@@ -7065,11 +7059,11 @@ function startRemoteServer(options) {
7065
7059
  response.send(executionTask);
7066
7060
  return [3 /*break*/, 5];
7067
7061
  case 4:
7068
- error_1 = _b.sent();
7069
- if (!(error_1 instanceof Error)) {
7070
- throw error_1;
7062
+ error_2 = _b.sent();
7063
+ if (!(error_2 instanceof Error)) {
7064
+ throw error_2;
7071
7065
  }
7072
- response.status(400).send({ error: serializeError(error_1) });
7066
+ response.status(400).send({ error: serializeError(error_2) });
7073
7067
  return [3 /*break*/, 5];
7074
7068
  case 5: return [2 /*return*/];
7075
7069
  }
@@ -7090,7 +7084,7 @@ function startRemoteServer(options) {
7090
7084
  }
7091
7085
  // -----------
7092
7086
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7093
- var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
7087
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_3;
7094
7088
  return __generator(this, function (_c) {
7095
7089
  switch (_c.label) {
7096
7090
  case 0:
@@ -7159,11 +7153,11 @@ function startRemoteServer(options) {
7159
7153
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
7160
7154
  return [3 /*break*/, 15];
7161
7155
  case 13:
7162
- error_2 = _c.sent();
7163
- if (!(error_2 instanceof Error)) {
7164
- throw error_2;
7156
+ error_3 = _c.sent();
7157
+ if (!(error_3 instanceof Error)) {
7158
+ throw error_3;
7165
7159
  }
7166
- socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
7160
+ socket.emit('error', serializeError(error_3) /* <- Note: [🤛] */);
7167
7161
  return [3 /*break*/, 15];
7168
7162
  case 14:
7169
7163
  socket.disconnect();
@@ -7175,7 +7169,7 @@ function startRemoteServer(options) {
7175
7169
  // -----------
7176
7170
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7177
7171
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7178
- var identification, tools, llm, models, error_3;
7172
+ var identification, tools, llm, models, error_4;
7179
7173
  return __generator(this, function (_a) {
7180
7174
  switch (_a.label) {
7181
7175
  case 0:
@@ -7196,11 +7190,11 @@ function startRemoteServer(options) {
7196
7190
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
7197
7191
  return [3 /*break*/, 6];
7198
7192
  case 4:
7199
- error_3 = _a.sent();
7200
- if (!(error_3 instanceof Error)) {
7201
- throw error_3;
7193
+ error_4 = _a.sent();
7194
+ if (!(error_4 instanceof Error)) {
7195
+ throw error_4;
7202
7196
  }
7203
- socket.emit('error', serializeError(error_3));
7197
+ socket.emit('error', serializeError(error_4));
7204
7198
  return [3 /*break*/, 6];
7205
7199
  case 5:
7206
7200
  socket.disconnect();
@@ -7212,7 +7206,7 @@ function startRemoteServer(options) {
7212
7206
  // -----------
7213
7207
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7214
7208
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7215
- var identification, pipeline, tools, preparedPipeline, error_4;
7209
+ var identification, pipeline, tools, preparedPipeline, error_5;
7216
7210
  return __generator(this, function (_a) {
7217
7211
  switch (_a.label) {
7218
7212
  case 0:
@@ -7232,11 +7226,11 @@ function startRemoteServer(options) {
7232
7226
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
7233
7227
  return [3 /*break*/, 6];
7234
7228
  case 4:
7235
- error_4 = _a.sent();
7236
- if (!(error_4 instanceof Error)) {
7237
- throw error_4;
7229
+ error_5 = _a.sent();
7230
+ if (!(error_5 instanceof Error)) {
7231
+ throw error_5;
7238
7232
  }
7239
- socket.emit('error', serializeError(error_4));
7233
+ socket.emit('error', serializeError(error_5));
7240
7234
  return [3 /*break*/, 6];
7241
7235
  case 5:
7242
7236
  socket.disconnect();