@promptbook/remote-server 0.89.0-4 → 0.89.0-6

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,6 +3,8 @@ import express from 'express';
3
3
  import http from 'http';
4
4
  import { Server } from 'socket.io';
5
5
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
6
+ import swaggerJsdoc from 'swagger-jsdoc';
7
+ import swaggerUi from 'swagger-ui-express';
6
8
  import { forTime } from 'waitasecond';
7
9
  import { randomBytes } from 'crypto';
8
10
  import { spawn } from 'child_process';
@@ -31,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
31
33
  * @generated
32
34
  * @see https://github.com/webgptorg/promptbook
33
35
  */
34
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-4';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-6';
35
37
  /**
36
38
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
37
39
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6782,9 +6784,37 @@ function startRemoteServer(options) {
6782
6784
  response.setHeader('X-Powered-By', 'Promptbook engine');
6783
6785
  next();
6784
6786
  });
6787
+ const swaggerOptions = {
6788
+ definition: {
6789
+ openapi: '3.0.0',
6790
+ info: {
6791
+ title: 'Promptbook Remote Server API',
6792
+ version: '1.0.0',
6793
+ description: 'API documentation for the Promptbook Remote Server',
6794
+ },
6795
+ servers: [
6796
+ {
6797
+ url: `http://localhost:${port}${rootPath}`,
6798
+ },
6799
+ ],
6800
+ },
6801
+ apis: ['./src/remote-server/**/*.ts'], // Adjust path as needed
6802
+ };
6803
+ const swaggerSpec = swaggerJsdoc(swaggerOptions);
6804
+ app.use(`${rootPath}/api-docs`, swaggerUi.serve, swaggerUi.setup(swaggerSpec));
6785
6805
  const runningExecutionTasks = [];
6786
6806
  // <- TODO: [🤬] Identify the users
6787
6807
  // TODO: [🧠] Do here some garbage collection of finished tasks
6808
+ /**
6809
+ * @swagger
6810
+ * /:
6811
+ * get:
6812
+ * summary: Get server details
6813
+ * description: Returns details about the Promptbook server.
6814
+ * responses:
6815
+ * 200:
6816
+ * description: Server details in markdown format.
6817
+ */
6788
6818
  app.get(['/', rootPath], async (request, response) => {
6789
6819
  var _a;
6790
6820
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
@@ -6842,6 +6872,22 @@ function startRemoteServer(options) {
6842
6872
  `));
6843
6873
  });
6844
6874
  // TODO: !!!!!! Add login route
6875
+ /**
6876
+ * @swagger
6877
+ * /books:
6878
+ * get:
6879
+ * summary: List all books
6880
+ * description: Returns a list of all available books in the collection.
6881
+ * responses:
6882
+ * 200:
6883
+ * description: A list of books.
6884
+ * content:
6885
+ * application/json:
6886
+ * schema:
6887
+ * type: array
6888
+ * items:
6889
+ * type: string
6890
+ */
6845
6891
  app.get(`${rootPath}/books`, async (request, response) => {
6846
6892
  if (collection === null) {
6847
6893
  response.status(500).send('No collection available');
@@ -6852,6 +6898,29 @@ function startRemoteServer(options) {
6852
6898
  response.send(pipelines);
6853
6899
  });
6854
6900
  // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
6901
+ /**
6902
+ * @swagger
6903
+ * /books/{bookId}:
6904
+ * get:
6905
+ * summary: Get book content
6906
+ * description: Returns the content of a specific book.
6907
+ * parameters:
6908
+ * - in: path
6909
+ * name: bookId
6910
+ * required: true
6911
+ * schema:
6912
+ * type: string
6913
+ * description: The ID of the book to retrieve.
6914
+ * responses:
6915
+ * 200:
6916
+ * description: The content of the book.
6917
+ * content:
6918
+ * text/markdown:
6919
+ * schema:
6920
+ * type: string
6921
+ * 404:
6922
+ * description: Book not found.
6923
+ */
6855
6924
  app.get(`${rootPath}/books/*`, async (request, response) => {
6856
6925
  try {
6857
6926
  if (collection === null) {
@@ -6906,6 +6975,22 @@ function startRemoteServer(options) {
6906
6975
  };
6907
6976
  }
6908
6977
  }
6978
+ /**
6979
+ * @swagger
6980
+ * /executions:
6981
+ * get:
6982
+ * summary: List all executions
6983
+ * description: Returns a list of all running execution tasks.
6984
+ * responses:
6985
+ * 200:
6986
+ * description: A list of execution tasks.
6987
+ * content:
6988
+ * application/json:
6989
+ * schema:
6990
+ * type: array
6991
+ * items:
6992
+ * type: object
6993
+ */
6909
6994
  app.get(`${rootPath}/executions`, async (request, response) => {
6910
6995
  response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
6911
6996
  });
@@ -6930,6 +7015,35 @@ function startRemoteServer(options) {
6930
7015
  }
6931
7016
  response.send(exportExecutionTask(executionTask, true));
6932
7017
  });
7018
+ /**
7019
+ * @swagger
7020
+ * /executions/new:
7021
+ * post:
7022
+ * summary: Start a new execution
7023
+ * description: Starts a new execution task for a given pipeline.
7024
+ * requestBody:
7025
+ * required: true
7026
+ * content:
7027
+ * application/json:
7028
+ * schema:
7029
+ * type: object
7030
+ * properties:
7031
+ * pipelineUrl:
7032
+ * type: string
7033
+ * inputParameters:
7034
+ * type: object
7035
+ * identification:
7036
+ * type: object
7037
+ * responses:
7038
+ * 200:
7039
+ * description: The newly created execution task.
7040
+ * content:
7041
+ * application/json:
7042
+ * schema:
7043
+ * type: object
7044
+ * 400:
7045
+ * description: Invalid input.
7046
+ */
6933
7047
  app.post(`${rootPath}/executions/new`, async (request, response) => {
6934
7048
  try {
6935
7049
  const { inputParameters, identification /* <- [🤬] */ } = request.body;
@@ -7107,6 +7221,15 @@ function startRemoteServer(options) {
7107
7221
  }
7108
7222
  let isDestroyed = false;
7109
7223
  return {
7224
+ get httpServer() {
7225
+ return httpServer;
7226
+ },
7227
+ get expressApp() {
7228
+ return app;
7229
+ },
7230
+ get socketIoServer() {
7231
+ return server;
7232
+ },
7110
7233
  get isDestroyed() {
7111
7234
  return isDestroyed;
7112
7235
  },