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.
- package/mcp/stdio-wrapper.js +72 -68
- package/package.json +1 -1
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -436,89 +436,93 @@ To re-login: npx polydev-ai`
|
|
|
436
436
|
};
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
455
|
-
|
|
459
|
+
if (url.pathname === '/callback') {
|
|
460
|
+
const token = url.searchParams.get('token');
|
|
456
461
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
471
|
-
|
|
475
|
+
console.error('[Polydev] Login successful, token saved');
|
|
476
|
+
console.error('[Polydev] ✓ You can now use Polydev tools!');
|
|
472
477
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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(
|
|
484
|
-
res.end('
|
|
486
|
+
res.writeHead(400, { 'Content-Type': 'text/plain' });
|
|
487
|
+
res.end('Invalid or missing token');
|
|
485
488
|
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
//
|
|
515
|
-
|
|
516
|
-
if (
|
|
517
|
-
console.error('[Polydev]
|
|
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 -
|
|
525
|
+
// Return immediately - server stays alive at this._loginServer
|
|
522
526
|
return {
|
|
523
527
|
jsonrpc: '2.0',
|
|
524
528
|
id,
|