@promptbook/remote-server 0.102.0-0 → 0.102.0-2

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
@@ -16,6 +16,8 @@ import sha256 from 'crypto-js/sha256';
16
16
  import { SHA256 } from 'crypto-js';
17
17
  import { lookup, extension } from 'mime-types';
18
18
  import { parse, unparse } from 'papaparse';
19
+ import { createElement } from 'react';
20
+ import { renderToStaticMarkup } from 'react-dom/server';
19
21
 
20
22
  // ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
21
23
  /**
@@ -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.102.0-0';
36
+ const PROMPTBOOK_ENGINE_VERSION = '0.102.0-2';
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
@@ -8090,6 +8092,44 @@ const openapiJson = {
8090
8092
  * Note: [💞] Ignore a discrepancy between file name and entity name
8091
8093
  */
8092
8094
 
8095
+ const h = createElement;
8096
+ function KeyVal(props) {
8097
+ return h('div', { className: 'flex items-start gap-2' }, h('div', { className: 'font-semibold min-w-[14rem]' }, props.label), h('div', { className: 'text-gray-800' }, props.value));
8098
+ }
8099
+ function List(props) {
8100
+ var _a;
8101
+ if (!((_a = props.items) === null || _a === void 0 ? void 0 : _a.length))
8102
+ return h('span', { className: 'text-gray-500' }, 'none');
8103
+ return h('ul', { className: 'list-disc ml-6' }, ...props.items.map((item, i) => h('li', { key: String(i), className: 'break-all' }, item)));
8104
+ }
8105
+ function Section(props) {
8106
+ return h('section', { className: 'mt-8' }, h('h2', { className: 'text-xl font-semibold mb-2' }, props.title), props.children);
8107
+ }
8108
+ function ServerBody({ info }) {
8109
+ var _a;
8110
+ return h('div', { className: 'max-w-4xl mx-auto p-6' }, h('h1', { className: 'text-3xl font-bold mb-4' }, 'Promptbook Server'), h('div', { className: 'space-y-2' }, h(KeyVal, { label: 'Book language version:', value: info.bookLanguageVersion }), h(KeyVal, { label: 'Promptbook engine version:', value: info.promptbookEngineVersion }), h(KeyVal, { label: 'Node.js version:', value: info.nodeVersion }), h(KeyVal, { label: 'Server port:', value: String((_a = info.port) !== null && _a !== void 0 ? _a : '') }), h(KeyVal, { label: 'Startup date:', value: info.startupDate }), h(KeyVal, {
8111
+ label: 'Anonymous mode:',
8112
+ value: info.isAnonymousModeAllowed ? 'enabled' : 'disabled',
8113
+ }), h(KeyVal, {
8114
+ label: 'Application mode:',
8115
+ value: info.isApplicationModeAllowed ? 'enabled' : 'disabled',
8116
+ }), h(KeyVal, { label: 'Running executions:', value: String(info.runningExecutions) })), h(Section, { title: 'Pipelines in collection' }, h(List, { items: info.pipelines })), h(Section, { title: 'Paths' }, h(List, { items: info.paths })), h(Section, { title: 'Instructions' }, h('ol', { className: 'list-decimal ml-6 space-y-1' }, h('li', null, 'The client ', h('a', { href: 'https://www.npmjs.com/package/@promptbook/remote-client', className: 'text-blue-600 underline' }, 'https://www.npmjs.com/package/@promptbook/remote-client')), h('li', null, 'OpenAI compatible client ', h('span', { className: 'text-gray-500' }, '(Not working yet)')), h('li', null, 'REST API')), h('p', { className: 'mt-2' }, 'For more information look at: ', h('a', { href: 'https://github.com/webgptorg/promptbook', className: 'text-blue-600 underline' }, 'https://github.com/webgptorg/promptbook'))));
8117
+ }
8118
+ function HtmlDoc({ info }) {
8119
+ return h('html', { lang: 'en' }, h('head', null, h('meta', { charSet: 'UTF-8' }), h('meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0' }), h('title', null, 'Promptbook Server'), h('link', {
8120
+ href: 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css',
8121
+ rel: 'stylesheet',
8122
+ })), h('body', { className: 'bg-gray-50 text-gray-900' }, h('div', { id: 'root' }, h(ServerBody, { info }))));
8123
+ }
8124
+ /**
8125
+ * Render full HTML for the server index using React SSR without requiring TSX/JSX compiler flags.
8126
+ *
8127
+ * @private internal utility of Remote Server
8128
+ */
8129
+ function renderServerIndexHtml(info) {
8130
+ return '<!DOCTYPE html>' + renderToStaticMarkup(h(HtmlDoc, { info }));
8131
+ }
8132
+
8093
8133
  /**
8094
8134
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
8095
8135
  *
@@ -8246,57 +8286,82 @@ function startRemoteServer(options) {
8246
8286
  if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
8247
8287
  return;
8248
8288
  }
8249
- response.type('text/markdown').send(await spaceTrim$1(async (block) => `
8250
- # Promptbook
8289
+ if (options.isRichUi !== false) {
8290
+ // Serve rich React + Tailwind UI with server info injected
8291
+ const serverInfo = {
8292
+ bookLanguageVersion: BOOK_LANGUAGE_VERSION,
8293
+ promptbookEngineVersion: PROMPTBOOK_ENGINE_VERSION,
8294
+ nodeVersion: process.version,
8295
+ port,
8296
+ startupDate: startupDate.toISOString(),
8297
+ isAnonymousModeAllowed,
8298
+ isApplicationModeAllowed,
8299
+ pipelines: !isApplicationModeAllowed || collection === null
8300
+ ? []
8301
+ : await collection.listPipelines(),
8302
+ runningExecutions: runningExecutionTasks.length,
8303
+ paths: [
8304
+ ...app._router.stack
8305
+ .map(({ route }) => (route === null || route === void 0 ? void 0 : route.path) || null)
8306
+ .filter((path) => path !== null),
8307
+ '/api-docs',
8308
+ ],
8309
+ };
8310
+ response.type('text/html').send(renderServerIndexHtml(serverInfo));
8311
+ }
8312
+ else {
8313
+ response.type('text/markdown').send(await spaceTrim$1(async (block) => `
8314
+ # Promptbook
8251
8315
 
8252
- > ${block(CLAIM)}
8316
+ > ${block(CLAIM)}
8253
8317
 
8254
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
8255
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
8256
- **Node.js version:** ${process.version /* <- TODO: [🧠] Is it secure to expose this */}
8318
+ **Book language version:** ${BOOK_LANGUAGE_VERSION}
8319
+ **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
8320
+ **Node.js version:** ${process.version /* <- TODO: [🧠] Is it secure to expose this */}
8257
8321
 
