polydev-ai 1.8.91 → 1.8.92

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.
@@ -436,89 +436,93 @@ To re-login: npx polydev-ai`
436
436
  };
437
437
  }
438
438
 
439
- // Start login server in background (don't block the tool response)
440
- const loginPromise = new Promise((resolve) => {
441
- const server = http.createServer((req, res) => {
442
- const url = new URL(req.url, `http://localhost`);
443
-
444
- if (req.method === 'OPTIONS') {
445
- res.writeHead(204, {
446
- 'Access-Control-Allow-Origin': '*',
447
- 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
448
- 'Access-Control-Allow-Headers': 'Content-Type'
449
- });
450
- res.end();
451
- return;
452
- }
439
+ // Close any existing login server
440
+ if (this._loginServer) {
441
+ try { this._loginServer.close(); } catch (e) {}
442
+ this._loginServer = null;
443
+ }
444
+
445
+ // Create and STORE the server at class level so it stays alive
446
+ this._loginServer = http.createServer((req, res) => {
447
+ const url = new URL(req.url, `http://localhost`);
448
+
449
+ if (req.method === 'OPTIONS') {
450
+ res.writeHead(204, {
451
+ 'Access-Control-Allow-Origin': '*',
452
+ 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
453
+ 'Access-Control-Allow-Headers': 'Content-Type'
454
+ });
455
+ res.end();
456
+ return;
457
+ }
453
458
 
454
- if (url.pathname === '/callback') {
455
- const token = url.searchParams.get('token');
459
+ if (url.pathname === '/callback') {
460
+ const token = url.searchParams.get('token');
456
461
 
457
- if (token && token.startsWith('pd_')) {
458
- // Save token
459
- this.saveTokenToFiles(token);
460
- this.userToken = token;
461
- this.isAuthenticated = true;
462
- this._freshLogin = true;
462
+ if (token && token.startsWith('pd_')) {
463
+ // Save token
464
+ this.saveTokenToFiles(token);
465
+ this.userToken = token;
466
+ this.isAuthenticated = true;
467
+ this._freshLogin = true;
463
468
 
464
- res.writeHead(200, {
465
- 'Content-Type': 'text/html; charset=utf-8',
466
- 'Access-Control-Allow-Origin': '*'
467
- });
468
- res.end(this.getLoginSuccessHTML());
469
+ res.writeHead(200, {
470
+ 'Content-Type': 'text/html; charset=utf-8',
471
+ 'Access-Control-Allow-Origin': '*'
472
+ });
473
+ res.end(this.getLoginSuccessHTML());
469
474
 
470
- console.error('[Polydev] Login successful, token saved');
471
- console.error('[Polydev] ✓ You can now use Polydev tools!');
475
+ console.error('[Polydev] Login successful, token saved');
476
+ console.error('[Polydev] ✓ You can now use Polydev tools!');
472
477
 
473
- // Wait 7 seconds before closing server
474
- setTimeout(() => {
475
- server.close();
476
- resolve(true);
477
- }, 7000);
478
- } else {
479
- res.writeHead(400, { 'Content-Type': 'text/plain' });
480
- res.end('Invalid or missing token');
481
- }
478
+ // Wait 7 seconds before closing server (let browser render success page)
479
+ setTimeout(() => {
480
+ if (this._loginServer) {
481
+ this._loginServer.close();
482
+ this._loginServer = null;
483
+ }
484
+ }, 7000);
482
485
  } else {
483
- res.writeHead(404);
484
- res.end('Not found');
486
+ res.writeHead(400, { 'Content-Type': 'text/plain' });
487
+ res.end('Invalid or missing token');
485
488
  }
486
- });
487
-
488
- server.listen(0, 'localhost', () => {
489
- const port = server.address().port;
490
- const callbackUrl = `http://localhost:${port}/callback`;
491
- const authUrl = `https://polydev.ai/auth?callback=${encodeURIComponent(callbackUrl)}&redirect=ide-plugin&auto=true`;
492
-
493
- console.error(`[Polydev] Opening browser for authentication...`);
494
- console.error(`[Polydev] Auth URL: ${authUrl}`);
495
-
496
- this.openBrowser(authUrl).catch(() => {
497
- console.error('[Polydev] Could not open browser automatically');
498
- console.error('[Polydev] Please open this URL manually:', authUrl);
499
- });
500
- });
489
+ } else {
490
+ res.writeHead(404);
491
+ res.end('Not found');
492
+ }
493
+ });
501
494
 
502
- // Timeout after 5 minutes
503
- setTimeout(() => {
504
- server.close();
505
- resolve(false);
506
- }, 5 * 60 * 1000);
495
+ // Start listening
496
+ this._loginServer.listen(0, 'localhost', () => {
497
+ const port = this._loginServer.address().port;
498
+ const callbackUrl = `http://localhost:${port}/callback`;
499
+ const authUrl = `https://polydev.ai/auth?callback=${encodeURIComponent(callbackUrl)}&redirect=ide-plugin&auto=true`;
507
500
 
508
- server.on('error', (err) => {
509
- console.error('[Polydev] Login server error:', err.message);
510
- resolve(false);
501
+ console.error(`[Polydev] Opening browser for authentication...`);
502
+ console.error(`[Polydev] Callback server listening on port ${port}`);
503
+ console.error(`[Polydev] Auth URL: ${authUrl}`);
504
+
505
+ this.openBrowser(authUrl).catch(() => {
506
+ console.error('[Polydev] Could not open browser automatically');
507
+ console.error('[Polydev] Please open this URL manually:', authUrl);
511
508
  });
512
509
  });
513
510
 
514
- // Don't await - let it run in background
515
- loginPromise.then((success) => {
516
- if (success) {
517
- console.error('[Polydev] Authentication completed successfully!');
511
+ // Timeout after 5 minutes
512
+ this._loginServerTimeout = setTimeout(() => {
513
+ if (this._loginServer) {
514
+ console.error('[Polydev] Login timeout - closing server');
515
+ this._loginServer.close();
516
+ this._loginServer = null;
518
517
  }
518
+ }, 5 * 60 * 1000);
519
+
520
+ this._loginServer.on('error', (err) => {
521
+ console.error('[Polydev] Login server error:', err.message);
522
+ this._loginServer = null;
519
523
  });
520
524
 
521
- // Return immediately - don't wait for auth to complete
525
+ // Return immediately - server stays alive at this._loginServer
522
526
  return {
523
527
  jsonrpc: '2.0',
524
528
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.91",
3
+ "version": "1.8.92",
4
4
  "engines": {
5
5
  "node": ">=20.x <=22.x"
6
6
  },