@promptbook/remote-client 0.89.0-9 → 0.89.0
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 -11
- package/esm/index.es.js +160 -53
- 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 +8 -4
- package/esm/typings/src/_packages/types.index.d.ts +18 -0
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
- 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 +10 -19
- package/esm/typings/src/errors/0-index.d.ts +7 -4
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- 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/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- 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/Identification.d.ts +7 -1
- 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/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +26 -0
- package/package.json +7 -3
- package/umd/index.umd.js +160 -53
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-client",
|
|
3
|
-
"version": "0.89.0
|
|
3
|
+
"version": "0.89.0",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -43,14 +43,18 @@
|
|
|
43
43
|
"url": "https://github.com/webgptorg/promptbook/issues"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://ptbk.io/",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=16.0.0",
|
|
48
|
+
"npm": ">=8.0.0"
|
|
49
|
+
},
|
|
46
50
|
"main": "./umd/index.umd.js",
|
|
47
51
|
"module": "./esm/index.es.js",
|
|
48
52
|
"typings": "./esm/typings/src/_packages/remote-client.index.d.ts",
|
|
49
53
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.89.0
|
|
54
|
+
"@promptbook/core": "0.89.0"
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"crypto": "
|
|
57
|
+
"crypto": "1.0.1",
|
|
54
58
|
"crypto-js": "4.2.0",
|
|
55
59
|
"papaparse": "5.4.1",
|
|
56
60
|
"socket.io-client": "4.7.2",
|
package/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
* TODO:
|
|
244
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
245
245
|
*/
|
|
246
246
|
|
|
247
247
|
/**
|
|
@@ -323,6 +323,7 @@
|
|
|
323
323
|
* @public exported from `@promptbook/core`
|
|
324
324
|
*/
|
|
325
325
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
326
|
+
// <- TODO: [🐊] Pick the best claim
|
|
326
327
|
/**
|
|
327
328
|
* When the title is not provided, the default title is used
|
|
328
329
|
*
|
|
@@ -446,6 +447,26 @@
|
|
|
446
447
|
}
|
|
447
448
|
}
|
|
448
449
|
|
|
450
|
+
/**
|
|
451
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
452
|
+
*
|
|
453
|
+
* @public exported from `@promptbook/core`
|
|
454
|
+
*/
|
|
455
|
+
class WrappedError extends Error {
|
|
456
|
+
constructor(whatWasThrown) {
|
|
457
|
+
const tag = `[🤮]`;
|
|
458
|
+
console.error(tag, whatWasThrown);
|
|
459
|
+
super(spaceTrim.spaceTrim(`
|
|
460
|
+
Non-Error object was thrown
|
|
461
|
+
|
|
462
|
+
Note: Look for ${tag} in the console for more details
|
|
463
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
464
|
+
`));
|
|
465
|
+
this.name = 'WrappedError';
|
|
466
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
449
470
|
/**
|
|
450
471
|
* Index of all custom errors
|
|
451
472
|
*
|
|
@@ -466,7 +487,10 @@
|
|
|
466
487
|
PipelineExecutionError,
|
|
467
488
|
PipelineLogicError,
|
|
468
489
|
PipelineUrlError,
|
|
490
|
+
AuthenticationError,
|
|
491
|
+
PromptbookFetchError,
|
|
469
492
|
UnexpectedError,
|
|
493
|
+
WrappedError,
|
|
470
494
|
// TODO: [🪑]> VersionMismatchError,
|
|
471
495
|
};
|
|
472
496
|
/**
|
|
@@ -483,8 +507,6 @@
|
|
|
483
507
|
TypeError,
|
|
484
508
|
URIError,
|
|
485
509
|
AggregateError,
|
|
486
|
-
AuthenticationError,
|
|
487
|
-
PromptbookFetchError,
|
|
488
510
|
/*
|
|
489
511
|
Note: Not widely supported
|
|
490
512
|
> InternalError,
|
|
@@ -533,6 +555,35 @@
|
|
|
533
555
|
return deserializedError;
|
|
534
556
|
}
|
|
535
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Tests if given string is valid URL.
|
|
560
|
+
*
|
|
561
|
+
* Note: Dataurl are considered perfectly valid.
|
|
562
|
+
* Note: There are two simmilar functions:
|
|
563
|
+
* - `isValidUrl` which tests any URL
|
|
564
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
565
|
+
*
|
|
566
|
+
* @public exported from `@promptbook/utils`
|
|
567
|
+
*/
|
|
568
|
+
function isValidUrl(url) {
|
|
569
|
+
if (typeof url !== 'string') {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
if (url.startsWith('blob:')) {
|
|
574
|
+
url = url.replace(/^blob:/, '');
|
|
575
|
+
}
|
|
576
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
577
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
536
587
|
/**
|
|
537
588
|
* Creates a connection to the remote proxy server.
|
|
538
589
|
*
|
|
@@ -542,17 +593,31 @@
|
|
|
542
593
|
*/
|
|
543
594
|
async function createRemoteClient(options) {
|
|
544
595
|
const { remoteServerUrl } = options;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
596
|
+
if (!isValidUrl(remoteServerUrl)) {
|
|
597
|
+
throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
|
|
598
|
+
}
|
|
599
|
+
const remoteServerUrlParsed = new URL(remoteServerUrl);
|
|
600
|
+
if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
|
|
601
|
+
remoteServerUrlParsed.pathname = '/';
|
|
602
|
+
throw new Error(spaceTrim__default["default"]((block) => `
|
|
603
|
+
Remote server requires root url \`/\`
|
|
604
|
+
|
|
605
|
+
You have provided \`remoteServerUrl\`:
|
|
606
|
+
${block(remoteServerUrl)}
|
|
607
|
+
|
|
608
|
+
But something like this is expected:
|
|
609
|
+
${block(remoteServerUrlParsed.href)}
|
|
610
|
+
|
|
611
|
+
Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
|
|
612
|
+
|
|
613
|
+
`));
|
|
548
614
|
}
|
|
549
|
-
path = `${path}/socket.io`;
|
|
550
615
|
return new Promise((resolve, reject) => {
|
|
551
616
|
const socket = socket_ioClient.io(remoteServerUrl, {
|
|
552
617
|
retries: CONNECTION_RETRIES_LIMIT,
|
|
553
618
|
timeout: CONNECTION_TIMEOUT_MS,
|
|
554
|
-
path,
|
|
555
|
-
transports: [
|
|
619
|
+
path: '/socket.io',
|
|
620
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
556
621
|
});
|
|
557
622
|
// console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
|
|
558
623
|
socket.on('connect', () => {
|
|
@@ -686,35 +751,6 @@
|
|
|
686
751
|
* TODO: [🍏] Implement for MacOs
|
|
687
752
|
*/
|
|
688
753
|
|
|
689
|
-
/**
|
|
690
|
-
* Tests if given string is valid URL.
|
|
691
|
-
*
|
|
692
|
-
* Note: Dataurl are considered perfectly valid.
|
|
693
|
-
* Note: There are two simmilar functions:
|
|
694
|
-
* - `isValidUrl` which tests any URL
|
|
695
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
696
|
-
*
|
|
697
|
-
* @public exported from `@promptbook/utils`
|
|
698
|
-
*/
|
|
699
|
-
function isValidUrl(url) {
|
|
700
|
-
if (typeof url !== 'string') {
|
|
701
|
-
return false;
|
|
702
|
-
}
|
|
703
|
-
try {
|
|
704
|
-
if (url.startsWith('blob:')) {
|
|
705
|
-
url = url.replace(/^blob:/, '');
|
|
706
|
-
}
|
|
707
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
708
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
709
|
-
return false;
|
|
710
|
-
}
|
|
711
|
-
return true;
|
|
712
|
-
}
|
|
713
|
-
catch (error) {
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
754
|
const defaultDiacriticsRemovalMap = [
|
|
719
755
|
{
|
|
720
756
|
base: 'A',
|
|
@@ -1542,6 +1578,34 @@
|
|
|
1542
1578
|
},
|
|
1543
1579
|
};
|
|
1544
1580
|
|
|
1581
|
+
/**
|
|
1582
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
1583
|
+
*
|
|
1584
|
+
* @param whatWasThrown Any object that was thrown
|
|
1585
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
1586
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
1587
|
+
*
|
|
1588
|
+
* @private within the repository
|
|
1589
|
+
*/
|
|
1590
|
+
function assertsError(whatWasThrown) {
|
|
1591
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
1592
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1593
|
+
const wrappedError = whatWasThrown;
|
|
1594
|
+
throw wrappedError;
|
|
1595
|
+
}
|
|
1596
|
+
// Case 2: Handle unexpected errors
|
|
1597
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1598
|
+
const unexpectedError = whatWasThrown;
|
|
1599
|
+
throw unexpectedError;
|
|
1600
|
+
}
|
|
1601
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
1602
|
+
if (whatWasThrown instanceof Error) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
1606
|
+
throw new WrappedError(whatWasThrown);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1545
1609
|
/**
|
|
1546
1610
|
* Units of text measurement
|
|
1547
1611
|
*
|
|
@@ -1622,6 +1686,8 @@
|
|
|
1622
1686
|
*/
|
|
1623
1687
|
|
|
1624
1688
|
/**
|
|
1689
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
1690
|
+
import { assertsError } from '../../errors/assertsError';
|
|
1625
1691
|
* Parses the expect command
|
|
1626
1692
|
*
|
|
1627
1693
|
* @see `documentationUrl` for more details
|
|
@@ -1713,9 +1779,7 @@
|
|
|
1713
1779
|
};
|
|
1714
1780
|
}
|
|
1715
1781
|
catch (error) {
|
|
1716
|
-
|
|
1717
|
-
throw error;
|
|
1718
|
-
}
|
|
1782
|
+
assertsError(error);
|
|
1719
1783
|
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
1720
1784
|
Invalid FORMAT command
|
|
1721
1785
|
${block(error.message)}:
|
|
@@ -1773,6 +1837,28 @@
|
|
|
1773
1837
|
// encoding: 'utf-8',
|
|
1774
1838
|
});
|
|
1775
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Function to check if a string is valid CSV
|
|
1842
|
+
*
|
|
1843
|
+
* @param value The string to check
|
|
1844
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
1845
|
+
*
|
|
1846
|
+
* @public exported from `@promptbook/utils`
|
|
1847
|
+
*/
|
|
1848
|
+
function isValidCsvString(value) {
|
|
1849
|
+
try {
|
|
1850
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
1851
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
1852
|
+
return true;
|
|
1853
|
+
}
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1856
|
+
catch (error) {
|
|
1857
|
+
assertsError(error);
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1776
1862
|
/**
|
|
1777
1863
|
* Definition for CSV spreadsheet
|
|
1778
1864
|
*
|
|
@@ -1783,7 +1869,7 @@
|
|
|
1783
1869
|
formatName: 'CSV',
|
|
1784
1870
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
1785
1871
|
isValid(value, settings, schema) {
|
|
1786
|
-
return
|
|
1872
|
+
return isValidCsvString(value);
|
|
1787
1873
|
},
|
|
1788
1874
|
canBeValid(partialValue, settings, schema) {
|
|
1789
1875
|
return true;
|
|
@@ -1864,6 +1950,9 @@
|
|
|
1864
1950
|
/**
|
|
1865
1951
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1866
1952
|
*
|
|
1953
|
+
* @param value The string to check
|
|
1954
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
1955
|
+
*
|
|
1867
1956
|
* @public exported from `@promptbook/utils`
|
|
1868
1957
|
*/
|
|
1869
1958
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -1872,9 +1961,7 @@
|
|
|
1872
1961
|
return true;
|
|
1873
1962
|
}
|
|
1874
1963
|
catch (error) {
|
|
1875
|
-
|
|
1876
|
-
throw error;
|
|
1877
|
-
}
|
|
1964
|
+
assertsError(error);
|
|
1878
1965
|
if (error.message.includes('Unexpected token')) {
|
|
1879
1966
|
return false;
|
|
1880
1967
|
}
|
|
@@ -1958,6 +2045,30 @@
|
|
|
1958
2045
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
1959
2046
|
*/
|
|
1960
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* Function to check if a string is valid XML
|
|
2050
|
+
*
|
|
2051
|
+
* @param value
|
|
2052
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
2053
|
+
*
|
|
2054
|
+
* @public exported from `@promptbook/utils`
|
|
2055
|
+
*/
|
|
2056
|
+
function isValidXmlString(value) {
|
|
2057
|
+
try {
|
|
2058
|
+
const parser = new DOMParser();
|
|
2059
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
2060
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
2061
|
+
if (parserError.length > 0) {
|
|
2062
|
+
return false;
|
|
2063
|
+
}
|
|
2064
|
+
return true;
|
|
2065
|
+
}
|
|
2066
|
+
catch (error) {
|
|
2067
|
+
assertsError(error);
|
|
2068
|
+
return false;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
|
|
1961
2072
|
/**
|
|
1962
2073
|
* Definition for XML format
|
|
1963
2074
|
*
|
|
@@ -1967,7 +2078,7 @@
|
|
|
1967
2078
|
formatName: 'XML',
|
|
1968
2079
|
mimeType: 'application/xml',
|
|
1969
2080
|
isValid(value, settings, schema) {
|
|
1970
|
-
return
|
|
2081
|
+
return isValidXmlString(value);
|
|
1971
2082
|
},
|
|
1972
2083
|
canBeValid(partialValue, settings, schema) {
|
|
1973
2084
|
return true;
|
|
@@ -2192,9 +2303,7 @@
|
|
|
2192
2303
|
JSON.stringify(value); // <- TODO: [0]
|
|
2193
2304
|
}
|
|
2194
2305
|
catch (error) {
|
|
2195
|
-
|
|
2196
|
-
throw error;
|
|
2197
|
-
}
|
|
2306
|
+
assertsError(error);
|
|
2198
2307
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
2199
2308
|
\`${name}\` is not serializable
|
|
2200
2309
|
|
|
@@ -4849,9 +4958,7 @@
|
|
|
4849
4958
|
}
|
|
4850
4959
|
}
|
|
4851
4960
|
catch (error) {
|
|
4852
|
-
|
|
4853
|
-
throw error;
|
|
4854
|
-
}
|
|
4961
|
+
assertsError(error);
|
|
4855
4962
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4856
4963
|
Can not extract variables from the script
|
|
4857
4964
|
${block(error.stack || error.message)}
|