8258
- ---
8322
+ ---
8259
8323
 
8260
- ## Details
8324
+ ## Details
8261
8325
 
8262
- **Server port:** ${port}
8263
- **Startup date:** ${startupDate.toISOString()}
8264
- **Anonymous mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
8265
- **Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
8266
- ${block(!isApplicationModeAllowed || collection === null
8267
- ? ''
8268
- : '**Pipelines in collection:**\n' +
8269
- (await collection.listPipelines())
8270
- .map((pipelineUrl) => `- ${pipelineUrl}`)
8271
- .join('\n'))}
8272
- **Running executions:** ${runningExecutionTasks.length}
8326
+ **Server port:** ${port}
8327
+ **Startup date:** ${startupDate.toISOString()}
8328
+ **Anonymous mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
8329
+ **Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
8330
+ ${block(!isApplicationModeAllowed || collection === null
8331
+ ? ''
8332
+ : '**Pipelines in collection:**\n' +
8333
+ (await collection.listPipelines())
8334
+ .map((pipelineUrl) => `- ${pipelineUrl}`)
8335
+ .join('\n'))}
8336
+ **Running executions:** ${runningExecutionTasks.length}
8273
8337
 
8274
- ---
8338
+ ---
8275
8339
 
8276
- ## Paths
8340
+ ## Paths
8277
8341
 
8278
- ${block([
8279
- ...app._router.stack
8280
- .map(({ route }) => (route === null || route === void 0 ? void 0 : route.path) || null)
8281
- .filter((path) => path !== null),
8282
- '/api-docs',
8283
- ]
8284
- .map((path) => `- ${path}`)
8285
- .join('\n'))}
8342
+ ${block([
8343
+ ...app._router.stack
8344
+ .map(({ route }) => (route === null || route === void 0 ? void 0 : route.path) || null)
8345
+ .filter((path) => path !== null),
8346
+ '/api-docs',
8347
+ ]
8348
+ .map((path) => `- ${path}`)
8349
+ .join('\n'))}
8286
8350
 
8287
- ---
8351
+ ---
8288
8352
 
8289
- ## Instructions
8353
+ ## Instructions
8290
8354
 
8291
- To connect to this server use:
8355
+ To connect to this server use:
8292
8356
 
8293
- 1) The client https://www.npmjs.com/package/@promptbook/remote-client
8294
- 2) OpenAI compatible client *(Not working yet)*
8295
- 3) REST API
8357
+ 1) The client https://www.npmjs.com/package/@promptbook/remote-client
8358
+ 2) OpenAI compatible client *(Not working yet)*
8359
+ 3) REST API
8296
8360
 
8297
- For more information look at:
8298
- https://github.com/webgptorg/promptbook
8299
- `));
8361
+ For more information look at:
8362
+ https://github.com/webgptorg/promptbook
8363
+ `));
8364
+ }
8300
8365
  });
8301
8366
  app.post(`/login`, async (request, response) => {
8302
8367
  if (!isApplicationModeAllowed || login === null) {