@promptbook/wizard 0.98.0-9 → 0.99.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/esm/index.es.js CHANGED
@@ -38,7 +38,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
38
38
  * @generated
39
39
  * @see https://github.com/webgptorg/promptbook
40
40
  */
41
- const PROMPTBOOK_ENGINE_VERSION = '0.98.0-9';
41
+ const PROMPTBOOK_ENGINE_VERSION = '0.99.0-0';
42
42
  /**
43
43
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
44
44
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -192,9 +192,12 @@ const SMALL_NUMBER = 0.001;
192
192
  /**
193
193
  * Timeout for the connections in milliseconds
194
194
  *
195
+ * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
196
+ * like Facebook login which may require user interaction and redirects
197
+ *
195
198
  * @private within the repository - too low-level in comparison with other `MAX_...`
196
199
  */
197
- const CONNECTION_TIMEOUT_MS = 7 * 1000;
200
+ const CONNECTION_TIMEOUT_MS = 30 * 1000;
198
201
  // <- TODO: [⏳] Standardize timeouts, Make DEFAULT_TIMEOUT_MS as global constant
199
202
  /**
200
203
  * How many times to retry the connections
@@ -1386,13 +1389,39 @@ async function createRemoteClient(options) {
1386
1389
  transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
1387
1390
  });
1388
1391
  // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
1392
+ let isResolved = false;
1389
1393
  socket.on('connect', () => {
1390
- resolve(socket);
1394
+ if (!isResolved) {
1395
+ isResolved = true;
1396
+ resolve(socket);
1397
+ }
1398
+ });
1399
+ socket.on('connect_error', (error) => {
1400
+ if (!isResolved) {
1401
+ isResolved = true;
1402
+ reject(new Error(`Failed to connect to ${remoteServerUrl}: ${error.message || error}`));
1403
+ }
1404
+ });
1405
+ socket.on('disconnect', (reason) => {
1406
+ if (!isResolved) {
1407
+ isResolved = true;
1408
+ reject(new Error(`Connection to ${remoteServerUrl} was disconnected: ${reason}`));
1409
+ }
1391
1410
  });
1392
- // TODO: [💩] Better timeout handling
1393
- setTimeout(() => {
1394
- reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
1411
+ // Better timeout handling with more descriptive error message
1412
+ const timeoutId = setTimeout(() => {
1413
+ if (!isResolved) {
1414
+ isResolved = true;
1415
+ socket.disconnect();
1416
+ reject(new Error(`Connection timeout after ${CONNECTION_TIMEOUT_MS / 1000} seconds while connecting to ${remoteServerUrl}. ` +
1417
+ `This may indicate network issues or the server may be experiencing high load. ` +
1418
+ `For authentication flows like social login, ensure sufficient time is allowed for user interaction.`));
1419
+ }
1395
1420
  }, CONNECTION_TIMEOUT_MS);
1421
+ // Clean up timeout if connection succeeds
1422
+ socket.on('connect', () => {
1423
+ clearTimeout(timeoutId);
1424
+ });
1396
1425
  });
1397
1426
  }
1398
1427
 
@@ -1438,8 +1467,33 @@ class RemoteLlmExecutionTools {
1438
1467
  * Check the configuration of all execution tools
1439
1468
  */
1440
1469
  async checkConfiguration() {
1441
- const socket = await createRemoteClient(this.options);
1442
- socket.disconnect();
1470
+ try {
1471
+ const socket = await createRemoteClient(this.options);
1472
+ socket.disconnect();
1473
+ }
1474
+ catch (error) {
1475
+ if (error instanceof Error) {
1476
+ // Provide user-friendly error messages for common connection issues
1477
+ if (error.message.includes('timeout') || error.message.includes('Timeout')) {
1478
+ throw new Error(`Connection to Promptbook server timed out. This may happen during authentication flows like Facebook login. ` +
1479
+ `Please ensure: 1) Server is running at ${this.options.remoteServerUrl}, ` +
1480
+ `2) Network connection is stable, 3) Authentication process is completed within the timeout period. ` +
1481
+ `Original error: ${error.message}`);
1482
+ }
1483
+ if (error.message.includes('connect') || error.message.includes('ECONNREFUSED')) {
1484
+ throw new Error(`Cannot connect to Promptbook server at ${this.options.remoteServerUrl}. ` +
1485
+ `Please check if the server is running and accessible. ` +
1486
+ `Original error: ${error.message}`);
1487
+ }
1488
+ if (error.message.includes('authentication') || error.message.includes('auth')) {
1489
+ throw new Error(`Authentication failed when connecting to Promptbook server. ` +
1490
+ `This may happen if social login (like Facebook) was not completed properly. ` +
1491
+ `Please retry the authentication process. ` +
1492
+ `Original error: ${error.message}`);
1493
+ }
1494
+ }
1495
+ throw error; // Re-throw if not a recognized error pattern
1496
+ }
1443
1497
  // TODO: [main] !!3 Check version of the remote server and compatibility
1444
1498
  // TODO: [🎍] Send checkConfiguration
1445
1499
  }
@@ -5113,6 +5167,7 @@ const _OpenAiCompatibleMetadataRegistration = $llmToolsMetadataRegister.register
5113
5167
  options: {
5114
5168
  apiKey: 'sk-',
5115
5169
  baseURL: 'https://api.openai.com/v1',
5170
+ defaultModelName: 'gpt-4-turbo',
5116
5171
  isProxied: false,
5117
5172
  remoteServerUrl: DEFAULT_REMOTE_SERVER_URL,
5118
5173
  maxRequestsPerMinute: DEFAULT_MAX_REQUESTS_PER_MINUTE,
@@ -12130,9 +12185,10 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
12130
12185
  .list()
12131
12186
  .find(({ packageName, className }) => llmConfiguration.packageName === packageName && llmConfiguration.className === className);
12132
12187
  if (registeredItem === undefined) {
12133
- console.log('!!! $llmToolsRegister.list()', $llmToolsRegister.list());
12188
+ // console.log('$llmToolsRegister.list()', $llmToolsRegister.list());
12134
12189
  throw new Error(spaceTrim((block) => `
12135
12190
  There is no constructor for LLM provider \`${llmConfiguration.className}\` from \`${llmConfiguration.packageName}\`
12191
+ Running in ${!$isRunningInBrowser() ? '' : 'browser environment'}${!$isRunningInNode() ? '' : 'node environment'}${!$isRunningInWebWorker() ? '' : 'worker environment'}
12136
12192
 
12137
12193
  You have probably forgotten install and import the provider package.
12138
12194
  To fix this issue, you can: