@promptbook/remote-client 0.98.0 → 0.100.0-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 CHANGED
@@ -25,6 +25,10 @@ Write AI applications using plain human language across multiple models and plat
25
25
 
26
26
 
27
27
 
28
+ <blockquote style="color: #ff8811">
29
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
30
+ </blockquote>
31
+
28
32
  ## 📦 Package `@promptbook/remote-client`
29
33
 
30
34
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
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.98.0';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-0';
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
@@ -349,9 +349,12 @@ const LOOP_LIMIT = 1000;
349
349
  /**
350
350
  * Timeout for the connections in milliseconds
351
351
  *
352
+ * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
353
+ * like Facebook login which may require user interaction and redirects
354
+ *
352
355
  * @private within the repository - too low-level in comparison with other `MAX_...`
353
356
  */
354
- const CONNECTION_TIMEOUT_MS = 7 * 1000;
357
+ const CONNECTION_TIMEOUT_MS = 30 * 1000;
355
358
  // <- TODO: [⏳] Standardize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
356
359
  /**
357
360
  * How many times to retry the connections
@@ -617,13 +620,39 @@ async function createRemoteClient(options) {
617
620
  transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
618
621
  });
619
622
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
623
+ let isResolved = false;
620
624
  socket.on('connect', () => {
621
- resolve(socket);
625
+ if (!isResolved) {
626
+ isResolved = true;
627
+ resolve(socket);
628
+ }
629
+ });
630
+ socket.on('connect_error', (error) => {
631
+ if (!isResolved) {
632
+ isResolved = true;
633
+ reject(new Error(`Failed to connect to ${remoteServerUrl}: ${error.message || error}`));
634
+ }
635
+ });
636
+ socket.on('disconnect', (reason) => {
637
+ if (!isResolved) {
638
+ isResolved = true;
639
+ reject(new Error(`Connection to ${remoteServerUrl} was disconnected: ${reason}`));
640
+ }
622
641
  });
623
- // TODO: [💩] Better timeout handling
624
- setTimeout(() => {
625
- reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
642
+ // Better timeout handling with more descriptive error message
643
+ const timeoutId = setTimeout(() => {
644
+ if (!isResolved) {
645
+ isResolved = true;
646
+ socket.disconnect();
647
+ reject(new Error(`Connection timeout after ${CONNECTION_TIMEOUT_MS / 1000} seconds while connecting to ${remoteServerUrl}. ` +
648
+ `This may indicate network issues or the server may be experiencing high load. ` +
649
+ `For authentication flows like social login, ensure sufficient time is allowed for user interaction.`));
650
+ }
626
651
  }, CONNECTION_TIMEOUT_MS);
652
+ // Clean up timeout if connection succeeds
653
+ socket.on('connect', () => {
654
+ clearTimeout(timeoutId);
655
+ });
627
656
  });
628
657
  }
629
658
 
@@ -5629,8 +5658,33 @@ class RemoteLlmExecutionTools {
5629
5658
  * Check the configuration of all execution tools
5630
5659
  */
5631
5660
  async checkConfiguration() {
5632
- const socket = await createRemoteClient(this.options);
5633
- socket.disconnect();
5661
+ try {
5662
+ const socket = await createRemoteClient(this.options);
5663
+ socket.disconnect();
5664
+ }
5665
+ catch (error) {
5666
+ if (error instanceof Error) {
5667
+ // Provide user-friendly error messages for common connection issues
5668
+ if (error.message.includes('timeout') || error.message.includes('Timeout')) {
5669
+ throw new Error(`Connection to Promptbook server timed out. This may happen during authentication flows like Facebook login. ` +
5670
+ `Please ensure: 1) Server is running at ${this.options.remoteServerUrl}, ` +
5671
+ `2) Network connection is stable, 3) Authentication process is completed within the timeout period. ` +
5672
+ `Original error: ${error.message}`);
5673
+ }
5674
+ if (error.message.includes('connect') || error.message.includes('ECONNREFUSED')) {
5675
+ throw new Error(`Cannot connect to Promptbook server at ${this.options.remoteServerUrl}. ` +
5676
+ `Please check if the server is running and accessible. ` +
5677
+ `Original error: ${error.message}`);
5678
+ }
5679
+ if (error.message.includes('authentication') || error.message.includes('auth')) {
5680
+ throw new Error(`Authentication failed when connecting to Promptbook server. ` +
5681
+ `This may happen if social login (like Facebook) was not completed properly. ` +
5682
+ `Please retry the authentication process. ` +
5683
+ `Original error: ${error.message}`);
5684
+ }
5685
+ }
5686
+ throw error; // Re-throw if not a recognized error pattern
5687
+ }
5634
5688
  // TODO: [main] !!3 Check version of the remote server and compatibility
5635
5689
  // TODO: [🎍] Send checkConfiguration
5636
5690
  }