@promptbook/cli 0.89.0-27 → 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/esm/index.es.js CHANGED
@@ -23,7 +23,7 @@ import moment from 'moment';
23
23
  import express from 'express';
24
24
  import http from 'http';
25
25
  import { Server } from 'socket.io';
26
- import swaggerJsdoc from 'swagger-jsdoc';
26
+ import * as OpenApiValidator from 'express-openapi-validator';
27
27
  import swaggerUi from 'swagger-ui-express';
28
28
  import Anthropic from '@anthropic-ai/sdk';
29
29
  import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
@@ -46,7 +46,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-27';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-29';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -13108,6 +13108,198 @@ function $initializeRunCommand(program) {
13108
13108
  * TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
13109
13109
  */
13110
13110
 
13111
+ // TODO: !!! List running services from REMOTE_SERVER_URLS
13112
+ // TODO: !!! Import directly from YML
13113
+ /**
13114
+ * @private !!!! Decide how to expose this
13115
+ */
13116
+ const openapiJson = {
13117
+ openapi: '3.0.0',
13118
+ info: {
13119
+ title: 'Promptbook Remote Server API (!!! From TS)',
13120
+ version: '1.0.0',
13121
+ description: 'API documentation for the Promptbook Remote Server',
13122
+ },
13123
+ paths: {
13124
+ '/': {
13125
+ get: {
13126
+ summary: 'Get server details',
13127
+ description: 'Returns details about the Promptbook server.',
13128
+ responses: {
13129
+ '200': {
13130
+ description: 'Server details in markdown format.',
13131
+ },
13132
+ },
13133
+ },
13134
+ },
13135
+ '/login': {
13136
+ post: {
13137
+ summary: 'Login to the server',
13138
+ description: 'Login to the server and get identification.',
13139
+ requestBody: {
13140
+ required: true,
13141
+ content: {
13142
+ 'application/json': {
13143
+ schema: {
13144
+ type: 'object',
13145
+ properties: {
13146
+ username: {
13147
+ type: 'string',
13148
+ },
13149
+ password: {
13150
+ type: 'string',
13151
+ },
13152
+ appId: {
13153
+ type: 'string',
13154
+ },
13155
+ },
13156
+ },
13157
+ },
13158
+ },
13159
+ },
13160
+ responses: {
13161
+ '200': {
13162
+ description: 'Successful login',
13163
+ content: {
13164
+ 'application/json': {
13165
+ schema: {
13166
+ type: 'object',
13167
+ properties: {
13168
+ identification: {
13169
+ type: 'object',
13170
+ },
13171
+ },
13172
+ },
13173
+ },
13174
+ },
13175
+ },
13176
+ },
13177
+ },
13178
+ },
13179
+ '/books': {
13180
+ get: {
13181
+ summary: 'List all books',
13182
+ description: 'Returns a list of all available books in the collection.',
13183
+ responses: {
13184
+ '200': {
13185
+ description: 'A list of books.',
13186
+ content: {
13187
+ 'application/json': {
13188
+ schema: {
13189
+ type: 'array',
13190
+ items: {
13191
+ type: 'string',
13192
+ },
13193
+ },
13194
+ },
13195
+ },
13196
+ },
13197
+ },
13198
+ },
13199
+ },
13200
+ '/books/{bookId}': {
13201
+ get: {
13202
+ summary: 'Get book content',
13203
+ description: 'Returns the content of a specific book.',
13204
+ parameters: [
13205
+ {
13206
+ in: 'path',
13207
+ name: 'bookId',
13208
+ required: true,
13209
+ schema: {
13210
+ type: 'string',
13211
+ },
13212
+ description: 'The ID of the book to retrieve.',
13213
+ },
13214
+ ],
13215
+ responses: {
13216
+ '200': {
13217
+ description: 'The content of the book.',
13218
+ content: {
13219
+ 'text/markdown': {
13220
+ schema: {
13221
+ type: 'string',
13222
+ },
13223
+ },
13224
+ },
13225
+ },
13226
+ '404': {
13227
+ description: 'Book not found.',
13228
+ },
13229
+ },
13230
+ },
13231
+ },
13232
+ '/executions': {
13233
+ get: {
13234
+ summary: 'List all executions',
13235
+ description: 'Returns a list of all running execution tasks.',
13236
+ responses: {
13237
+ '200': {
13238
+ description: 'A list of execution tasks.',
13239
+ content: {
13240
+ 'application/json': {
13241
+ schema: {
13242
+ type: 'array',
13243
+ items: {
13244
+ type: 'object',
13245
+ },
13246
+ },
13247
+ },
13248
+ },
13249
+ },
13250
+ },
13251
+ },
13252
+ },
13253
+ '/executions/new': {
13254
+ post: {
13255
+ summary: 'Start a new execution',
13256
+ description: 'Starts a new execution task for a given pipeline.',
13257
+ requestBody: {
13258
+ required: true,
13259
+ content: {
13260
+ 'application/json': {
13261
+ schema: {
13262
+ type: 'object',
13263
+ properties: {
13264
+ pipelineUrl: {
13265
+ type: 'string',
13266
+ },
13267
+ inputParameters: {
13268
+ type: 'object',
13269
+ },
13270
+ identification: {
13271
+ type: 'object',
13272
+ },
13273
+ },
13274
+ },
13275
+ },
13276
+ },
13277
+ },
13278
+ responses: {
13279
+ '200': {
13280
+ description: 'The newly created execution task.',
13281
+ content: {
13282
+ 'application/json': {
13283
+ schema: {
13284
+ type: 'object',
13285
+ },
13286
+ },
13287
+ },
13288
+ },
13289
+ '400': {
13290
+ description: 'Invalid input.',
13291
+ },
13292
+ },
13293
+ },
13294
+ },
13295
+ },
13296
+ components: {},
13297
+ tags: [],
13298
+ };
13299
+ /**
13300
+ * Note: [💞] Ignore a discrepancy between file name and entity name
13301
+ */
13302
+
13111
13303
  /**
13112
13304
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
13113
13305
  *
@@ -13182,41 +13374,33 @@ function startRemoteServer(options) {
13182
13374
  response.setHeader('X-Powered-By', 'Promptbook engine');
13183
13375
  next();
13184
13376
  });
13185
- const swaggerOptions = {
13186
- definition: {
13187
- openapi: '3.0.0',
13188
- info: {
13189
- title: 'Promptbook Remote Server API',
13190
- version: '1.0.0',
13191
- description: 'API documentation for the Promptbook Remote Server',
13192
- },
13193
- /*
13194
- TODO:
13195
- servers: [
13196
- {
13197
- url: `http://localhost:${port}${rootPath}`,
13198
- // <- TODO: Pass some public URLs here
13199
- },
13200
- ],
13201
- */
13377
+ // TODO: !!! Expose openapiJson to consumer and also allow to add new routes
13378
+ app.use(OpenApiValidator.middleware({
13379
+ apiSpec: openapiJson,
13380
+ // TODO: !!! Adjust
13381
+ ignorePaths(...args) {
13382
+ console.warn(`!!! Ignoring paths`, ...args);
13383
+ return true;
13202
13384
  },
13203
- apis: ['./src/remote-server/**/*.ts'], // Adjust path as needed
13204
- };
13205
- const swaggerSpec = swaggerJsdoc(swaggerOptions);
13206
- app.use(`/api-docs`, swaggerUi.serve, swaggerUi.setup(swaggerSpec));
13385
+ // TODO: !!! Validate both
13386
+ validateRequests: false,
13387
+ validateResponses: false, // false by default
13388
+ }));
13389
+ app.use([`/api-docs`, `/swagger`], swaggerUi.serve, swaggerUi.setup(openapiJson, {
13390
+ // customCss: '.swagger-ui .topbar { display: none }',
13391
+ // customSiteTitle: 'BRJ API',
13392
+ // customfavIcon: 'https://brj.app/favicon.ico',
13393
+ }));
13394
+ app.get(`/openapi`, (request, response) => {
13395
+ response.json(openapiJson);
13396
+ });
13397
+ // TODO: !!! Remove:
13398
+ app.get(`/xxx`, (request, response) => {
13399
+ response.json(openapiJson);
13400
+ });
13207
13401
  const runningExecutionTasks = [];
