@promptbook/remote-server 0.89.0-21 → 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/esm/index.es.js CHANGED
@@ -3,7 +3,7 @@ import express from 'express';
3
3
  import http from 'http';
4
4
  import { Server } from 'socket.io';
5
5
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
6
- import swaggerJsdoc from 'swagger-jsdoc';
6
+ import * as OpenApiValidator from 'express-openapi-validator';
7
7
  import swaggerUi from 'swagger-ui-express';
8
8
  import { forTime } from 'waitasecond';
9
9
  import { randomBytes } from 'crypto';
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
33
33
  * @generated
34
34
  * @see https://github.com/webgptorg/promptbook
35
35
  */
36
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-21';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-28';
37
37
  /**
38
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
39
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6778,6 +6778,198 @@ async function $provideScriptingForNode(options) {
6778
6778
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
6779
6779
  */
6780
6780
 
6781
+ // TODO: !!! List running services from REMOTE_SERVER_URLS
6782
+ // TODO: !!! Import directly from YML
6783
+ /**
6784
+ * @private !!!! Decide how to expose this
6785
+ */
6786
+ const openapiJson = {
6787
+ openapi: '3.0.0',
6788
+ info: {
6789
+ title: 'Promptbook Remote Server API (!!! From TS)',
6790
+ version: '1.0.0',
6791
+ description: 'API documentation for the Promptbook Remote Server',
6792
+ },
6793
+ paths: {
6794
+ '/': {
6795
+ get: {
6796
+ summary: 'Get server details',
6797
+ description: 'Returns details about the Promptbook server.',
6798
+ responses: {
6799
+ '200': {
6800
+ description: 'Server details in markdown format.',
6801
+ },
6802
+ },
6803
+ },
6804
+ },
6805
+ '/login': {
6806
+ post: {
6807
+ summary: 'Login to the server',
6808
+ description: 'Login to the server and get identification.',
6809
+ requestBody: {
6810
+ required: true,
6811
+ content: {
6812
+ 'application/json': {
6813
+ schema: {
6814
+ type: 'object',
6815
+ properties: {
6816
+ username: {
6817
+ type: 'string',
6818
+ },
6819
+ password: {
6820
+ type: 'string',
6821
+ },
6822
+ appId: {
6823
+ type: 'string',
6824
+ },
6825
+ },
6826
+ },
6827
+ },
6828
+ },
6829
+ },
6830
+ responses: {
6831
+ '200': {
6832
+ description: 'Successful login',
6833
+ content: {
6834
+ 'application/json': {
6835
+ schema: {
6836
+ type: 'object',
6837
+ properties: {
6838
+ identification: {
6839
+ type: 'object',
6840
+ },
6841
+ },
6842
+ },
6843
+ },
6844
+ },
6845
+ },
6846
+ },
6847
+ },
6848
+ },
6849
+ '/books': {
6850
+ get: {
6851
+ summary: 'List all books',
6852
+ description: 'Returns a list of all available books in the collection.',
6853
+ responses: {
6854
+ '200': {
6855
+ description: 'A list of books.',
6856
+ content: {
6857
+ 'application/json': {
6858
+ schema: {
6859
+ type: 'array',
6860
+ items: {
6861
+ type: 'string',
6862
+ },
6863
+ },
6864
+ },
6865
+ },
6866
+ },
6867
+ },
6868
+ },
6869
+ },
6870
+ '/books/{bookId}': {
6871
+ get: {
6872
+ summary: 'Get book content',
6873
+ description: 'Returns the content of a specific book.',
6874
+ parameters: [
6875
+ {
6876
+ in: 'path',
6877
+ name: 'bookId',
6878
+ required: true,
6879
+ schema: {
6880
+ type: 'string',
6881
+ },
6882
+ description: 'The ID of the book to retrieve.',
6883
+ },
6884
+ ],
6885
+ responses: {
6886
+ '200': {
6887
+ description: 'The content of the book.',
6888
+ content: {
6889
+ 'text/markdown': {
6890
+ schema: {
6891
+ type: 'string',
6892
+ },
6893
+ },
6894
+ },
6895
+ },
6896
+ '404': {
6897
+ description: 'Book not found.',
6898
+ },
6899
+ },
6900
+ },
6901
+ },
6902
+ '/executions': {
6903
+ get: {
6904
+ summary: 'List all executions',
6905
+ description: 'Returns a list of all running execution tasks.',
6906
+ responses: {
6907
+ '200': {
6908
+ description: 'A list of execution tasks.',
6909
+ content: {
6910
+ 'application/json': {
6911
+ schema: {
6912
+ type: 'array',
6913
+ items: {
6914
+ type: 'object',
6915
+ },
6916
+ },
6917
+ },
6918
+ },
6919
+ },
6920
+ },
6921
+ },
6922
+ },
6923
+ '/executions/new': {
6924
+ post: {
6925
+ summary: 'Start a new execution',
6926
+ description: 'Starts a new execution task for a given pipeline.',
6927
+ requestBody: {
6928
+ required: true,
6929
+ content: {
6930
+ 'application/json': {
6931
+ schema: {
6932
+ type: 'object',
6933
+ properties: {
6934
+ pipelineUrl: {
6935
+ type: 'string',
6936
+ },
6937
+ inputParameters: {
6938
+ type: 'object',
6939
+ },
6940
+ identification: {
6941
+ type: 'object',
6942
+ },
6943
+ },
6944
+ },
6945
+ },
6946
+ },
6947
+ },
6948
+ responses: {
6949
+ '200': {
6950
+ description: 'The newly created execution task.',
6951
+ content: {
6952
+ 'application/json': {
6953
+ schema: {
6954
+ type: 'object',
6955
+ },
6956
+ },
6957
+ },
6958
+ },
6959
+ '400': {
6960
+ description: 'Invalid input.',
6961
+ },
6962
+ },
6963
+ },
6964
+ },
6965
+ },
6966
+ components: {},
6967
+ tags: [],
6968
+ };
6969
+ /**
6970
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6971
+ */
6972
+
6781
6973
  /**
6782
6974
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
6783
6975
  *
@@ -6852,43 +7044,34 @@ function startRemoteServer(options) {
6852
7044
  response.setHeader('X-Powered-By', 'Promptbook engine');
6853
7045
  next();
6854
7046
  });
6855
- const swaggerOptions = {
6856
- definition: {
6857
- openapi: '3.0.0',
6858
- info: {
6859
- title: 'Promptbook Remote Server API',
6860
- version: '1.0.0',
6861
- description: 'API documentation for the Promptbook Remote Server',
6862
- },
6863
- /*
6864
- TODO:
6865
- servers: [
6866
- {
6867
- url: `http://localhost:${port}${rootPath}`,
6868
- // <- TODO: Pass some public URLs here
6869
- },
6870
- ],
6871
- */
7047
+ // TODO: !!! Expose openapiJson to consumer and also allow to add new routes
7048
+ app.use(OpenApiValidator.middleware({
7049
+ apiSpec: openapiJson,
7050
+ // TODO: !!! Adjust
7051
+ ignorePaths(...args) {
7052
+ console.warn(`!!! Ignoring paths`, ...args);
7053
+ return true;
6872
7054
  },
6873
- apis: ['./src/remote-server/**/*.ts'], // Adjust path as needed
6874
- };
6875
- const swaggerSpec = swaggerJsdoc(swaggerOptions);
6876
- const rootPath = ''; // <- TODO: !!!! Remove after merging into feature/elysia+openai+swagger-2
6877
- app.use([`/api-docs`, `${rootPath}/api-docs`], swaggerUi.serve, swaggerUi.setup(swaggerSpec));
7055
+ // TODO: !!! Validate both
7056
+ validateRequests: false,
7057
+ validateResponses: false, // false by default
7058
+ }));
7059
+ app.use([`/api-docs`, `/swagger`], swaggerUi.serve, swaggerUi.setup(openapiJson, {
7060
+ // customCss: '.swagger-ui .topbar { display: none }',
7061
+ // customSiteTitle: 'BRJ API',
7062
+ // customfavIcon: 'https://brj.app/favicon.ico',
7063
+ }));
7064
+ app.get(`/openapi`, (request, response) => {
7065
+ response.json(openapiJson);
7066
+ });
7067
+ // TODO: !!! Remove:
7068
+ app.get(`/xxx`, (request, response) => {
7069
+ response.json(openapiJson);
7070
+ });
6878
7071
  const runningExecutionTasks = [];
