@promptbook/remote-server 0.89.0-21 → 0.89.0-29

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-21';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-29';
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
  *
@@ -6849,43 +7059,34 @@
6849
7059
  response.setHeader('X-Powered-By', 'Promptbook engine');
6850
7060
  next();
6851
7061
  });
6852
- const swaggerOptions = {
6853
- definition: {
6854
- openapi: '3.0.0',
6855
- info: {
6856
- title: 'Promptbook Remote Server API',
6857
- version: '1.0.0',
6858
- description: 'API documentation for the Promptbook Remote Server',
6859
- },
6860
- /*
6861
- TODO:
6862
- servers: [
6863
- {
6864
- url: `http://localhost:${port}${rootPath}`,
6865
- // <- TODO: Pass some public URLs here
6866
- },
6867
- ],
6868
- */
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;
6869
7069
  },
6870
- apis: ['./src/remote-server/**/*.ts'], // Adjust path as needed
6871
- };
6872
- const swaggerSpec = swaggerJsdoc__default["default"](swaggerOptions);
6873
- const rootPath = ''; // <- TODO: !!!! Remove after merging into feature/elysia+openai+swagger-2
6874
- 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
+ });
6875
7086
  const runningExecutionTasks = [];
6876
7087
  // <- TODO: [🤬] Identify the users
6877
7088
  // TODO: [🧠] Do here some garbage collection of finished tasks
