@promptbook/remote-server 0.89.0-20 → 0.89.0-28

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/umd/index.umd.js CHANGED
@@ -1,16 +1,34 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('express'), require('http'), require('socket.io'), require('spacetrim'), require('swagger-jsdoc'), require('swagger-ui-express'), require('waitasecond'), require('crypto'), require('child_process'), require('fs/promises'), require('path'), require('rxjs'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'http', 'socket.io', 'spacetrim', 'swagger-jsdoc', 'swagger-ui-express', 'waitasecond', 'crypto', 'child_process', 'fs/promises', 'path', 'rxjs', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.swaggerJsdoc, global.swaggerUi, global.waitasecond, global.crypto, global.child_process, global.promises, global.path, global.rxjs, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
- })(this, (function (exports, colors, express, http, socket_io, spaceTrim, swaggerJsdoc, swaggerUi, waitasecond, crypto, child_process, promises, path, rxjs, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('colors'), require('express'), require('http'), require('socket.io'), require('spacetrim'), require('express-openapi-validator'), require('swagger-ui-express'), require('waitasecond'), require('crypto'), require('child_process'), require('fs/promises'), require('path'), require('rxjs'), require('prettier'), require('prettier/parser-html'), require('crypto-js/enc-hex'), require('crypto-js/sha256'), require('crypto-js'), require('mime-types'), require('papaparse')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'colors', 'express', 'http', 'socket.io', 'spacetrim', 'express-openapi-validator', 'swagger-ui-express', 'waitasecond', 'crypto', 'child_process', 'fs/promises', 'path', 'rxjs', 'prettier', 'prettier/parser-html', 'crypto-js/enc-hex', 'crypto-js/sha256', 'crypto-js', 'mime-types', 'papaparse'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-server"] = {}, global.colors, global.express, global.http, global.socket_io, global.spaceTrim, global.OpenApiValidator, global.swaggerUi, global.waitasecond, global.crypto, global.child_process, global.promises, global.path, global.rxjs, global.prettier, global.parserHtml, global.hexEncoder, global.sha256, global.cryptoJs, global.mimeTypes, global.papaparse));
5
+ })(this, (function (exports, colors, express, http, socket_io, spaceTrim, OpenApiValidator, swaggerUi, waitasecond, crypto, child_process, promises, path, rxjs, prettier, parserHtml, hexEncoder, sha256, cryptoJs, mimeTypes, papaparse) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
9
27
  var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
10
28
  var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
11
29
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
12
30
  var spaceTrim__default = /*#__PURE__*/_interopDefaultLegacy(spaceTrim);
13
- var swaggerJsdoc__default = /*#__PURE__*/_interopDefaultLegacy(swaggerJsdoc);
31
+ var OpenApiValidator__namespace = /*#__PURE__*/_interopNamespace(OpenApiValidator);
14
32
  var swaggerUi__default = /*#__PURE__*/_interopDefaultLegacy(swaggerUi);
15
33
  var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
16
34
  var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
@@ -30,7 +48,7 @@
30
48
  * @generated
31
49
  * @see https://github.com/webgptorg/promptbook
32
50
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-20';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-28';
34
52
  /**
35
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
54
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6775,6 +6793,198 @@
6775
6793
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6776
6794
  */
6777
6795
 
6796
+ // TODO: !!! List running services from REMOTE_SERVER_URLS
6797
+ // TODO: !!! Import directly from YML
6798
+ /**
6799
+ * @private !!!! Decide how to expose this
6800
+ */
6801
+ const openapiJson = {
6802
+ openapi: '3.0.0',
6803
+ info: {
6804
+ title: 'Promptbook Remote Server API (!!! From TS)',
6805
+ version: '1.0.0',
6806
+ description: 'API documentation for the Promptbook Remote Server',
6807
+ },
6808
+ paths: {
6809
+ '/': {
6810
+ get: {
6811
+ summary: 'Get server details',
6812
+ description: 'Returns details about the Promptbook server.',
6813
+ responses: {
6814
+ '200': {
6815
+ description: 'Server details in markdown format.',
6816
+ },
6817
+ },
6818
+ },
6819
+ },
6820
+ '/login': {
6821
+ post: {
6822
+ summary: 'Login to the server',
6823
+ description: 'Login to the server and get identification.',
6824
+ requestBody: {
6825
+ required: true,
6826
+ content: {
6827
+ 'application/json': {
6828
+ schema: {
6829
+ type: 'object',
6830
+ properties: {
6831
+ username: {
6832
+ type: 'string',
6833
+ },
6834
+ password: {
6835
+ type: 'string',
6836
+ },
6837
+ appId: {
6838
+ type: 'string',
6839
+ },
6840
+ },
6841
+ },
6842
+ },
6843
+ },
6844
+ },
6845
+ responses: {
6846
+ '200': {
6847
+ description: 'Successful login',
6848
+ content: {
6849
+ 'application/json': {
6850
+ schema: {
6851
+ type: 'object',
6852
+ properties: {
6853
+ identification: {
6854
+ type: 'object',
6855
+ },
6856
+ },
6857
+ },
6858
+ },
6859
+ },
6860
+ },
6861
+ },
6862
+ },
6863
+ },
6864
+ '/books': {
6865
+ get: {
6866
+ summary: 'List all books',
6867
+ description: 'Returns a list of all available books in the collection.',
6868
+ responses: {
6869
+ '200': {
6870
+ description: 'A list of books.',
6871
+ content: {
6872
+ 'application/json': {
6873
+ schema: {
6874
+ type: 'array',
6875
+ items: {
6876
+ type: 'string',
6877
+ },
6878
+ },
6879
+ },
6880
+ },
6881
+ },
6882
+ },
6883
+ },
6884
+ },
6885
+ '/books/{bookId}': {
6886
+ get: {
6887
+ summary: 'Get book content',
6888
+ description: 'Returns the content of a specific book.',
6889
+ parameters: [
6890
+ {
6891
+ in: 'path',
6892
+ name: 'bookId',
6893
+ required: true,
6894
+ schema: {
6895
+ type: 'string',
6896
+ },
6897
+ description: 'The ID of the book to retrieve.',
6898
+ },
6899
+ ],
6900
+ responses: {
6901
+ '200': {
6902
+ description: 'The content of the book.',
6903
+ content: {
6904
+ 'text/markdown': {
6905
+ schema: {
6906
+ type: 'string',
6907
+ },
6908
+ },
6909
+ },
6910
+ },
6911
+ '404': {
6912
+ description: 'Book not found.',
6913
+ },
6914
+ },
6915
+ },
6916
+ },
6917
+ '/executions': {
6918
+ get: {
6919
+ summary: 'List all executions',
6920
+ description: 'Returns a list of all running execution tasks.',
6921
+ responses: {
6922
+ '200': {
6923
+ description: 'A list of execution tasks.',
6924
+ content: {
6925
+ 'application/json': {
6926
+ schema: {
6927
+ type: 'array',
6928
+ items: {
6929
+ type: 'object',
6930
+ },
6931
+ },
6932
+ },
6933
+ },
6934
+ },
6935
+ },
6936
+ },
6937
+ },
6938
+ '/executions/new': {
6939
+ post: {
6940
+ summary: 'Start a new execution',
6941
+ description: 'Starts a new execution task for a given pipeline.',
6942
+ requestBody: {
6943
+ required: true,
6944
+ content: {
6945
+ 'application/json': {
6946
+ schema: {
6947
+ type: 'object',
6948
+ properties: {
6949
+ pipelineUrl: {
6950
+ type: 'string',
6951
+ },
6952
+ inputParameters: {
6953
+ type: 'object',
6954
+ },
6955
+ identification: {
6956
+ type: 'object',
6957
+ },
6958
+ },
6959
+ },
6960
+ },
6961
+ },
6962
+ },
6963
+ responses: {
6964
+ '200': {
6965
+ description: 'The newly created execution task.',
6966
+ content: {
6967
+ 'application/json': {
6968
+ schema: {
6969
+ type: 'object',
6970
+ },
6971
+ },
6972
+ },
6973
+ },
6974
+ '400': {
6975
+ description: 'Invalid input.',
6976
+ },
6977
+ },
6978
+ },
6979
+ },
6980
+ },
6981
+ components: {},
6982
+ tags: [],
6983
+ };
6984
+ /**
6985
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6986
+ */
6987
+
6778
6988
  /**
6779
6989
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
6780
6990
  *
@@ -6793,22 +7003,6 @@
6793
7003
  login: null,
6794
7004
  ...options,
6795
7005
  };
6796
- // <- TODO: [🦪] Some helper type to be able to use discriminant union types with destructuring
6797
- let { rootPath = '/' } = options;
6798
- if (!rootPath.startsWith('/')) {
6799
- rootPath = `/${rootPath}`;
6800
- } /* not else */
6801
- if (rootPath.endsWith('/')) {
6802
- rootPath = rootPath.slice(0, -1);
6803
- } /* not else */
6804
- if (rootPath === '/') {
6805
- rootPath = '';
6806
- }
6807
- const socketioPath = '/' +
6808
- `${rootPath}/socket.io`
6809
- .split('/')
6810
- .filter((part) => part !== '')
6811
- .join('/');
6812
7006
  const startupDate = new Date();
6813
7007
  async function getExecutionToolsFromIdentification(identification) {
6814
7008
  if (identification === null || identification === undefined) {
@@ -6865,39 +7059,34 @@
6865
7059
  response.setHeader('X-Powered-By', 'Promptbook engine');
6866
7060
  next();
6867
7061
  });
6868
- const swaggerOptions = {
6869
- definition: {
6870
- openapi: '3.0.0',
6871
- info: {
6872
- title: 'Promptbook Remote Server API',
6873
- version: '1.0.0',
6874
- description: 'API documentation for the Promptbook Remote Server',
6875
- },
6876
- servers: [
6877
- {
6878
- url: `http://localhost:${port}${rootPath}`,
6879
- // <- TODO: !!!!! Probbably: Pass `remoteServerUrl` instead of `port` and `rootPath`
6880
- },
6881
- ],
7062
+ // TODO: !!! Expose openapiJson to consumer and also allow to add new routes
7063
+ app.use(OpenApiValidator__namespace.middleware({
7064
+ apiSpec: openapiJson,
7065
+ // TODO: !!! Adjust
7066
+ ignorePaths(...args) {
7067
+ console.warn(`!!! Ignoring paths`, ...args);
7068
+ return true;
6882
7069
  },
6883
- apis: ['./src/remote-server/**/*.ts'], // Adjust path as needed
6884
- };
6885
- const swaggerSpec = swaggerJsdoc__default["default"](swaggerOptions);
6886
- app.use([`/api-docs`, `${rootPath}/api-docs`], swaggerUi__default["default"].serve, swaggerUi__default["default"].setup(swaggerSpec));
7070
+ // TODO: !!! Validate both
7071
+ validateRequests: false,
7072
+ validateResponses: false, // false by default
7073
+ }));
7074
+ app.use([`/api-docs`, `/swagger`], swaggerUi__default["default"].serve, swaggerUi__default["default"].setup(openapiJson, {
7075
+ // customCss: '.swagger-ui .topbar { display: none }',
7076
+ // customSiteTitle: 'BRJ API',
7077
+ // customfavIcon: 'https://brj.app/favicon.ico',
7078
+ }));
7079
+ app.get(`/openapi`, (request, response) => {
7080
+ response.json(openapiJson);
7081
+ });
7082
+ // TODO: !!! Remove:
7083
+ app.get(`/xxx`, (request, response) => {
7084
+ response.json(openapiJson);
7085
+ });
6887
7086
  const runningExecutionTasks = [];
6888
7087
  // <- TODO: [🤬] Identify the users
6889
7088
  // TODO: [🧠] Do here some garbage collection of finished tasks
6890
- /**
6891
- * @swagger
6892
- * /:
6893
- * get:
6894
- * summary: Get server details
6895
- * description: Returns details about the Promptbook server.
6896
- * responses:
6897
- * 200:
6898
- * description: Server details in markdown format.
6899
- */
6900
- app.get(['/', rootPath], async (request, response) => {
7089
+ app.get('/', async (request, response) => {
6901
7090
  var _a;
6902
7091
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
6903
7092
  return;
@@ -6916,8 +7105,6 @@
6916
7105
  ## Details
6917
7106
 
6918
7107
  **Server port:** ${port}
6919
- **Server root path:** ${rootPath}
6920
- **Socket.io path:** ${socketioPath}
6921
7108
  **Startup date:** ${startupDate.toISOString()}
6922
7109
  **Anonymouse mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
6923
7110
  **Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
@@ -6956,38 +7143,7 @@
6956
7143
  https://github.com/webgptorg/promptbook
6957
7144
  `));
6958
7145
  });
6959
- /**
6960
- * @swagger
6961
- *
6962
- * /login:
6963
- * post:
6964
- * summary: Login to the server
6965
- * description: Login to the server and get identification.
6966
- * requestBody:
6967
- * required: true
6968
- * content:
6969
- * application/json:
6970
- * schema:
6971
- * type: object
6972
- * properties:
6973
- * username:
6974
- * type: string
6975
- * password:
6976
- * type: string
6977
- * appId:
6978
- * type: string
6979
- * responses:
6980
- * 200:
6981
- * description: Successful login
6982
- * content:
6983
- * application/json:
6984
- * schema:
6985
- * type: object
6986
- * properties:
6987
- * identification:
6988
- * type: object
6989
- */
6990
- app.post([`/login`, `${rootPath}/login`], async (request, response) => {
7146
+ app.post(`/login`, async (request, response) => {
6991
7147
  if (!isApplicationModeAllowed || login === null) {
6992
7148
  response.status(400).send('Application mode is not allowed');
6993
7149
  return;
@@ -7027,23 +7183,7 @@
7027
7183
  response.status(400).send({ error: serializeError(error) });
7028
7184
  }
7029
7185
  });
7030
- /**
7031
- * @swagger
7032
- * /books:
7033
- * get:
7034
- * summary: List all books
7035
- * description: Returns a list of all available books in the collection.
7036
- * responses:
7037
- * 200:
7038
- * description: A list of books.
7039
- * content:
7040
- * application/json:
7041
- * schema:
7042
- * type: array
7043
- * items:
7044
- * type: string
7045
- */
7046
- app.get([`/books`, `${rootPath}/books`], async (request, response) => {
7186
+ app.get(`/books`, async (request, response) => {
7047
7187
  if (collection === null) {
7048
7188
  response.status(500).send('No collection available');
7049
7189
  return;
@@ -7053,30 +7193,7 @@
7053
7193
  response.send(pipelines);
7054
7194
  });
7055
7195
  // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
7056
- /**
7057
- * @swagger
7058
- * /books/{bookId}:
7059
- * get:
7060
- * summary: Get book content
7061
- * description: Returns the content of a specific book.
7062
- * parameters:
7063
- * - in: path
7064
- * name: bookId
7065
- * required: true
7066
- * schema:
7067
- * type: string
7068
- * description: The ID of the book to retrieve.
7069
- * responses:
7070
- * 200:
7071
- * description: The content of the book.
7072
- * content:
7073
- * text/markdown:
7074
- * schema:
7075
- * type: string
7076
- * 404:
7077
- * description: Book not found.
7078
- */
7079
- app.get([`/books/*`, `${rootPath}/books/*`], async (request, response) => {
7196
+ app.get(`/books/*`, async (request, response) => {
7080
7197
  try {
7081
7198
  if (collection === null) {
7082
7199
  response.status(500).send('No collection nor books available');
@@ -7128,26 +7245,10 @@
7128
7245
  };
7129
7246
  }
7130
7247
  }
7131
- /**
7132
- * @swagger
7133
- * /executions:
7134
- * get:
7135
- * summary: List all executions
7136
- * description: Returns a list of all running execution tasks.
7137
- * responses:
7138
- * 200:
7139
- * description: A list of execution tasks.
7140
- * content:
7141
- * application/json:
7142
- * schema:
7143
- * type: array
7144
- * items:
7145
- * type: object
7146
- */
7147
- app.get([`/executions`, `${rootPath}/executions`], async (request, response) => {
7248
+ app.get(`/executions`, async (request, response) => {
7148
7249
  response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
7149
7250
  });
7150
- app.get([`/executions/last`, `${rootPath}/executions/last`], async (request, response) => {
7251
+ app.get(`/executions/last`, async (request, response) => {
7151
7252
  // TODO: [🤬] Filter only for user
7152
7253
  if (runningExecutionTasks.length === 0) {
7153
7254
  response.status(404).send('No execution tasks found');
@@ -7156,7 +7257,7 @@
7156
7257
  const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
7157
7258
  response.send(exportExecutionTask(lastExecutionTask, true));
7158
7259
  });
7159
- app.get([`/executions/:taskId`, `${rootPath}/executions/:taskId`], async (request, response) => {
7260
+ app.get(`/executions/:taskId`, async (request, response) => {
7160
7261
  const { taskId } = request.params;
7161
7262
  // TODO: [🤬] Filter only for user
7162
7263
  const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
@@ -7168,36 +7269,7 @@
7168
7269
  }
7169
7270
  response.send(exportExecutionTask(executionTask, true));
7170
7271
  });
7171
- /**
7172
- * @swagger
7173
- * /executions/new:
7174
- * post:
7175
- * summary: Start a new execution
7176
- * description: Starts a new execution task for a given pipeline.
7177
- * requestBody:
7178
- * required: true
7179
- * content:
7180
- * application/json:
7181
- * schema:
7182
- * type: object
7183
- * properties:
7184
- * pipelineUrl:
7185
- * type: string
7186
- * inputParameters:
7187
- * type: object
7188
- * identification:
7189
- * type: object
7190
- * responses:
7191
- * 200:
7192
- * description: The newly created execution task.
7193
- * content:
7194
- * application/json:
7195
- * schema:
7196
- * type: object
7197
- * 400:
7198
- * description: Invalid input.
7199
- */
7200
- app.post([`/executions/new`, `${rootPath}/executions/new`], async (request, response) => {
7272
+ app.post(`/executions/new`, async (request, response) => {
7201
7273
  try {
7202
7274
  const { inputParameters, identification /* <- [🤬] */ } = request.body;
7203
7275
  const pipelineUrl = request.body.pipelineUrl || request.body.book;
@@ -7246,11 +7318,12 @@
7246
7318
  });
7247
7319
  const httpServer = http__default["default"].createServer(app);
7248
7320
  const server = new socket_io.Server(httpServer, {
7249
- path: socketioPath,
7250
- transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
7321
+ path: '/socket.io',
7322
+ transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
7251
7323
  cors: {
7252
7324
  origin: '*',
7253
7325
  methods: ['GET', 'POST'],
7326
+ // <- TODO: [🌡] Allow to pass
7254
7327
  },
7255
7328
  });
7256
7329
  server.on('connection', (socket) => {
@@ -7395,7 +7468,7 @@
7395
7468
  };
7396
7469
  }
7397
7470
  /**
7398
- * TODO: !! Add CORS and security - probbably via `helmet`
7471
+ * TODO: [🌡] Add CORS and security - probbably via `helmet`
7399
7472
  * TODO: Split this file into multiple functions - handler for each request
7400
7473
  * TODO: Maybe use `$exportJson`
7401
7474
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`