6879
7072
  // <- TODO: [🤬] Identify the users
6880
7073
  // TODO: [🧠] Do here some garbage collection of finished tasks
6881
- /**
6882
- * @swagger
6883
- * /:
6884
- * get:
6885
- * summary: Get server details
6886
- * description: Returns details about the Promptbook server.
6887
- * responses:
6888
- * 200:
6889
- * description: Server details in markdown format.
6890
- */
6891
- app.get(['/', rootPath], async (request, response) => {
7074
+ app.get('/', async (request, response) => {
6892
7075
  var _a;
6893
7076
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
6894
7077
  return;
@@ -6907,7 +7090,6 @@ function startRemoteServer(options) {
6907
7090
  ## Details
6908
7091
 
6909
7092
  **Server port:** ${port}
6910
- **Server root path:** ${rootPath}
6911
7093
  **Startup date:** ${startupDate.toISOString()}
6912
7094
  **Anonymouse mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
6913
7095
  **Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
@@ -6946,38 +7128,7 @@ function startRemoteServer(options) {
6946
7128
  https://github.com/webgptorg/promptbook
6947
7129
  `));
6948
7130
  });
6949
- /**
6950
- * @swagger
6951
- *
6952
- * /login:
6953
- * post:
6954
- * summary: Login to the server
6955
- * description: Login to the server and get identification.
6956
- * requestBody:
6957
- * required: true
6958
- * content:
6959
- * application/json:
6960
- * schema:
6961
- * type: object
6962
- * properties:
6963
- * username:
6964
- * type: string
6965
- * password:
6966
- * type: string
6967
- * appId:
6968
- * type: string
6969
- * responses:
6970
- * 200:
6971
- * description: Successful login
6972
- * content:
6973
- * application/json:
6974
- * schema:
6975
- * type: object
6976
- * properties:
6977
- * identification:
6978
- * type: object
6979
- */
6980
- app.post([`/login`, `${rootPath}/login`], async (request, response) => {
7131
+ app.post(`/login`, async (request, response) => {
6981
7132
  if (!isApplicationModeAllowed || login === null) {
6982
7133
  response.status(400).send('Application mode is not allowed');
6983
7134
  return;
@@ -7017,23 +7168,7 @@ function startRemoteServer(options) {
7017
7168
  response.status(400).send({ error: serializeError(error) });
7018
7169
  }
7019
7170
  });
7020
- /**
7021
- * @swagger
7022
- * /books:
7023
- * get:
7024
- * summary: List all books
7025
- * description: Returns a list of all available books in the collection.
7026
- * responses:
7027
- * 200:
7028
- * description: A list of books.
7029
- * content:
7030
- * application/json:
7031
- * schema:
7032
- * type: array
7033
- * items:
7034
- * type: string
7035
- */
7036
- app.get([`/books`, `${rootPath}/books`], async (request, response) => {
7171
+ app.get(`/books`, async (request, response) => {
7037
7172
  if (collection === null) {
7038
7173
  response.status(500).send('No collection available');
7039
7174
  return;
@@ -7043,30 +7178,7 @@ function startRemoteServer(options) {
7043
7178
  response.send(pipelines);
7044
7179
  });
7045
7180
  // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
7046
- /**
7047
- * @swagger
7048
- * /books/{bookId}:
7049
- * get:
7050
- * summary: Get book content
7051
- * description: Returns the content of a specific book.
7052
- * parameters:
7053
- * - in: path
7054
- * name: bookId
7055
- * required: true
7056
- * schema:
7057
- * type: string
7058
- * description: The ID of the book to retrieve.
7059
- * responses:
7060
- * 200:
7061
- * description: The content of the book.
7062
- * content:
7063
- * text/markdown:
7064
- * schema:
7065
- * type: string
7066
- * 404:
7067
- * description: Book not found.
7068
- */
7069
- app.get([`/books/*`, `${rootPath}/books/*`], async (request, response) => {
7181
+ app.get(`/books/*`, async (request, response) => {
7070
7182
  try {
7071
7183
  if (collection === null) {
7072
7184
  response.status(500).send('No collection nor books available');
@@ -7118,26 +7230,10 @@ function startRemoteServer(options) {
7118
7230
  };
7119
7231
  }
7120
7232
  }
7121
- /**
7122
- * @swagger
7123
- * /executions:
7124
- * get:
7125
- * summary: List all executions
7126
- * description: Returns a list of all running execution tasks.
7127
- * responses:
7128
- * 200:
7129
- * description: A list of execution tasks.
7130
- * content:
7131
- * application/json:
7132
- * schema:
7133
- * type: array
7134
- * items:
7135
- * type: object
7136
- */
7137
- app.get([`/executions`, `${rootPath}/executions`], async (request, response) => {
7233
+ app.get(`/executions`, async (request, response) => {
7138
7234
  response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
7139
7235
  });
7140
- app.get([`/executions/last`, `${rootPath}/executions/last`], async (request, response) => {
7236
+ app.get(`/executions/last`, async (request, response) => {
7141
7237
  // TODO: [🤬] Filter only for user
7142
7238
  if (runningExecutionTasks.length === 0) {
7143
7239
  response.status(404).send('No execution tasks found');
@@ -7146,7 +7242,7 @@ function startRemoteServer(options) {
7146
7242
  const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
7147
7243
  response.send(exportExecutionTask(lastExecutionTask, true));
7148
7244
  });
7149
- app.get([`/executions/:taskId`, `${rootPath}/executions/:taskId`], async (request, response) => {
7245
+ app.get(`/executions/:taskId`, async (request, response) => {
7150
7246
  const { taskId } = request.params;
7151
7247
  // TODO: [🤬] Filter only for user
7152
7248
  const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
@@ -7158,36 +7254,7 @@ function startRemoteServer(options) {
7158
7254
  }
7159
7255
  response.send(exportExecutionTask(executionTask, true));
7160
7256
  });
7161
- /**
7162
- * @swagger
7163
- * /executions/new:
7164
- * post:
7165
- * summary: Start a new execution
7166
- * description: Starts a new execution task for a given pipeline.
7167
- * requestBody:
7168
- * required: true
7169
- * content:
7170
- * application/json:
7171
- * schema:
7172
- * type: object
7173
- * properties:
7174
- * pipelineUrl:
7175
- * type: string
7176
- * inputParameters:
7177
- * type: object
7178
- * identification:
7179
- * type: object
7180
- * responses:
7181
- * 200:
7182
- * description: The newly created execution task.
7183
- * content:
7184
- * application/json:
7185
- * schema:
7186
- * type: object
7187
- * 400:
7188
- * description: Invalid input.
7189
- */
7190
- app.post([`/executions/new`, `${rootPath}/executions/new`], async (request, response) => {
7257
+ app.post(`/executions/new`, async (request, response) => {
7191
7258
  try {
7192
7259
  const { inputParameters, identification /* <- [🤬] */ } = request.body;
7193
7260
  const pipelineUrl = request.body.pipelineUrl || request.body.book;