13208
13402
  // <- TODO: [🤬] Identify the users
13209
13403
  // TODO: [🧠] Do here some garbage collection of finished tasks
13210
- /**
13211
- * @swagger
13212
- * /:
13213
- * get:
13214
- * summary: Get server details
13215
- * description: Returns details about the Promptbook server.
13216
- * responses:
13217
- * 200:
13218
- * description: Server details in markdown format.
13219
- */
13220
13404
  app.get('/', async (request, response) => {
13221
13405
  var _a;
13222
13406
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
@@ -13274,37 +13458,6 @@ function startRemoteServer(options) {
13274
13458
  https://github.com/webgptorg/promptbook
13275
13459
  `));
13276
13460
  });
13277
- /**
13278
- * @swagger
13279
- *
13280
- * /login:
13281
- * post:
13282
- * summary: Login to the server
13283
- * description: Login to the server and get identification.
13284
- * requestBody:
13285
- * required: true
13286
- * content:
13287
- * application/json:
13288
- * schema:
13289
- * type: object
13290
- * properties:
13291
- * username:
13292
- * type: string
13293
- * password:
13294
- * type: string
13295
- * appId:
13296
- * type: string
13297
- * responses:
13298
- * 200:
13299
- * description: Successful login
13300
- * content:
13301
- * application/json:
13302
- * schema:
13303
- * type: object
13304
- * properties:
13305
- * identification:
13306
- * type: object
13307
- */
13308
13461
  app.post(`/login`, async (request, response) => {
13309
13462
  if (!isApplicationModeAllowed || login === null) {
13310
13463
  response.status(400).send('Application mode is not allowed');
@@ -13345,22 +13498,6 @@ function startRemoteServer(options) {
13345
13498
  response.status(400).send({ error: serializeError(error) });
13346
13499
  }
13347
13500
  });
13348
- /**
13349
- * @swagger
13350
- * /books:
13351
- * get:
13352
- * summary: List all books
13353
- * description: Returns a list of all available books in the collection.
13354
- * responses:
13355
- * 200:
13356
- * description: A list of books.
13357
- * content:
13358
- * application/json:
13359
- * schema:
13360
- * type: array
13361
- * items:
13362
- * type: string
13363
- */
13364
13501
  app.get(`/books`, async (request, response) => {
13365
13502
  if (collection === null) {
13366
13503
  response.status(500).send('No collection available');
@@ -13371,29 +13508,6 @@ function startRemoteServer(options) {
13371
13508
  response.send(pipelines);
13372
13509
  });
13373
13510
  // TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
13374
- /**
13375
- * @swagger
13376
- * /books/{bookId}:
13377
- * get:
13378
- * summary: Get book content
13379
- * description: Returns the content of a specific book.
13380
- * parameters:
13381
- * - in: path
13382
- * name: bookId
13383
- * required: true
13384
- * schema:
13385
- * type: string
13386
- * description: The ID of the book to retrieve.
13387
- * responses:
13388
- * 200:
13389
- * description: The content of the book.
13390
- * content:
13391
- * text/markdown:
13392
- * schema:
13393
- * type: string
13394
- * 404:
13395
- * description: Book not found.
13396
- */
13397
13511
  app.get(`/books/*`, async (request, response) => {
13398
13512
  try {
13399
13513
  if (collection === null) {
@@ -13446,22 +13560,6 @@ function startRemoteServer(options) {
13446
13560
  };
13447
13561
  }
13448
13562
  }
13449
- /**
13450
- * @swagger
13451
- * /executions:
13452
- * get:
13453
- * summary: List all executions
13454
- * description: Returns a list of all running execution tasks.
13455
- * responses:
13456
- * 200:
13457
- * description: A list of execution tasks.
13458
- * content:
13459
- * application/json:
13460
- * schema:
13461
- * type: array
13462
- * items:
13463
- * type: object
13464
- */
13465
13563
  app.get(`/executions`, async (request, response) => {
13466
13564
  response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
13467
13565
  });
@@ -13486,35 +13584,6 @@ function startRemoteServer(options) {
13486
13584
  }
13487
13585
  response.send(exportExecutionTask(executionTask, true));
13488
13586
  });
13489
- /**
13490
- * @swagger
13491
- * /executions/new:
13492
- * post:
13493
- * summary: Start a new execution
13494
- * description: Starts a new execution task for a given pipeline.
13495
- * requestBody:
13496
- * required: true
13497
- * content:
13498
- * application/json:
13499
- * schema:
13500
- * type: object
13501
- * properties:
13502
- * pipelineUrl:
13503
- * type: string
13504
- * inputParameters:
13505
- * type: object
13506
- * identification:
13507
- * type: object
13508
- * responses:
13509
- * 200:
13510
- * description: The newly created execution task.
13511
- * content:
13512
- * application/json:
13513
- * schema:
13514
- * type: object
13515
- * 400:
13516
- * description: Invalid input.
13517
- */
13518
13587
  app.post(`/executions/new`, async (request, response) => {
13519
13588
  try {
13520
13589
  const { inputParameters, identification /* <- [🤬] */ } = request.body;