@promptbook/remote-client 0.89.0-3 → 0.89.0-30
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 +141 -51
- 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 +7 -3
- package/umd/index.umd.js +141 -51
- 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/README.md
CHANGED
|
@@ -244,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
|
|
247
|
+
## 🔒 Security
|
|
248
|
+
|
|
249
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
250
|
+
|
|
247
251
|
## 📦 Packages _(for developers)_
|
|
248
252
|
|
|
249
253
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -300,7 +304,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
300
304
|
### General LLM / AI terms
|
|
301
305
|
|
|
302
306
|
- **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
|
|
303
|
-
- **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
|
|
307
|
+
- [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
|
|
304
308
|
- **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
|
|
305
309
|
- **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
|
|
306
310
|
- **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
|
|
@@ -308,10 +312,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
308
312
|
- **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
|
|
309
313
|
- **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
|
|
310
314
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
315
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
316
316
|
|
|
317
317
|
|
|
@@ -425,6 +425,8 @@ See [TODO.md](./TODO.md)
|
|
|
425
425
|
|
|
426
426
|
## 🖋️ Contributing
|
|
427
427
|
|
|
428
|
-
We are open to pull requests, feedback, and suggestions.
|
|
428
|
+
You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
|
|
429
|
+
|
|
430
|
+
## 📞 Support
|
|
429
431
|
|
|
430
|
-
|
|
432
|
+
If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
|
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
* @generated
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-
|
|
23
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-30';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -56,6 +56,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
61
|
+
*
|
|
62
|
+
* @public exported from `@promptbook/core`
|
|
63
|
+
*/
|
|
64
|
+
class AuthenticationError extends Error {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = 'AuthenticationError';
|
|
68
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
59
72
|
/**
|
|
60
73
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
61
74
|
*
|
|
@@ -225,7 +238,7 @@ class PipelineExecutionError extends Error {
|
|
|
225
238
|
}
|
|
226
239
|
}
|
|
227
240
|
/**
|
|
228
|
-
* TODO:
|
|
241
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
229
242
|
*/
|
|
230
243
|
|
|
231
244
|
/**
|
|
@@ -254,6 +267,19 @@ class PipelineUrlError extends Error {
|
|
|
254
267
|
}
|
|
255
268
|
}
|
|
256
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Error thrown when a fetch request fails
|
|
272
|
+
*
|
|
273
|
+
* @public exported from `@promptbook/core`
|
|
274
|
+
*/
|
|
275
|
+
class PromptbookFetchError extends Error {
|
|
276
|
+
constructor(message) {
|
|
277
|
+
super(message);
|
|
278
|
+
this.name = 'PromptbookFetchError';
|
|
279
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
257
283
|
/**
|
|
258
284
|
* Returns the same value that is passed as argument.
|
|
259
285
|
* No side effects.
|
|
@@ -294,6 +320,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
|
294
320
|
* @public exported from `@promptbook/core`
|
|
295
321
|
*/
|
|
296
322
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
323
|
+
// <- TODO: [🐊] Pick the best claim
|
|
297
324
|
/**
|
|
298
325
|
* When the title is not provided, the default title is used
|
|
299
326
|
*
|
|
@@ -346,7 +373,7 @@ Object.freeze({
|
|
|
346
373
|
});
|
|
347
374
|
/**
|
|
348
375
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
349
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
376
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
350
377
|
*/
|
|
351
378
|
|
|
352
379
|
/**
|
|
@@ -417,6 +444,26 @@ class UnexpectedError extends Error {
|
|
|
417
444
|
}
|
|
418
445
|
}
|
|
419
446
|
|
|
447
|
+
/**
|
|
448
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
449
|
+
*
|
|
450
|
+
* @public exported from `@promptbook/core`
|
|
451
|
+
*/
|
|
452
|
+
class WrappedError extends Error {
|
|
453
|
+
constructor(whatWasThrown) {
|
|
454
|
+
const tag = `[🤮]`;
|
|
455
|
+
console.error(tag, whatWasThrown);
|
|
456
|
+
super(spaceTrim(`
|
|
457
|
+
Non-Error object was thrown
|
|
458
|
+
|
|
459
|
+
Note: Look for ${tag} in the console for more details
|
|
460
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
461
|
+
`));
|
|
462
|
+
this.name = 'WrappedError';
|
|
463
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
420
467
|
/**
|
|
421
468
|
* Index of all custom errors
|
|
422
469
|
*
|
|
@@ -437,7 +484,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
437
484
|
PipelineExecutionError,
|
|
438
485
|
PipelineLogicError,
|
|
439
486
|
PipelineUrlError,
|
|
487
|
+
AuthenticationError,
|
|
488
|
+
PromptbookFetchError,
|
|
440
489
|
UnexpectedError,
|
|
490
|
+
WrappedError,
|
|
441
491
|
// TODO: [🪑]> VersionMismatchError,
|
|
442
492
|
};
|
|
443
493
|
/**
|
|
@@ -502,6 +552,35 @@ function deserializeError(error) {
|
|
|
502
552
|
return deserializedError;
|
|
503
553
|
}
|
|
504
554
|
|
|
555
|
+
/**
|
|
556
|
+
* Tests if given string is valid URL.
|
|
557
|
+
*
|
|
558
|
+
* Note: Dataurl are considered perfectly valid.
|
|
559
|
+
* Note: There are two simmilar functions:
|
|
560
|
+
* - `isValidUrl` which tests any URL
|
|
561
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
562
|
+
*
|
|
563
|
+
* @public exported from `@promptbook/utils`
|
|
564
|
+
*/
|
|
565
|
+
function isValidUrl(url) {
|
|
566
|
+
if (typeof url !== 'string') {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
try {
|
|
570
|
+
if (url.startsWith('blob:')) {
|
|
571
|
+
url = url.replace(/^blob:/, '');
|
|
572
|
+
}
|
|
573
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
574
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
505
584
|
/**
|
|
506
585
|
* Creates a connection to the remote proxy server.
|
|
507
586
|
*
|
|
@@ -510,22 +589,40 @@ function deserializeError(error) {
|
|
|
510
589
|
* @private internal utility function
|
|
511
590
|
*/
|
|
512
591
|
async function createRemoteClient(options) {
|
|
513
|
-
const {
|
|
592
|
+
const { remoteServerUrl } = options;
|
|
593
|
+
if (!isValidUrl(remoteServerUrl)) {
|
|
594
|
+
throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
|
|
595
|
+
}
|
|
596
|
+
const remoteServerUrlParsed = new URL(remoteServerUrl);
|
|
597
|
+
if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
|
|
598
|
+
remoteServerUrlParsed.pathname = '/';
|
|
599
|
+
throw new Error(spaceTrim$1((block) => `
|
|
600
|
+
Remote server requires root url \`/\`
|
|
601
|
+
|
|
602
|
+
You have provided \`remoteServerUrl\`:
|
|
603
|
+
${block(remoteServerUrl)}
|
|
604
|
+
|
|
605
|
+
But something like this is expected:
|
|
606
|
+
${block(remoteServerUrlParsed.href)}
|
|
607
|
+
|
|
608
|
+
Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
|
|
609
|
+
|
|
610
|
+
`));
|
|
611
|
+
}
|
|
514
612
|
return new Promise((resolve, reject) => {
|
|
515
|
-
const socket = io(
|
|
613
|
+
const socket = io(remoteServerUrl, {
|
|
516
614
|
retries: CONNECTION_RETRIES_LIMIT,
|
|
517
615
|
timeout: CONNECTION_TIMEOUT_MS,
|
|
518
|
-
path,
|
|
519
|
-
|
|
520
|
-
transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
|
|
616
|
+
path: '/socket.io',
|
|
617
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
521
618
|
});
|
|
522
|
-
// console.log('Connecting to', this.options.
|
|
619
|
+
// console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
|
|
523
620
|
socket.on('connect', () => {
|
|
524
621
|
resolve(socket);
|
|
525
622
|
});
|
|
526
623
|
// TODO: [💩] Better timeout handling
|
|
527
624
|
setTimeout(() => {
|
|
528
|
-
reject(new Error(`Timeout while connecting to ${
|
|
625
|
+
reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
|
|
529
626
|
}, CONNECTION_TIMEOUT_MS);
|
|
530
627
|
});
|
|
531
628
|
}
|
|
@@ -651,35 +748,6 @@ function isValidFilePath(filename) {
|
|
|
651
748
|
* TODO: [🍏] Implement for MacOs
|
|
652
749
|
*/
|
|
653
750
|
|
|
654
|
-
/**
|
|
655
|
-
* Tests if given string is valid URL.
|
|
656
|
-
*
|
|
657
|
-
* Note: Dataurl are considered perfectly valid.
|
|
658
|
-
* Note: There are two simmilar functions:
|
|
659
|
-
* - `isValidUrl` which tests any URL
|
|
660
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
661
|
-
*
|
|
662
|
-
* @public exported from `@promptbook/utils`
|
|
663
|
-
*/
|
|
664
|
-
function isValidUrl(url) {
|
|
665
|
-
if (typeof url !== 'string') {
|
|
666
|
-
return false;
|
|
667
|
-
}
|
|
668
|
-
try {
|
|
669
|
-
if (url.startsWith('blob:')) {
|
|
670
|
-
url = url.replace(/^blob:/, '');
|
|
671
|
-
}
|
|
672
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
673
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
674
|
-
return false;
|
|
675
|
-
}
|
|
676
|
-
return true;
|
|
677
|
-
}
|
|
678
|
-
catch (error) {
|
|
679
|
-
return false;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
751
|
const defaultDiacriticsRemovalMap = [
|
|
684
752
|
{
|
|
685
753
|
base: 'A',
|
|
@@ -1507,6 +1575,34 @@ const bookVersionCommandParser = {
|
|
|
1507
1575
|
},
|
|
1508
1576
|
};
|
|
1509
1577
|
|
|
1578
|
+
/**
|
|
1579
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
1580
|
+
*
|
|
1581
|
+
* @param whatWasThrown Any object that was thrown
|
|
1582
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
1583
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
1584
|
+
*
|
|
1585
|
+
* @private within the repository
|
|
1586
|
+
*/
|
|
1587
|
+
function assertsError(whatWasThrown) {
|
|
1588
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
1589
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1590
|
+
const wrappedError = whatWasThrown;
|
|
1591
|
+
throw wrappedError;
|
|
1592
|
+
}
|
|
1593
|
+
// Case 2: Handle unexpected errors
|
|
1594
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1595
|
+
const unexpectedError = whatWasThrown;
|
|
1596
|
+
throw unexpectedError;
|
|
1597
|
+
}
|
|
1598
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
1599
|
+
if (whatWasThrown instanceof Error) {
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
1603
|
+
throw new WrappedError(whatWasThrown);
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1510
1606
|
/**
|
|
1511
1607
|
* Units of text measurement
|
|
1512
1608
|
*
|
|
@@ -1587,6 +1683,8 @@ function parseNumber(value) {
|
|
|
1587
1683
|
*/
|
|
1588
1684
|
|
|
1589
1685
|
/**
|
|
1686
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
1687
|
+
import { assertsError } from '../../errors/assertsError';
|
|
1590
1688
|
* Parses the expect command
|
|
1591
1689
|
*
|
|
1592
1690
|
* @see `documentationUrl` for more details
|
|
@@ -1678,9 +1776,7 @@ const expectCommandParser = {
|
|
|
1678
1776
|
};
|
|
1679
1777
|
}
|
|
1680
1778
|
catch (error) {
|
|
1681
|
-
|
|
1682
|
-
throw error;
|
|
1683
|
-
}
|
|
1779
|
+
assertsError(error);
|
|
1684
1780
|
throw new ParseError(spaceTrim$1((block) => `
|
|
1685
1781
|
Invalid FORMAT command
|
|
1686
1782
|
${block(error.message)}:
|
|
@@ -1837,9 +1933,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1837
1933
|
return true;
|
|
1838
1934
|
}
|
|
1839
1935
|
catch (error) {
|
|
1840
|
-
|
|
1841
|
-
throw error;
|
|
1842
|
-
}
|
|
1936
|
+
assertsError(error);
|
|
1843
1937
|
if (error.message.includes('Unexpected token')) {
|
|
1844
1938
|
return false;
|
|
1845
1939
|
}
|
|
@@ -2157,9 +2251,7 @@ function checkSerializableAsJson(options) {
|
|
|
2157
2251
|
JSON.stringify(value); // <- TODO: [0]
|
|
2158
2252
|
}
|
|
2159
2253
|
catch (error) {
|
|
2160
|
-
|
|
2161
|
-
throw error;
|
|
2162
|
-
}
|
|
2254
|
+
assertsError(error);
|
|
2163
2255
|
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2164
2256
|
\`${name}\` is not serializable
|
|
2165
2257
|
|
|
@@ -4814,9 +4906,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
4814
4906
|
}
|
|
4815
4907
|
}
|
|
4816
4908
|
catch (error) {
|
|
4817
|
-
|
|
4818
|
-
throw error;
|
|
4819
|
-
}
|
|
4909
|
+
assertsError(error);
|
|
4820
4910
|
throw new ParseError(spaceTrim((block) => `
|
|
4821
4911
|
Can not extract variables from the script
|
|
4822
4912
|
${block(error.stack || error.message)}
|