6878
- /**
6879
- * @swagger
6880
- * /:
6881
- * get:
6882
- * summary: Get server details
6883
- * description: Returns details about the Promptbook server.
6884
- * responses:
6885
- * 200:
6886
- * description: Server details in markdown format.
6887
- */
6888
- app.get(['/', rootPath], async (request, response) => {
7089
+ app.get('/', async (request, response) => {
6889
7090
  var _a;
6890
7091
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
6891
7092
  return;
@@ -6904,7 +7105,6 @@
6904
7105
  ## Details
6905
7106
 
6906
7107
  **Server port:** ${port}
6907
- **Server root path:** ${rootPath}
6908
7108
  **Startup date:** ${startupDate.toISOString()}
6909
7109
  **Anonymouse mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
6910
7110
  **Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
@@ -6943,38 +7143,7 @@
6943
7143
  https://github.com/webgptorg/promptbook
6944
7144
  `));
6945
7145
  });
6946
- /**
6947
- * @swagger
6948
- *
6949
- * /login:
6950
- * post:
6951
- * summary: Login to the server
6952
- * description: Login to the server and get identification.
6953
- * requestBody:
6954
- * required: true
6955
- * content:
6956
- * application/json:
6957
- * schema:
6958
- * type: object
6959
- * properties:
6960
- * username:
6961
- * type: string
6962
- * password:
6963
- * type: string
6964
- * appId:
6965
- * type: string
6966
- * responses:
6967
- * 200:
6968
- * description: Successful login
6969
- * content:
6970
- * application/json:
6971
- * schema:
6972
- * type: object
6973
- * properties:
6974
- * identification:
6975
- * type: object
6976
- */
6977
- app.post([`/login`, `${rootPath}/login`], async (request, response) => {
7146
+ app.post(`/login`, async (request, response) => {
6978
7147
  if (!isApplicationModeAllowed || login === null) {
6979
7148
  response.status(400).send('Application mode is not allowed');
6980
7149
  return;
@@ -7014,23 +7183,7 @@
7014
7183
  response.status(400).send({ error: serializeError(error) });
7015
7184
  }
7016
7185
  });
7017
- /**
7018
- * @swagger
7019
- * /books:
7020
- * get:
7021
- * summary: List all books
7022
- * description: Returns a list of all available books in the collection.
7023
- * responses:
7024
- * 200:
7025
- * description: A list of books.
7026
- * content:
7027
- * application/json:
7028
- * schema:
7029
- * type: array
7030
- * items:
7031
- * type: string
7032
- */
7033
- app.get([`/books`, `${rootPath}/books`], async (request, response) => {
7186
+ app.get(`/books`, async (request, response) => {
7034
7187
  if (collection === null) {
7035
7188
  response.status(500).send('No collection available');
7036
7189
  return;
@@ -7040,30 +7193,7 @@
7040
7193
  response.send(pipelines);
7041
7194
  });
7042
7195
  // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
7043
- /**
7044
- * @swagger
7045
- * /books/{bookId}:
7046
- * get:
7047
- * summary: Get book content
7048
- * description: Returns the content of a specific book.
7049
- * parameters:
7050
- * - in: path
7051
- * name: bookId
7052
- * required: true
7053
- * schema:
7054
- * type: string
7055
- * description: The ID of the book to retrieve.
7056
- * responses:
7057
- * 200:
7058
- * description: The content of the book.
7059
- * content:
7060
- * text/markdown:
7061
- * schema:
7062
- * type: string
7063
- * 404:
7064
- * description: Book not found.
7065
- */
7066
- app.get([`/books/*`, `${rootPath}/books/*`], async (request, response) => {
7196
+ app.get(`/books/*`, async (request, response) => {
7067
7197
  try {
7068
7198
  if (collection === null) {
7069
7199
  response.status(500).send('No collection nor books available');
@@ -7115,26 +7245,10 @@
7115
7245
  };
7116
7246
  }
7117
7247
  }
7118
- /**
7119
- * @swagger
7120
- * /executions:
7121
- * get:
7122
- * summary: List all executions
7123
- * description: Returns a list of all running execution tasks.
7124
- * responses:
7125
- * 200:
7126
- * description: A list of execution tasks.
7127
- * content:
7128
- * application/json:
7129
- * schema:
7130
- * type: array
7131
- * items:
7132
- * type: object
7133
- */
7134
- app.get([`/executions`, `${rootPath}/executions`], async (request, response) => {
7248
+ app.get(`/executions`, async (request, response) => {
7135
7249
  response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
7136
7250
  });
7137
- app.get([`/executions/last`, `${rootPath}/executions/last`], async (request, response) => {
7251
+ app.get(`/executions/last`, async (request, response) => {
7138
7252
  // TODO: [🤬] Filter only for user
7139
7253
  if (runningExecutionTasks.length === 0) {
7140
7254
  response.status(404).send('No execution tasks found');
@@ -7143,7 +7257,7 @@
7143
7257
  const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
7144
7258
  response.send(exportExecutionTask(lastExecutionTask, true));
7145
7259
  });
7146
- app.get([`/executions/:taskId`, `${rootPath}/executions/:taskId`], async (request, response) => {
7260
+ app.get(`/executions/:taskId`, async (request, response) => {
7147
7261
  const { taskId } = request.params;
7148
7262
  // TODO: [🤬] Filter only for user
7149
7263
  const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
@@ -7155,36 +7269,7 @@
7155
7269
  }
7156
7270
  response.send(exportExecutionTask(executionTask, true));
7157
7271
  });
7158
- /**
7159
- * @swagger
7160
- * /executions/new:
7161
- * post:
7162
- * summary: Start a new execution
7163
- * description: Starts a new execution task for a given pipeline.
7164
- * requestBody:
7165
- * required: true
7166
- * content:
7167
- * application/json:
7168
- * schema:
7169
- * type: object
7170
- * properties:
7171
- * pipelineUrl:
7172
- * type: string
7173
- * inputParameters:
7174
- * type: object
7175
- * identification:
7176
- * type: object
7177
- * responses:
7178
- * 200:
7179
- * description: The newly created execution task.
7180
- * content:
7181
- * application/json:
7182
- * schema:
7183
- * type: object
7184
- * 400:
7185
- * description: Invalid input.
7186
- */
7187
- app.post([`/executions/new`, `${rootPath}/executions/new`], async (request, response) => {
7272
+ app.post(`/executions/new`, async (request, response) => {
7188
7273
  try {
7189
7274
  const { inputParameters, identification /* <- [🤬] */ } = request.body;
7190
7275
  const pipelineUrl = request.body.pipelineUrl || request.body.book;