@promptbook/remote-client 0.89.0-20 → 0.89.0-28
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 +50 -36
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -1
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +0 -10
- package/package.json +2 -2
- package/umd/index.umd.js +50 -36
- package/umd/index.umd.js.map +1 -1
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-28';
|
|
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
|
|
@@ -552,6 +552,35 @@ function deserializeError(error) {
|
|
|
552
552
|
return deserializedError;
|
|
553
553
|
}
|
|
554
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
|
+
|
|
555
584
|
/**
|
|
556
585
|
* Creates a connection to the remote proxy server.
|
|
557
586
|
*
|
|
@@ -561,17 +590,31 @@ function deserializeError(error) {
|
|
|
561
590
|
*/
|
|
562
591
|
async function createRemoteClient(options) {
|
|
563
592
|
const { remoteServerUrl } = options;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
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
|
+
`));
|
|
567
611
|
}
|
|
568
|
-
path = `${path}/socket.io`;
|
|
569
612
|
return new Promise((resolve, reject) => {
|
|
570
613
|
const socket = io(remoteServerUrl, {
|
|
571
614
|
retries: CONNECTION_RETRIES_LIMIT,
|
|
572
615
|
timeout: CONNECTION_TIMEOUT_MS,
|
|
573
|
-
path,
|
|
574
|
-
transports: [
|
|
616
|
+
path: '/socket.io',
|
|
617
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
575
618
|
});
|
|
576
619
|
// console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
|
|
577
620
|
socket.on('connect', () => {
|
|
@@ -705,35 +748,6 @@ function isValidFilePath(filename) {
|
|
|
705
748
|
* TODO: [🍏] Implement for MacOs
|
|
706
749
|
*/
|
|
707
750
|
|
|
708
|
-
/**
|
|
709
|
-
* Tests if given string is valid URL.
|
|
710
|
-
*
|
|
711
|
-
* Note: Dataurl are considered perfectly valid.
|
|
712
|
-
* Note: There are two simmilar functions:
|
|
713
|
-
* - `isValidUrl` which tests any URL
|
|
714
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
715
|
-
*
|
|
716
|
-
* @public exported from `@promptbook/utils`
|
|
717
|
-
*/
|
|
718
|
-
function isValidUrl(url) {
|
|
719
|
-
if (typeof url !== 'string') {
|
|
720
|
-
return false;
|
|
721
|
-
}
|
|
722
|
-
try {
|
|
723
|
-
if (url.startsWith('blob:')) {
|
|
724
|
-
url = url.replace(/^blob:/, '');
|
|
725
|
-
}
|
|
726
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
727
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
728
|
-
return false;
|
|
729
|
-
}
|
|
730
|
-
return true;
|
|
731
|
-
}
|
|
732
|
-
catch (error) {
|
|
733
|
-
return false;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
751
|
const defaultDiacriticsRemovalMap = [
|
|
738
752
|
{
|
|
739
753
|
base: 'A',
|