polydev-ai 1.9.1 → 1.9.3
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/lib/cliManager.js +7 -7
- package/mcp/server.js +44 -0
- package/mcp/stdio-wrapper.js +55 -3
- package/package.json +1 -1
package/lib/cliManager.js
CHANGED
|
@@ -429,16 +429,16 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
async sendCliPrompt(providerId, prompt, mode = 'args', timeoutMs = null, model = null) {
|
|
432
|
-
// Set default timeout for CLI
|
|
433
|
-
//
|
|
432
|
+
// Set default timeout for CLI responses (240 seconds / 4 minutes)
|
|
433
|
+
// CLI-within-CLI scenarios (Claude Code calling Claude Code) need generous timeouts
|
|
434
434
|
if (timeoutMs === null) {
|
|
435
|
-
timeoutMs =
|
|
435
|
+
timeoutMs = 240000; // 240 seconds (4 minutes) default for CLI responses
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
// Ensure timeoutMs is valid (not undefined, null, Infinity, or negative)
|
|
439
439
|
// Allow up to 600 seconds (10 minutes) for very complex operations
|
|
440
440
|
if (!timeoutMs || timeoutMs === Infinity || timeoutMs < 1 || timeoutMs > 600000) {
|
|
441
|
-
timeoutMs =
|
|
441
|
+
timeoutMs = 240000 // Default to 240 seconds (4 minutes) for CLI responses
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
const startTime = Date.now();
|
|
@@ -777,11 +777,11 @@ This is a known issue with @google/gemini-cli@0.3.4 and older Node.js versions.`
|
|
|
777
777
|
}
|
|
778
778
|
}
|
|
779
779
|
|
|
780
|
-
async executeCliCommand(command, args, mode = 'args', timeoutMs =
|
|
780
|
+
async executeCliCommand(command, args, mode = 'args', timeoutMs = 240000, stdinInput) {
|
|
781
781
|
// Ensure timeoutMs is valid (not undefined, null, Infinity, or negative)
|
|
782
|
-
//
|
|
782
|
+
// 240 seconds (4 minutes) default for CLI responses
|
|
783
783
|
if (!timeoutMs || timeoutMs === Infinity || timeoutMs < 1 || timeoutMs > 600000) {
|
|
784
|
-
timeoutMs =
|
|
784
|
+
timeoutMs = 240000 // Default to 240 seconds (4 minutes)
|
|
785
785
|
}
|
|
786
786
|
|
|
787
787
|
return new Promise((resolve, reject) => {
|
package/mcp/server.js
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// Ensure fetch is available (polyfill for environments where native fetch is missing)
|
|
4
|
+
if (typeof globalThis.fetch === 'undefined') {
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const http = require('http');
|
|
7
|
+
const { URL } = require('url');
|
|
8
|
+
|
|
9
|
+
globalThis.fetch = function fetchPolyfill(url, options = {}) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const parsed = new URL(url);
|
|
12
|
+
const mod = parsed.protocol === 'https:' ? https : http;
|
|
13
|
+
const reqOptions = {
|
|
14
|
+
hostname: parsed.hostname,
|
|
15
|
+
port: parsed.port,
|
|
16
|
+
path: parsed.pathname + parsed.search,
|
|
17
|
+
method: options.method || 'GET',
|
|
18
|
+
headers: options.headers || {}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const req = mod.request(reqOptions, (res) => {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
24
|
+
res.on('end', () => {
|
|
25
|
+
const body = Buffer.concat(chunks).toString('utf8');
|
|
26
|
+
resolve({
|
|
27
|
+
ok: res.statusCode >= 200 && res.statusCode < 300,
|
|
28
|
+
status: res.statusCode,
|
|
29
|
+
statusText: res.statusMessage,
|
|
30
|
+
headers: { get: (name) => res.headers[name.toLowerCase()] },
|
|
31
|
+
json: () => Promise.resolve(JSON.parse(body)),
|
|
32
|
+
text: () => Promise.resolve(body)
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
req.on('error', reject);
|
|
38
|
+
req.setTimeout(30000, () => { req.destroy(); reject(new Error('Request timed out')); });
|
|
39
|
+
if (options.body) req.write(options.body);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
console.error('[Polydev MCP] fetch polyfill loaded (native fetch unavailable)');
|
|
45
|
+
}
|
|
46
|
+
|
|
3
47
|
// Register ts-node for TypeScript support
|
|
4
48
|
try {
|
|
5
49
|
require('ts-node/register');
|
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// Ensure fetch is available (polyfill for environments where native fetch is missing)
|
|
4
|
+
if (typeof globalThis.fetch === 'undefined') {
|
|
5
|
+
const https = require('https');
|
|
6
|
+
const http = require('http');
|
|
7
|
+
const { URL } = require('url');
|
|
8
|
+
|
|
9
|
+
globalThis.fetch = function fetchPolyfill(url, options = {}) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const parsed = new URL(url);
|
|
12
|
+
const mod = parsed.protocol === 'https:' ? https : http;
|
|
13
|
+
const reqOptions = {
|
|
14
|
+
hostname: parsed.hostname,
|
|
15
|
+
port: parsed.port,
|
|
16
|
+
path: parsed.pathname + parsed.search,
|
|
17
|
+
method: options.method || 'GET',
|
|
18
|
+
headers: options.headers || {}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const req = mod.request(reqOptions, (res) => {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
24
|
+
res.on('end', () => {
|
|
25
|
+
const body = Buffer.concat(chunks).toString('utf8');
|
|
26
|
+
resolve({
|
|
27
|
+
ok: res.statusCode >= 200 && res.statusCode < 300,
|
|
28
|
+
status: res.statusCode,
|
|
29
|
+
statusText: res.statusMessage,
|
|
30
|
+
headers: { get: (name) => res.headers[name.toLowerCase()] },
|
|
31
|
+
json: () => Promise.resolve(JSON.parse(body)),
|
|
32
|
+
text: () => Promise.resolve(body)
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
req.on('error', reject);
|
|
38
|
+
req.setTimeout(240000, () => { req.destroy(); reject(new Error('Request timed out')); });
|
|
39
|
+
if (options.body) req.write(options.body);
|
|
40
|
+
req.end();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
console.error('[Polydev MCP] fetch polyfill loaded (native fetch unavailable)');
|
|
45
|
+
}
|
|
46
|
+
|
|
3
47
|
// Lightweight stdio wrapper with local CLI functionality and remote Polydev MCP server fallback
|
|
4
48
|
const fs = require('fs');
|
|
5
49
|
const path = require('path');
|
|
@@ -1126,6 +1170,10 @@ Error: ${error.message}`
|
|
|
1126
1170
|
console.error(`[Stdio Wrapper] Forwarding request to remote server`);
|
|
1127
1171
|
|
|
1128
1172
|
try {
|
|
1173
|
+
// Use AbortController for timeout if available, otherwise rely on fetch timeout
|
|
1174
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
1175
|
+
const timeoutId = controller ? setTimeout(() => controller.abort(), 240000) : null; // 240s timeout
|
|
1176
|
+
|
|
1129
1177
|
const response = await fetch('https://www.polydev.ai/api/mcp', {
|
|
1130
1178
|
method: 'POST',
|
|
1131
1179
|
headers: {
|
|
@@ -1133,9 +1181,12 @@ Error: ${error.message}`
|
|
|
1133
1181
|
'Authorization': `Bearer ${this.userToken}`,
|
|
1134
1182
|
'User-Agent': 'polydev-stdio-wrapper/1.0.0'
|
|
1135
1183
|
},
|
|
1136
|
-
body: JSON.stringify(request)
|
|
1184
|
+
body: JSON.stringify(request),
|
|
1185
|
+
...(controller ? { signal: controller.signal } : {})
|
|
1137
1186
|
});
|
|
1138
1187
|
|
|
1188
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1189
|
+
|
|
1139
1190
|
if (!response.ok) {
|
|
1140
1191
|
const errorText = await response.text();
|
|
1141
1192
|
console.error(`[Stdio Wrapper] Remote server error: ${response.status} - ${errorText}`);
|
|
@@ -1613,8 +1664,9 @@ Error: ${error.message}`
|
|
|
1613
1664
|
console.error('[Polydev] CLI detection ready, proceeding with request');
|
|
1614
1665
|
}
|
|
1615
1666
|
|
|
1616
|
-
|
|
1617
|
-
|
|
1667
|
+
// Use cached status (refreshed by smart scheduler) instead of forceCliDetection on every request
|
|
1668
|
+
const results = await this.cliManager.getCliStatus();
|
|
1669
|
+
console.error(`[Stdio Wrapper] CLI status (cached):`, JSON.stringify(results, null, 2));
|
|
1618
1670
|
const availableProviders = [];
|
|
1619
1671
|
const unavailableProviders = [];
|
|
1620
1672
|
|