@promptbook/remote-server 0.89.0-3 → 0.89.0-31
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/README.md +9 -7
- package/esm/index.es.js +593 -267
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +20 -8
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -12
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +24 -26
- package/esm/typings/src/errors/0-index.d.ts +9 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +19 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +11 -5
- package/umd/index.umd.js +515 -171
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/umd/index.umd.js
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
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('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', '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.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, 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);
|
|
31
|
+
var OpenApiValidator__namespace = /*#__PURE__*/_interopNamespace(OpenApiValidator);
|
|
32
|
+
var swaggerUi__default = /*#__PURE__*/_interopDefaultLegacy(swaggerUi);
|
|
13
33
|
var parserHtml__default = /*#__PURE__*/_interopDefaultLegacy(parserHtml);
|
|
14
34
|
var hexEncoder__default = /*#__PURE__*/_interopDefaultLegacy(hexEncoder);
|
|
15
35
|
var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
|
|
@@ -28,7 +48,7 @@
|
|
|
28
48
|
* @generated
|
|
29
49
|
* @see https://github.com/webgptorg/promptbook
|
|
30
50
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-31';
|
|
32
52
|
/**
|
|
33
53
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
54
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -82,6 +102,7 @@
|
|
|
82
102
|
* @public exported from `@promptbook/core`
|
|
83
103
|
*/
|
|
84
104
|
const CLAIM = `It's time for a paradigm shift. The future of software in plain English, French or Latin`;
|
|
105
|
+
// <- TODO: [🐊] Pick the best claim
|
|
85
106
|
/**
|
|
86
107
|
* When the title is not provided, the default title is used
|
|
87
108
|
*
|
|
@@ -114,6 +135,7 @@
|
|
|
114
135
|
infinity: '(infinity; ∞)',
|
|
115
136
|
negativeInfinity: '(negative infinity; -∞)',
|
|
116
137
|
unserializable: '(unserializable value)',
|
|
138
|
+
circular: '(circular JSON)',
|
|
117
139
|
};
|
|
118
140
|
/**
|
|
119
141
|
* Small number limit
|
|
@@ -153,6 +175,7 @@
|
|
|
153
175
|
*/
|
|
154
176
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
155
177
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
178
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
156
179
|
/**
|
|
157
180
|
* Where to store the temporary downloads
|
|
158
181
|
*
|
|
@@ -204,8 +227,137 @@
|
|
|
204
227
|
true);
|
|
205
228
|
/**
|
|
206
229
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
207
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
230
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Make error report URL for the given error
|
|
235
|
+
*
|
|
236
|
+
* @private private within the repository
|
|
237
|
+
*/
|
|
238
|
+
function getErrorReportUrl(error) {
|
|
239
|
+
const report = {
|
|
240
|
+
title: `🐜 Error report from ${NAME}`,
|
|
241
|
+
body: spaceTrim__default["default"]((block) => `
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
245
|
+
|
|
246
|
+
\`\`\`
|
|
247
|
+
${block(error.message || '(no error message)')}
|
|
248
|
+
\`\`\`
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
## More info:
|
|
252
|
+
|
|
253
|
+
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
254
|
+
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
255
|
+
- **Time:** ${new Date().toISOString()}
|
|
256
|
+
|
|
257
|
+
<details>
|
|
258
|
+
<summary>Stack trace:</summary>
|
|
259
|
+
|
|
260
|
+
## Stack trace:
|
|
261
|
+
|
|
262
|
+
\`\`\`stacktrace
|
|
263
|
+
${block(error.stack || '(empty)')}
|
|
264
|
+
\`\`\`
|
|
265
|
+
</details>
|
|
266
|
+
|
|
267
|
+
`),
|
|
268
|
+
};
|
|
269
|
+
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
270
|
+
reportUrl.searchParams.set('labels', 'bug');
|
|
271
|
+
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
272
|
+
reportUrl.searchParams.set('title', report.title);
|
|
273
|
+
reportUrl.searchParams.set('body', report.body);
|
|
274
|
+
return reportUrl;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
279
|
+
*
|
|
280
|
+
* @public exported from `@promptbook/core`
|
|
281
|
+
*/
|
|
282
|
+
class UnexpectedError extends Error {
|
|
283
|
+
constructor(message) {
|
|
284
|
+
super(spaceTrim.spaceTrim((block) => `
|
|
285
|
+
${block(message)}
|
|
286
|
+
|
|
287
|
+
Note: This error should not happen.
|
|
288
|
+
It's probbably a bug in the pipeline collection
|
|
289
|
+
|
|
290
|
+
Please report issue:
|
|
291
|
+
${block(getErrorReportUrl(new Error(message)).href)}
|
|
292
|
+
|
|
293
|
+
Or contact us on ${ADMIN_EMAIL}
|
|
294
|
+
|
|
295
|
+
`));
|
|
296
|
+
this.name = 'UnexpectedError';
|
|
297
|
+
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
303
|
+
*
|
|
304
|
+
* @public exported from `@promptbook/core`
|
|
305
|
+
*/
|
|
306
|
+
class WrappedError extends Error {
|
|
307
|
+
constructor(whatWasThrown) {
|
|
308
|
+
const tag = `[🤮]`;
|
|
309
|
+
console.error(tag, whatWasThrown);
|
|
310
|
+
super(spaceTrim.spaceTrim(`
|
|
311
|
+
Non-Error object was thrown
|
|
312
|
+
|
|
313
|
+
Note: Look for ${tag} in the console for more details
|
|
314
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
315
|
+
`));
|
|
316
|
+
this.name = 'WrappedError';
|
|
317
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
323
|
+
*
|
|
324
|
+
* @param whatWasThrown Any object that was thrown
|
|
325
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
326
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
327
|
+
*
|
|
328
|
+
* @private within the repository
|
|
329
|
+
*/
|
|
330
|
+
function assertsError(whatWasThrown) {
|
|
331
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
332
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
333
|
+
const wrappedError = whatWasThrown;
|
|
334
|
+
throw wrappedError;
|
|
335
|
+
}
|
|
336
|
+
// Case 2: Handle unexpected errors
|
|
337
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
338
|
+
const unexpectedError = whatWasThrown;
|
|
339
|
+
throw unexpectedError;
|
|
340
|
+
}
|
|
341
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
342
|
+
if (whatWasThrown instanceof Error) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
346
|
+
throw new WrappedError(whatWasThrown);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
351
|
+
*
|
|
352
|
+
* @public exported from `@promptbook/core`
|
|
208
353
|
*/
|
|
354
|
+
class AuthenticationError extends Error {
|
|
355
|
+
constructor(message) {
|
|
356
|
+
super(message);
|
|
357
|
+
this.name = 'AuthenticationError';
|
|
358
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
209
361
|
|
|
210
362
|
/**
|
|
211
363
|
* Generates random token
|
|
@@ -238,7 +390,7 @@
|
|
|
238
390
|
}
|
|
239
391
|
}
|
|
240
392
|
/**
|
|
241
|
-
* TODO:
|
|
393
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
242
394
|
*/
|
|
243
395
|
|
|
244
396
|
/**
|
|
@@ -436,70 +588,15 @@
|
|
|
436
588
|
}
|
|
437
589
|
|
|
438
590
|
/**
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
* @private private within the repository
|
|
442
|
-
*/
|
|
443
|
-
function getErrorReportUrl(error) {
|
|
444
|
-
const report = {
|
|
445
|
-
title: `🐜 Error report from ${NAME}`,
|
|
446
|
-
body: spaceTrim__default["default"]((block) => `
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
\`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
|
|
450
|
-
|
|
451
|
-
\`\`\`
|
|
452
|
-
${block(error.message || '(no error message)')}
|
|
453
|
-
\`\`\`
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
## More info:
|
|
457
|
-
|
|
458
|
-
- **Promptbook engine version:** ${PROMPTBOOK_ENGINE_VERSION}
|
|
459
|
-
- **Book language version:** ${BOOK_LANGUAGE_VERSION}
|
|
460
|
-
- **Time:** ${new Date().toISOString()}
|
|
461
|
-
|
|
462
|
-
<details>
|
|
463
|
-
<summary>Stack trace:</summary>
|
|
464
|
-
|
|
465
|
-
## Stack trace:
|
|
466
|
-
|
|
467
|
-
\`\`\`stacktrace
|
|
468
|
-
${block(error.stack || '(empty)')}
|
|
469
|
-
\`\`\`
|
|
470
|
-
</details>
|
|
471
|
-
|
|
472
|
-
`),
|
|
473
|
-
};
|
|
474
|
-
const reportUrl = new URL(`https://github.com/webgptorg/promptbook/issues/new`);
|
|
475
|
-
reportUrl.searchParams.set('labels', 'bug');
|
|
476
|
-
reportUrl.searchParams.set('assignees', ADMIN_GITHUB_NAME);
|
|
477
|
-
reportUrl.searchParams.set('title', report.title);
|
|
478
|
-
reportUrl.searchParams.set('body', report.body);
|
|
479
|
-
return reportUrl;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* This error type indicates that the error should not happen and its last check before crashing with some other error
|
|
591
|
+
* Error thrown when a fetch request fails
|
|
484
592
|
*
|
|
485
593
|
* @public exported from `@promptbook/core`
|
|
486
594
|
*/
|
|
487
|
-
class
|
|
595
|
+
class PromptbookFetchError extends Error {
|
|
488
596
|
constructor(message) {
|
|
489
|
-
super(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
Note: This error should not happen.
|
|
493
|
-
It's probbably a bug in the pipeline collection
|
|
494
|
-
|
|
495
|
-
Please report issue:
|
|
496
|
-
${block(getErrorReportUrl(new Error(message)).href)}
|
|
497
|
-
|
|
498
|
-
Or contact us on ${ADMIN_EMAIL}
|
|
499
|
-
|
|
500
|
-
`));
|
|
501
|
-
this.name = 'UnexpectedError';
|
|
502
|
-
Object.setPrototypeOf(this, UnexpectedError.prototype);
|
|
597
|
+
super(message);
|
|
598
|
+
this.name = 'PromptbookFetchError';
|
|
599
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
503
600
|
}
|
|
504
601
|
}
|
|
505
602
|
|
|
@@ -523,7 +620,10 @@
|
|
|
523
620
|
PipelineExecutionError,
|
|
524
621
|
PipelineLogicError,
|
|
525
622
|
PipelineUrlError,
|
|
623
|
+
AuthenticationError,
|
|
624
|
+
PromptbookFetchError,
|
|
526
625
|
UnexpectedError,
|
|
626
|
+
WrappedError,
|
|
527
627
|
// TODO: [🪑]> VersionMismatchError,
|
|
528
628
|
};
|
|
529
629
|
/**
|
|
@@ -575,6 +675,10 @@
|
|
|
575
675
|
|
|
576
676
|
Cannot serialize error with name "${name}"
|
|
577
677
|
|
|
678
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
679
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
680
|
+
|
|
681
|
+
|
|
578
682
|
${block(stack || message)}
|
|
579
683
|
|
|
580
684
|
`));
|
|
@@ -778,9 +882,7 @@
|
|
|
778
882
|
return result.trim();
|
|
779
883
|
}
|
|
780
884
|
catch (error) {
|
|
781
|
-
|
|
782
|
-
throw error;
|
|
783
|
-
}
|
|
885
|
+
assertsError(error);
|
|
784
886
|
return null;
|
|
785
887
|
}
|
|
786
888
|
}
|
|
@@ -858,9 +960,7 @@
|
|
|
858
960
|
return result.trim() + toExec;
|
|
859
961
|
}
|
|
860
962
|
catch (error) {
|
|
861
|
-
|
|
862
|
-
throw error;
|
|
863
|
-
}
|
|
963
|
+
assertsError(error);
|
|
864
964
|
return null;
|
|
865
965
|
}
|
|
866
966
|
}
|
|
@@ -891,9 +991,7 @@
|
|
|
891
991
|
throw new Error(`Can not locate app ${appName} on Windows.`);
|
|
892
992
|
}
|
|
893
993
|
catch (error) {
|
|
894
|
-
|
|
895
|
-
throw error;
|
|
896
|
-
}
|
|
994
|
+
assertsError(error);
|
|
897
995
|
return null;
|
|
898
996
|
}
|
|
899
997
|
}
|
|
@@ -1131,9 +1229,7 @@
|
|
|
1131
1229
|
JSON.stringify(value); // <- TODO: [0]
|
|
1132
1230
|
}
|
|
1133
1231
|
catch (error) {
|
|
1134
|
-
|
|
1135
|
-
throw error;
|
|
1136
|
-
}
|
|
1232
|
+
assertsError(error);
|
|
1137
1233
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
1138
1234
|
\`${name}\` is not serializable
|
|
1139
1235
|
|
|
@@ -1741,9 +1837,7 @@
|
|
|
1741
1837
|
return true;
|
|
1742
1838
|
}
|
|
1743
1839
|
catch (error) {
|
|
1744
|
-
|
|
1745
|
-
throw error;
|
|
1746
|
-
}
|
|
1840
|
+
assertsError(error);
|
|
1747
1841
|
if (error.message.includes('Unexpected token')) {
|
|
1748
1842
|
return false;
|
|
1749
1843
|
}
|
|
@@ -1881,8 +1975,8 @@
|
|
|
1881
1975
|
updatedAt = new Date();
|
|
1882
1976
|
errors.push(...executionResult.errors);
|
|
1883
1977
|
warnings.push(...executionResult.warnings);
|
|
1884
|
-
// <- TODO:
|
|
1885
|
-
// TODO: [🧠]
|
|
1978
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
1979
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1886
1980
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1887
1981
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1888
1982
|
assertsTaskSuccessful(executionResult);
|
|
@@ -1892,6 +1986,7 @@
|
|
|
1892
1986
|
partialResultSubject.next(executionResult);
|
|
1893
1987
|
}
|
|
1894
1988
|
catch (error) {
|
|
1989
|
+
assertsError(error);
|
|
1895
1990
|
status = 'ERROR';
|
|
1896
1991
|
errors.push(error);
|
|
1897
1992
|
partialResultSubject.error(error);
|
|
@@ -2702,14 +2797,15 @@
|
|
|
2702
2797
|
}
|
|
2703
2798
|
}
|
|
2704
2799
|
catch (error) {
|
|
2705
|
-
|
|
2800
|
+
assertsError(error);
|
|
2801
|
+
if (error instanceof UnexpectedError) {
|
|
2706
2802
|
throw error;
|
|
2707
2803
|
}
|
|
2708
2804
|
errors.push({ llmExecutionTools, error });
|
|
2709
2805
|
}
|
|
2710
2806
|
}
|
|
2711
2807
|
if (errors.length === 1) {
|
|
2712
|
-
throw errors[0];
|
|
2808
|
+
throw errors[0].error;
|
|
2713
2809
|
}
|
|
2714
2810
|
else if (errors.length > 1) {
|
|
2715
2811
|
throw new PipelineExecutionError(
|
|
@@ -3543,17 +3639,22 @@
|
|
|
3543
3639
|
/**
|
|
3544
3640
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3545
3641
|
*
|
|
3546
|
-
* @
|
|
3642
|
+
* @public exported from `@promptbook/core`
|
|
3547
3643
|
*/
|
|
3548
|
-
const
|
|
3644
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3549
3645
|
try {
|
|
3550
|
-
return await fetch(
|
|
3646
|
+
return await fetch(urlOrRequest, init);
|
|
3551
3647
|
}
|
|
3552
3648
|
catch (error) {
|
|
3553
|
-
|
|
3554
|
-
|
|
3649
|
+
assertsError(error);
|
|
3650
|
+
let url;
|
|
3651
|
+
if (typeof urlOrRequest === 'string') {
|
|
3652
|
+
url = urlOrRequest;
|
|
3653
|
+
}
|
|
3654
|
+
else if (urlOrRequest instanceof Request) {
|
|
3655
|
+
url = urlOrRequest.url;
|
|
3555
3656
|
}
|
|
3556
|
-
throw new
|
|
3657
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
3557
3658
|
Can not fetch "${url}"
|
|
3558
3659
|
|
|
3559
3660
|
Fetch error:
|
|
@@ -3574,7 +3675,7 @@
|
|
|
3574
3675
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3575
3676
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3576
3677
|
var _a;
|
|
3577
|
-
const { fetch =
|
|
3678
|
+
const { fetch = promptbookFetch } = tools;
|
|
3578
3679
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3579
3680
|
let { name } = knowledgeSource;
|
|
3580
3681
|
const { rootDirname = null,
|
|
@@ -3776,9 +3877,7 @@
|
|
|
3776
3877
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3777
3878
|
}
|
|
3778
3879
|
catch (error) {
|
|
3779
|
-
|
|
3780
|
-
throw error;
|
|
3781
|
-
}
|
|
3880
|
+
assertsError(error);
|
|
3782
3881
|
console.warn(error);
|
|
3783
3882
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3784
3883
|
}
|
|
@@ -4070,13 +4169,19 @@
|
|
|
4070
4169
|
return value.toISOString();
|
|
4071
4170
|
}
|
|
4072
4171
|
else {
|
|
4073
|
-
|
|
4172
|
+
try {
|
|
4173
|
+
return JSON.stringify(value);
|
|
4174
|
+
}
|
|
4175
|
+
catch (error) {
|
|
4176
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
4177
|
+
return VALUE_STRINGS.circular;
|
|
4178
|
+
}
|
|
4179
|
+
throw error;
|
|
4180
|
+
}
|
|
4074
4181
|
}
|
|
4075
4182
|
}
|
|
4076
4183
|
catch (error) {
|
|
4077
|
-
|
|
4078
|
-
throw error;
|
|
4079
|
-
}
|
|
4184
|
+
assertsError(error);
|
|
4080
4185
|
console.error(error);
|
|
4081
4186
|
return VALUE_STRINGS.unserializable;
|
|
4082
4187
|
}
|
|
@@ -4133,9 +4238,7 @@
|
|
|
4133
4238
|
}
|
|
4134
4239
|
}
|
|
4135
4240
|
catch (error) {
|
|
4136
|
-
|
|
4137
|
-
throw error;
|
|
4138
|
-
}
|
|
4241
|
+
assertsError(error);
|
|
4139
4242
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4140
4243
|
Can not extract variables from the script
|
|
4141
4244
|
${block(error.stack || error.message)}
|
|
@@ -5017,9 +5120,7 @@
|
|
|
5017
5120
|
break scripts;
|
|
5018
5121
|
}
|
|
5019
5122
|
catch (error) {
|
|
5020
|
-
|
|
5021
|
-
throw error;
|
|
5022
|
-
}
|
|
5123
|
+
assertsError(error);
|
|
5023
5124
|
if (error instanceof UnexpectedError) {
|
|
5024
5125
|
throw error;
|
|
5025
5126
|
}
|
|
@@ -5089,9 +5190,7 @@
|
|
|
5089
5190
|
break scripts;
|
|
5090
5191
|
}
|
|
5091
5192
|
catch (error) {
|
|
5092
|
-
|
|
5093
|
-
throw error;
|
|
5094
|
-
}
|
|
5193
|
+
assertsError(error);
|
|
5095
5194
|
if (error instanceof UnexpectedError) {
|
|
5096
5195
|
throw error;
|
|
5097
5196
|
}
|
|
@@ -5712,9 +5811,7 @@
|
|
|
5712
5811
|
await Promise.all(resolving);
|
|
5713
5812
|
}
|
|
5714
5813
|
catch (error /* <- Note: [3] */) {
|
|
5715
|
-
|
|
5716
|
-
throw error;
|
|
5717
|
-
}
|
|
5814
|
+
assertsError(error);
|
|
5718
5815
|
// Note: No need to rethrow UnexpectedError
|
|
5719
5816
|
// if (error instanceof UnexpectedError) {
|
|
5720
5817
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -6616,9 +6713,7 @@
|
|
|
6616
6713
|
}
|
|
6617
6714
|
}
|
|
6618
6715
|
catch (error) {
|
|
6619
|
-
|
|
6620
|
-
throw error;
|
|
6621
|
-
}
|
|
6716
|
+
assertsError(error);
|
|
6622
6717
|
if (error instanceof ReferenceError) {
|
|
6623
6718
|
const undefinedName = error.message.split(' ')[0];
|
|
6624
6719
|
/*
|
|
@@ -6698,6 +6793,198 @@
|
|
|
6698
6793
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
6699
6794
|
*/
|
|
6700
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
|
+
|
|
6701
6988
|
/**
|
|
6702
6989
|
* Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
|
|
6703
6990
|
*
|
|
@@ -6708,29 +6995,14 @@
|
|
|
6708
6995
|
* @public exported from `@promptbook/remote-server`
|
|
6709
6996
|
*/
|
|
6710
6997
|
function startRemoteServer(options) {
|
|
6711
|
-
const { port, collection, createLlmExecutionTools, isAnonymousModeAllowed, isApplicationModeAllowed, isVerbose = DEFAULT_IS_VERBOSE, } = {
|
|
6998
|
+
const { port, collection, createLlmExecutionTools, createExecutionTools, isAnonymousModeAllowed, isApplicationModeAllowed, isVerbose = DEFAULT_IS_VERBOSE, login, } = {
|
|
6712
6999
|
isAnonymousModeAllowed: false,
|
|
6713
7000
|
isApplicationModeAllowed: false,
|
|
6714
7001
|
collection: null,
|
|
6715
7002
|
createLlmExecutionTools: null,
|
|
7003
|
+
login: null,
|
|
6716
7004
|
...options,
|
|
6717
7005
|
};
|
|
6718
|
-
// <- TODO: [🦪] Some helper type to be able to use discriminant union types with destructuring
|
|
6719
|
-
let { rootPath = '/' } = options;
|
|
6720
|
-
if (!rootPath.startsWith('/')) {
|
|
6721
|
-
rootPath = `/${rootPath}`;
|
|
6722
|
-
} /* not else */
|
|
6723
|
-
if (rootPath.endsWith('/')) {
|
|
6724
|
-
rootPath = rootPath.slice(0, -1);
|
|
6725
|
-
} /* not else */
|
|
6726
|
-
if (rootPath === '/') {
|
|
6727
|
-
rootPath = '';
|
|
6728
|
-
}
|
|
6729
|
-
const socketioPath = '/' +
|
|
6730
|
-
`${rootPath}/socket.io`
|
|
6731
|
-
.split('/')
|
|
6732
|
-
.filter((part) => part !== '')
|
|
6733
|
-
.join('/');
|
|
6734
7006
|
const startupDate = new Date();
|
|
6735
7007
|
async function getExecutionToolsFromIdentification(identification) {
|
|
6736
7008
|
if (identification === null || identification === undefined) {
|
|
@@ -6755,6 +7027,7 @@
|
|
|
6755
7027
|
// Note: Application mode
|
|
6756
7028
|
const { appId, userId, customOptions } = identification;
|
|
6757
7029
|
llm = await createLlmExecutionTools({
|
|
7030
|
+
isAnonymous: false,
|
|
6758
7031
|
appId,
|
|
6759
7032
|
userId,
|
|
6760
7033
|
customOptions,
|
|
@@ -6763,13 +7036,20 @@
|
|
|
6763
7036
|
else {
|
|
6764
7037
|
throw new PipelineExecutionError(`You must provide either llmToolsConfiguration or non-anonymous mode must be propperly configured`);
|
|
6765
7038
|
}
|
|
6766
|
-
const
|
|
6767
|
-
const
|
|
7039
|
+
const customExecutionTools = createExecutionTools ? await createExecutionTools(identification) : {};
|
|
7040
|
+
const fs = customExecutionTools.fs || $provideFilesystemForNode();
|
|
7041
|
+
const executables = customExecutionTools.executables || (await $provideExecutablesForNode());
|
|
7042
|
+
const scrapers = customExecutionTools.scrapers || (await $provideScrapersForNode({ fs, llm, executables }));
|
|
7043
|
+
const script = customExecutionTools.script || (await $provideScriptingForNode({}));
|
|
7044
|
+
const fetch = customExecutionTools.fetch || promptbookFetch;
|
|
7045
|
+
const userInterface = customExecutionTools.userInterface || undefined;
|
|
6768
7046
|
const tools = {
|
|
6769
7047
|
llm,
|
|
6770
7048
|
fs,
|
|
6771
|
-
scrapers
|
|
6772
|
-
script
|
|
7049
|
+
scrapers,
|
|
7050
|
+
script,
|
|
7051
|
+
fetch,
|
|
7052
|
+
userInterface,
|
|
6773
7053
|
};
|
|
6774
7054
|
return tools;
|
|
6775
7055
|
}
|
|
@@ -6779,10 +7059,27 @@
|
|
|
6779
7059
|
response.setHeader('X-Powered-By', 'Promptbook engine');
|
|
6780
7060
|
next();
|
|
6781
7061
|
});
|
|
7062
|
+
// TODO: !!!! Expose openapiJson to consumer and also allow to add new routes
|
|
7063
|
+
app.use(OpenApiValidator__namespace.middleware({
|
|
7064
|
+
apiSpec: openapiJson,
|
|
7065
|
+
ignorePaths(path) {
|
|
7066
|
+
return path.startsWith('/api-docs') || path.startsWith('/swagger') || path.startsWith('/openapi');
|
|
7067
|
+
},
|
|
7068
|
+
validateRequests: true,
|
|
7069
|
+
validateResponses: true,
|
|
7070
|
+
}));
|
|
7071
|
+
app.use([`/api-docs`, `/swagger`], swaggerUi__default["default"].serve, swaggerUi__default["default"].setup(openapiJson, {
|
|
7072
|
+
// customCss: '.swagger-ui .topbar { display: none }',
|
|
7073
|
+
// customSiteTitle: 'BRJ API',
|
|
7074
|
+
// customfavIcon: 'https://brj.app/favicon.ico',
|
|
7075
|
+
}));
|
|
7076
|
+
app.get(`/openapi`, (request, response) => {
|
|
7077
|
+
response.json(openapiJson);
|
|
7078
|
+
});
|
|
6782
7079
|
const runningExecutionTasks = [];
|
|
6783
7080
|
// <- TODO: [🤬] Identify the users
|
|
6784
7081
|
// TODO: [🧠] Do here some garbage collection of finished tasks
|
|
6785
|
-
app.get(
|
|
7082
|
+
app.get('/', async (request, response) => {
|
|
6786
7083
|
var _a;
|
|
6787
7084
|
if ((_a = request.url) === null || _a === void 0 ? void 0 : _a.includes('socket.io')) {
|
|
6788
7085
|
return;
|
|
@@ -6801,8 +7098,6 @@
|
|
|
6801
7098
|
## Details
|
|
6802
7099
|
|
|
6803
7100
|
**Server port:** ${port}
|
|
6804
|
-
**Server root path:** ${rootPath}
|
|
6805
|
-
**Socket.io path:** ${socketioPath}
|
|
6806
7101
|
**Startup date:** ${startupDate.toISOString()}
|
|
6807
7102
|
**Anonymouse mode:** ${isAnonymousModeAllowed ? 'enabled' : 'disabled'}
|
|
6808
7103
|
**Application mode:** ${isApplicationModeAllowed ? 'enabled' : 'disabled'}
|
|
@@ -6818,9 +7113,12 @@
|
|
|
6818
7113
|
|
|
6819
7114
|
## Paths
|
|
6820
7115
|
|
|
6821
|
-
${block(
|
|
6822
|
-
.
|
|
6823
|
-
|
|
7116
|
+
${block([
|
|
7117
|
+
...app._router.stack
|
|
7118
|
+
.map(({ route }) => (route === null || route === void 0 ? void 0 : route.path) || null)
|
|
7119
|
+
.filter((path) => path !== null),
|
|
7120
|
+
'/api-docs',
|
|
7121
|
+
]
|
|
6824
7122
|
.map((path) => `- ${path}`)
|
|
6825
7123
|
.join('\n'))}
|
|
6826
7124
|
|
|
@@ -6838,8 +7136,47 @@
|
|
|
6838
7136
|
https://github.com/webgptorg/promptbook
|
|
6839
7137
|
`));
|
|
6840
7138
|
});
|
|
6841
|
-
|
|
6842
|
-
|
|
7139
|
+
app.post(`/login`, async (request, response) => {
|
|
7140
|
+
if (!isApplicationModeAllowed || login === null) {
|
|
7141
|
+
response.status(400).send('Application mode is not allowed');
|
|
7142
|
+
return;
|
|
7143
|
+
}
|
|
7144
|
+
try {
|
|
7145
|
+
const username = request.body.username;
|
|
7146
|
+
const password = request.body.password;
|
|
7147
|
+
const appId = request.body.appId;
|
|
7148
|
+
const { isSuccess, error, message, identification } = await login({
|
|
7149
|
+
username,
|
|
7150
|
+
password,
|
|
7151
|
+
appId,
|
|
7152
|
+
rawRequest: request,
|
|
7153
|
+
rawResponse: response,
|
|
7154
|
+
});
|
|
7155
|
+
response.status(201).send({
|
|
7156
|
+
isSuccess,
|
|
7157
|
+
message,
|
|
7158
|
+
error: error ? serializeError(error) : undefined,
|
|
7159
|
+
identification,
|
|
7160
|
+
});
|
|
7161
|
+
return;
|
|
7162
|
+
}
|
|
7163
|
+
catch (error) {
|
|
7164
|
+
assertsError(error);
|
|
7165
|
+
if (error instanceof AuthenticationError) {
|
|
7166
|
+
response.status(401).send({
|
|
7167
|
+
isSuccess: false,
|
|
7168
|
+
message: error.message,
|
|
7169
|
+
error: serializeError(error),
|
|
7170
|
+
});
|
|
7171
|
+
}
|
|
7172
|
+
console.warn(`Login function thrown different error than AuthenticationError`, {
|
|
7173
|
+
error,
|
|
7174
|
+
serializedError: serializeError(error),
|
|
7175
|
+
});
|
|
7176
|
+
response.status(400).send({ error: serializeError(error) });
|
|
7177
|
+
}
|
|
7178
|
+
});
|
|
7179
|
+
app.get(`/books`, async (request, response) => {
|
|
6843
7180
|
if (collection === null) {
|
|
6844
7181
|
response.status(500).send('No collection available');
|
|
6845
7182
|
return;
|
|
@@ -6849,7 +7186,7 @@
|
|
|
6849
7186
|
response.send(pipelines);
|
|
6850
7187
|
});
|
|
6851
7188
|
// TODO: [🧠] Is it secure / good idea to expose source codes of hosted books
|
|
6852
|
-
app.get(
|
|
7189
|
+
app.get(`/books/*`, async (request, response) => {
|
|
6853
7190
|
try {
|
|
6854
7191
|
if (collection === null) {
|
|
6855
7192
|
response.status(500).send('No collection nor books available');
|
|
@@ -6868,9 +7205,7 @@
|
|
|
6868
7205
|
.send(source.content);
|
|
6869
7206
|
}
|
|
6870
7207
|
catch (error) {
|
|
6871
|
-
|
|
6872
|
-
throw error;
|
|
6873
|
-
}
|
|
7208
|
+
assertsError(error);
|
|
6874
7209
|
response
|
|
6875
7210
|
.status(404)
|
|
6876
7211
|
.send({ error: serializeError(error) });
|
|
@@ -6903,10 +7238,10 @@
|
|
|
6903
7238
|
};
|
|
6904
7239
|
}
|
|
6905
7240
|
}
|
|
6906
|
-
app.get(
|
|
6907
|
-
response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)));
|
|
7241
|
+
app.get(`/executions`, async (request, response) => {
|
|
7242
|
+
response.send(runningExecutionTasks.map((runningExecutionTask) => exportExecutionTask(runningExecutionTask, false)) /* <- TODO: satisfies paths['/executions']['get']['responses']['200']['content']['application/json'] */);
|
|
6908
7243
|
});
|
|
6909
|
-
app.get(
|
|
7244
|
+
app.get(`/executions/last`, async (request, response) => {
|
|
6910
7245
|
// TODO: [🤬] Filter only for user
|
|
6911
7246
|
if (runningExecutionTasks.length === 0) {
|
|
6912
7247
|
response.status(404).send('No execution tasks found');
|
|
@@ -6915,7 +7250,7 @@
|
|
|
6915
7250
|
const lastExecutionTask = runningExecutionTasks[runningExecutionTasks.length - 1];
|
|
6916
7251
|
response.send(exportExecutionTask(lastExecutionTask, true));
|
|
6917
7252
|
});
|
|
6918
|
-
app.get(
|
|
7253
|
+
app.get(`/executions/:taskId`, async (request, response) => {
|
|
6919
7254
|
const { taskId } = request.params;
|
|
6920
7255
|
// TODO: [🤬] Filter only for user
|
|
6921
7256
|
const executionTask = runningExecutionTasks.find((executionTask) => executionTask.taskId === taskId);
|
|
@@ -6927,10 +7262,12 @@
|
|
|
6927
7262
|
}
|
|
6928
7263
|
response.send(exportExecutionTask(executionTask, true));
|
|
6929
7264
|
});
|
|
6930
|
-
app.post(
|
|
7265
|
+
app.post(`/executions/new`, async (request, response) => {
|
|
6931
7266
|
try {
|
|
6932
7267
|
const { inputParameters, identification /* <- [🤬] */ } = request.body;
|
|
6933
|
-
const pipelineUrl = request.body
|
|
7268
|
+
const pipelineUrl = request.body
|
|
7269
|
+
.pipelineUrl /* <- TODO: as paths['/executions/new']['post']['requestBody']['content']['application/json'] */ ||
|
|
7270
|
+
request.body.book;
|
|
6934
7271
|
// TODO: [🧠] Check `pipelineUrl` and `inputParameters` here or it should be responsibility of `collection.getPipelineByUrl` and `pipelineExecutor`
|
|
6935
7272
|
const pipeline = await (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl));
|
|
6936
7273
|
if (pipeline === undefined) {
|
|
@@ -6944,7 +7281,7 @@
|
|
|
6944
7281
|
await waitasecond.forTime(10);
|
|
6945
7282
|
// <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
|
|
6946
7283
|
// <- TODO: Put this into configuration
|
|
6947
|
-
response.send(executionTask);
|
|
7284
|
+
response.send(executionTask /* <- TODO: satisfies paths['/executions/new']['post']['responses']['200']['content']['application/json'] */);
|
|
6948
7285
|
/*/
|
|
6949
7286
|
executionTask.asObservable().subscribe({
|
|
6950
7287
|
next(partialResult) {
|
|
@@ -6964,19 +7301,24 @@
|
|
|
6964
7301
|
*/
|
|
6965
7302
|
}
|
|
6966
7303
|
catch (error) {
|
|
6967
|
-
|
|
6968
|
-
throw error;
|
|
6969
|
-
}
|
|
7304
|
+
assertsError(error);
|
|
6970
7305
|
response.status(400).send({ error: serializeError(error) });
|
|
6971
7306
|
}
|
|
6972
7307
|
});
|
|
7308
|
+
/**
|
|
7309
|
+
* Catch-all handler for unmatched routes
|
|
7310
|
+
*/
|
|
7311
|
+
app.use((request, response) => {
|
|
7312
|
+
response.status(404).send(`URL "${request.originalUrl}" was not found on Promptbook server.`);
|
|
7313
|
+
});
|
|
6973
7314
|
const httpServer = http__default["default"].createServer(app);
|
|
6974
7315
|
const server = new socket_io.Server(httpServer, {
|
|
6975
|
-
path:
|
|
6976
|
-
transports: [
|
|
7316
|
+
path: '/socket.io',
|
|
7317
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
6977
7318
|
cors: {
|
|
6978
7319
|
origin: '*',
|
|
6979
7320
|
methods: ['GET', 'POST'],
|
|
7321
|
+
// <- TODO: [🌡] Allow to pass
|
|
6980
7322
|
},
|
|
6981
7323
|
});
|
|
6982
7324
|
server.on('connection', (socket) => {
|
|
@@ -7030,9 +7372,7 @@
|
|
|
7030
7372
|
socket.emit('prompt-response', { promptResult } /* <- Note: [🤛] */);
|
|
7031
7373
|
}
|
|
7032
7374
|
catch (error) {
|
|
7033
|
-
|
|
7034
|
-
throw error;
|
|
7035
|
-
}
|
|
7375
|
+
assertsError(error);
|
|
7036
7376
|
socket.emit('error', serializeError(error) /* <- Note: [🤛] */);
|
|
7037
7377
|
}
|
|
7038
7378
|
finally {
|
|
@@ -7054,9 +7394,7 @@
|
|
|
7054
7394
|
socket.emit('listModels-response', { models } /* <- Note: [🤛] */);
|
|
7055
7395
|
}
|
|
7056
7396
|
catch (error) {
|
|
7057
|
-
|
|
7058
|
-
throw error;
|
|
7059
|
-
}
|
|
7397
|
+
assertsError(error);
|
|
7060
7398
|
socket.emit('error', serializeError(error));
|
|
7061
7399
|
}
|
|
7062
7400
|
finally {
|
|
@@ -7077,9 +7415,7 @@
|
|
|
7077
7415
|
socket.emit('preparePipeline-response', { preparedPipeline } /* <- Note: [🤛] */);
|
|
7078
7416
|
}
|
|
7079
7417
|
catch (error) {
|
|
7080
|
-
|
|
7081
|
-
throw error;
|
|
7082
|
-
}
|
|
7418
|
+
assertsError(error);
|
|
7083
7419
|
socket.emit('error', serializeError(error));
|
|
7084
7420
|
// <- TODO: [🚋] There is a problem with the remote server handling errors and sending them back to the client
|
|
7085
7421
|
}
|
|
@@ -7104,6 +7440,15 @@
|
|
|
7104
7440
|
}
|
|
7105
7441
|
let isDestroyed = false;
|
|
7106
7442
|
return {
|
|
7443
|
+
get httpServer() {
|
|
7444
|
+
return httpServer;
|
|
7445
|
+
},
|
|
7446
|
+
get expressApp() {
|
|
7447
|
+
return app;
|
|
7448
|
+
},
|
|
7449
|
+
get socketIoServer() {
|
|
7450
|
+
return server;
|
|
7451
|
+
},
|
|
7107
7452
|
get isDestroyed() {
|
|
7108
7453
|
return isDestroyed;
|
|
7109
7454
|
},
|
|
@@ -7118,8 +7463,7 @@
|
|
|
7118
7463
|
};
|
|
7119
7464
|
}
|
|
7120
7465
|
/**
|
|
7121
|
-
* TODO:
|
|
7122
|
-
* TODO: [👩🏾🤝🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
|
|
7466
|
+
* TODO: [🌡] Add CORS and security - probbably via `helmet`
|
|
7123
7467
|
* TODO: Split this file into multiple functions - handler for each request
|
|
7124
7468
|
* TODO: Maybe use `$exportJson`
|
|
7125
7469
|
* TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
|