polydev-ai 1.8.90 → 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.
Files changed (2) hide show
  1. package/mcp/stdio-wrapper.js +107 -117
  2. package/package.json +2 -2
@@ -410,18 +410,16 @@ class StdioMCPWrapper {
410
410
  */
411
411
  async handleLoginTool(params, id) {
412
412
  const http = require('http');
413
- const { spawn } = require('child_process');
414
413
 
415
- return new Promise((resolve) => {
416
- // Check if already authenticated
417
- if (this.isAuthenticated && this.userToken) {
418
- resolve({
419
- jsonrpc: '2.0',
420
- id,
421
- result: {
422
- content: [{
423
- type: 'text',
424
- text: `╭─────────────────────────────────────────╮
414
+ // Check if already authenticated
415
+ if (this.isAuthenticated && this.userToken) {
416
+ return {
417
+ jsonrpc: '2.0',
418
+ id,
419
+ result: {
420
+ content: [{
421
+ type: 'text',
422
+ text: `╭─────────────────────────────────────────╮
425
423
  │ ALREADY AUTHENTICATED ✓ │
426
424
  ╰─────────────────────────────────────────╯
427
425
 
@@ -433,128 +431,120 @@ class StdioMCPWrapper {
433
431
  • get_perspectives - Direct tool call
434
432
 
435
433
  To re-login: npx polydev-ai`
436
- }]
437
- }
434
+ }]
435
+ }
436
+ };
437
+ }
438
+
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'
438
454
  });
455
+ res.end();
439
456
  return;
440
457
  }
441
-
442
- const server = http.createServer((req, res) => {
443
- const url = new URL(req.url, `http://localhost`);
444
-
445
- if (req.method === 'OPTIONS') {
446
- res.writeHead(204, {
447
- 'Access-Control-Allow-Origin': '*',
448
- 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
449
- 'Access-Control-Allow-Headers': 'Content-Type'
450
- });
451
- res.end();
452
- return;
453
- }
454
458
 
455
- if (url.pathname === '/callback') {
456
- const token = url.searchParams.get('token');
459
+ if (url.pathname === '/callback') {
460
+ const token = url.searchParams.get('token');
457
461
 
458
- if (token && token.startsWith('pd_')) {
459
- // Save token
460
- this.saveTokenToFiles(token);
461
- this.userToken = token;
462
- this.isAuthenticated = true;
463
- this._freshLogin = true; // Flag for opening models page after CLI detection
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;
464
468
 
465
- res.writeHead(200, {
466
- 'Content-Type': 'text/html; charset=utf-8',
467
- 'Access-Control-Allow-Origin': '*'
468
- });
469
- 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());
470
474
 
471
- console.error('[Polydev] Login successful, token saved');
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 (gives time for 5s auto-close countdown + buffer)
474
- setTimeout(() => {
475
- server.close();
476
- resolve({
477
- jsonrpc: '2.0',
478
- id,
479
- result: {
480
- content: [{
481
- type: 'text',
482
- text: `╭─────────────────────────────────────────╮
483
- LOGIN SUCCESSFUL! ✓ │
484
- ╰─────────────────────────────────────────╯
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);
485
+ } else {
486
+ res.writeHead(400, { 'Content-Type': 'text/plain' });
487
+ res.end('Invalid or missing token');
488
+ }
489
+ } else {
490
+ res.writeHead(404);
491
+ res.end('Not found');
492
+ }
493
+ });
485
494
 
486
- 🔐 Token saved to:
487
- ~/.polydev.env
488
- ~/.zshrc
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`;
489
500
 
490
- ⚠️ IMPORTANT: Restart your IDE to activate.
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);
508
+ });
509
+ });
491
510
 
492
- 🤖 After restart, you can:
493
- Use /polydev:ask to query multiple AI models
494
- Use /polydev:auth to check status & credits
495
- Use get_perspectives tool directly
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;
517
+ }
518
+ }, 5 * 60 * 1000);
496
519
 
497
- 📊 Dashboard: https://polydev.ai/dashboard`
498
- }]
499
- }
500
- });
501
- }, 7000);
502
- } else {
503
- res.writeHead(400, { 'Content-Type': 'text/plain' });
504
- res.end('Invalid or missing token');
505
- }
506
- } else {
507
- res.writeHead(404);
508
- res.end('Not found');
509
- }
510
- });
520
+ this._loginServer.on('error', (err) => {
521
+ console.error('[Polydev] Login server error:', err.message);
522
+ this._loginServer = null;
523
+ });
511
524
 
512
- server.listen(0, 'localhost', () => {
513
- const port = server.address().port;
514
- const callbackUrl = `http://localhost:${port}/callback`;
515
- const authUrl = `https://polydev.ai/auth?callback=${encodeURIComponent(callbackUrl)}&redirect=ide-plugin&auto=true`;
525
+ // Return immediately - server stays alive at this._loginServer
526
+ return {
527
+ jsonrpc: '2.0',
528
+ id,
529
+ result: {
530
+ content: [{
531
+ type: 'text',
532
+ text: `╭─────────────────────────────────────────╮
533
+ │ BROWSER OPENED FOR LOGIN 🌐 │
534
+ ╰─────────────────────────────────────────╯
516
535
 
517
- console.error(`[Polydev] Opening browser for authentication: ${authUrl}`);
518
-
519
- // Best-in-class browser opening using 'open' package (cross-platform)
520
- // Falls back to platform-specific commands if package fails
521
- this.openBrowser(authUrl).catch(() => {
522
- console.error('[Polydev] All browser open methods failed');
523
- console.error('[Polydev] Please open this URL manually:', authUrl);
524
- });
536
+ 📱 Complete authentication in your browser.
525
537
 
526
- // Timeout after 5 minutes
527
- setTimeout(() => {
528
- server.close();
529
- resolve({
530
- jsonrpc: '2.0',
531
- id,
532
- result: {
533
- content: [{
534
- type: 'text',
535
- text: `Login timed out.\n\nPlease try again or run in terminal: npx polydev-ai`
536
- }],
537
- isError: true
538
- }
539
- });
540
- }, 5 * 60 * 1000);
541
- });
538
+ After login:
539
+ Token will be saved automatically
540
+ • You'll see a success page with auto-close
541
+ • Return here and the tools will be ready!
542
542
 
543
- server.on('error', (err) => {
544
- console.error('[Polydev] Login server error:', err.message);
545
- resolve({
546
- jsonrpc: '2.0',
547
- id,
548
- result: {
549
- content: [{
550
- type: 'text',
551
- text: `Login failed: ${err.message}\n\nPlease run in terminal: npx polydev-ai`
552
- }],
553
- isError: true
554
- }
555
- });
556
- });
557
- });
543
+ Waiting for authentication...
544
+ (Server listening for up to 5 minutes)`
545
+ }]
546
+ }
547
+ };
558
548
  }
559
549
 
560
550
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polydev-ai",
3
- "version": "1.8.90",
3
+ "version": "1.8.92",
4
4
  "engines": {
5
5
  "node": ">=20.x <=22.x"
6
6
  },
@@ -74,7 +74,7 @@
74
74
  "marked": "^16.2.1",
75
75
  "next": "^15.5.7",
76
76
  "open": "^11.0.0",
77
- "polydev-ai": "^1.8.42",
77
+ "polydev-ai": "^1.8.90",
78
78
  "posthog-js": "^1.157.2",
79
79
  "prismjs": "^1.30.0",
80
80
  "react": "^18.3.1",