@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.
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.85.0-9",
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-9"
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-8';
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
  /**
@@ -7014,6 +6966,46 @@
7014
6966
  }
7015
6967
  });
7016
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
+ }); });
7017
7009
  app.get("".concat(rootPath, "/executions"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
7018
7010
  return __generator(this, function (_a) {
7019
7011
  response.send(runningExecutionTasks);
@@ -7026,7 +7018,9 @@
7026
7018
  taskId = request.params.taskId;
7027
7019
  execution = runningExecutionTasks.find(function (executionTask) { return executionTask.taskId === taskId; });
7028
7020
  if (execution === undefined) {
7029
- response.status(404).send("Execution \"".concat(taskId, "\" not found"));
7021
+ response
7022
+ .status(404)
7023
+ .send("Execution \"".concat(taskId, "\" not found"));
7030
7024
  return [2 /*return*/];
7031
7025
  }
7032
7026
  response.send(execution.currentValue);
@@ -7034,7 +7028,7 @@
7034
7028
  });
7035
7029
  }); });
7036
7030
  app.post("".concat(rootPath, "/executions/new"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
7037
- var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_1;
7031
+ var _a, inputParameters, identification, pipelineUrl, pipeline, tools, pipelineExecutor, executionTask, error_2;
7038
7032
  return __generator(this, function (_b) {
7039
7033
  switch (_b.label) {
7040
7034
  case 0:
@@ -7062,11 +7056,11 @@
7062
7056
  response.send(executionTask);
7063
7057
  return [3 /*break*/, 5];
7064
7058
  case 4:
7065
- error_1 = _b.sent();
7066
- if (!(error_1 instanceof Error)) {
7067
- throw error_1;
7059
+ error_2 = _b.sent();
7060
+ if (!(error_2 instanceof Error)) {
7061
+ throw error_2;
7068
7062
  }
7069
- response.status(400).send({ error: serializeError(error_1) });
7063
+ response.status(400).send({ error: serializeError(error_2) });
7070
7064
  return [3 /*break*/, 5];
7071
7065
  case 5: return [2 /*return*/];
7072
7066
  }
@@ -7087,7 +7081,7 @@
7087
7081
  }
7088
7082
  // -----------
7089
7083
  socket.on('prompt-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7090
- var identification, prompt, tools, llm, _a, promptResult, _b, error_2;
7084
+ var identification, prompt, tools, llm, _a, promptResult, _b, error_3;
7091
7085
  return __generator(this, function (_c) {
7092
7086
  switch (_c.label) {
7093
7087
  case 0:
@@ -7156,11 +7150,11 @@
7156
7150
  socket.emit('prompt-response', { promptResult: promptResult } /* <- Note: [🤛] */);
7157
7151
  return [3 /*break*/, 15];
7158
7152
  case 13:
7159
- error_2 = _c.sent();
7160
- if (!(error_2 instanceof Error)) {
7161
- throw error_2;
7153
+ error_3 = _c.sent();
7154
+ if (!(error_3 instanceof Error)) {
7155
+ throw error_3;
7162
7156
  }
7163
- socket.emit('error', serializeError(error_2) /* <- Note: [🤛] */);
7157
+ socket.emit('error', serializeError(error_3) /* <- Note: [🤛] */);
7164
7158
  return [3 /*break*/, 15];
7165
7159
  case 14:
7166
7160
  socket.disconnect();
@@ -7172,7 +7166,7 @@
7172
7166
  // -----------
7173
7167
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7174
7168
  socket.on('listModels-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7175
- var identification, tools, llm, models, error_3;
7169
+ var identification, tools, llm, models, error_4;
7176
7170
  return __generator(this, function (_a) {
7177
7171
  switch (_a.label) {
7178
7172
  case 0:
@@ -7193,11 +7187,11 @@
7193
7187
  socket.emit('listModels-response', { models: models } /* <- Note: [🤛] */);
7194
7188
  return [3 /*break*/, 6];
7195
7189
  case 4:
7196
- error_3 = _a.sent();
7197
- if (!(error_3 instanceof Error)) {
7198
- throw error_3;
7190
+ error_4 = _a.sent();
7191
+ if (!(error_4 instanceof Error)) {
7192
+ throw error_4;
7199
7193
  }
7200
- socket.emit('error', serializeError(error_3));
7194
+ socket.emit('error', serializeError(error_4));
7201
7195
  return [3 /*break*/, 6];
7202
7196
  case 5:
7203
7197
  socket.disconnect();
@@ -7209,7 +7203,7 @@
7209
7203
  // -----------
7210
7204
  // TODO: [👒] Listing models (and checking configuration) probbably should go through REST API not Socket.io
7211
7205
  socket.on('preparePipeline-request', function (request) { return __awaiter(_this, void 0, void 0, function () {
7212
- var identification, pipeline, tools, preparedPipeline, error_4;
7206
+ var identification, pipeline, tools, preparedPipeline, error_5;
7213
7207
  return __generator(this, function (_a) {
7214
7208
  switch (_a.label) {
7215
7209
  case 0:
@@ -7229,11 +7223,11 @@
7229
7223
  socket.emit('preparePipeline-response', { preparedPipeline: preparedPipeline } /* <- Note: [🤛] */);
7230
7224
  return [3 /*break*/, 6];
7231
7225
  case 4:
7232
- error_4 = _a.sent();
7233
- if (!(error_4 instanceof Error)) {
7234
- throw error_4;
7226
+ error_5 = _a.sent();
7227
+ if (!(error_5 instanceof Error)) {
7228
+ throw error_5;
7235
7229
  }
7236
- socket.emit('error', serializeError(error_4));
7230
+ socket.emit('error', serializeError(error_5));
7237
7231
  return [3 /*break*/, 6];
7238
7232
  case 5:
7239
7233
  socket.disconnect();