polydev-ai 1.9.28 → 1.9.30
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 +128 -2
- package/package.json +1 -1
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -1633,8 +1633,7 @@ To re-login: /polydev:login`
|
|
|
1633
1633
|
|
|
1634
1634
|
/**
|
|
1635
1635
|
* Start a periodic progress heartbeat to prevent client-side timeouts.
|
|
1636
|
-
* Sends a progress notification every intervalMs to
|
|
1637
|
-
* Compatible MCP clients will reset their timeout clock on each notification.
|
|
1636
|
+
* Sends a progress notification every intervalMs to keep the connection alive
|
|
1638
1637
|
* @param {string|number} progressToken - Token from request's _meta.progressToken
|
|
1639
1638
|
* @param {number} intervalMs - Heartbeat interval in milliseconds (default: 10s)
|
|
1640
1639
|
* @returns {{ stop: Function, tick: Function }} Controller to stop heartbeat and manually tick progress
|
|
@@ -1659,6 +1658,86 @@ To re-login: /polydev:login`
|
|
|
1659
1658
|
};
|
|
1660
1659
|
}
|
|
1661
1660
|
|
|
1661
|
+
/**
|
|
1662
|
+
* Forward a request to the remote Polydev API server
|
|
1663
|
+
*/
|
|
1664
|
+
async forwardToRemoteServer(request) {
|
|
1665
|
+
console.error(`[Stdio Wrapper] Forwarding request to remote server`);
|
|
1666
|
+
|
|
1667
|
+
try {
|
|
1668
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
1669
|
+
const timeoutId = controller ? setTimeout(() => controller.abort(), 400000) : null; // 400s timeout
|
|
1670
|
+
|
|
1671
|
+
const response = await fetch('https://www.polydev.ai/api/mcp', {
|
|
1672
|
+
method: 'POST',
|
|
1673
|
+
headers: {
|
|
1674
|
+
'Content-Type': 'application/json',
|
|
1675
|
+
'Authorization': `Bearer ${this.userToken}`,
|
|
1676
|
+
'User-Agent': 'polydev-stdio-wrapper/1.0.0'
|
|
1677
|
+
},
|
|
1678
|
+
body: JSON.stringify(request),
|
|
1679
|
+
...(controller ? { signal: controller.signal } : {})
|
|
1680
|
+
});
|
|
1681
|
+
|
|
1682
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1683
|
+
|
|
1684
|
+
if (!response.ok) {
|
|
1685
|
+
const errorText = await response.text();
|
|
1686
|
+
console.error(`[Stdio Wrapper] Remote server error: ${response.status} - ${errorText}`);
|
|
1687
|
+
|
|
1688
|
+
if (response.status === 401) {
|
|
1689
|
+
console.error('[Polydev] Remote API returned 401 — token expired or invalid.');
|
|
1690
|
+
return {
|
|
1691
|
+
jsonrpc: '2.0',
|
|
1692
|
+
id: request.id,
|
|
1693
|
+
error: {
|
|
1694
|
+
code: -32603,
|
|
1695
|
+
message: 'Authentication expired. Use the "login" tool to re-authenticate.'
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
return {
|
|
1701
|
+
jsonrpc: '2.0',
|
|
1702
|
+
id: request.id,
|
|
1703
|
+
error: {
|
|
1704
|
+
code: -32603,
|
|
1705
|
+
message: `Remote server error: ${response.status} - ${errorText}`
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const result = await response.json();
|
|
1711
|
+
console.error(`[Stdio Wrapper] Got response from remote server`);
|
|
1712
|
+
return result;
|
|
1713
|
+
} catch (error) {
|
|
1714
|
+
console.error(`[Stdio Wrapper] Network error:`, error.message);
|
|
1715
|
+
return {
|
|
1716
|
+
jsonrpc: '2.0',
|
|
1717
|
+
id: request.id,
|
|
1718
|
+
error: {
|
|
1719
|
+
code: -32603,
|
|
1720
|
+
message: `Network error: ${error.message}`
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/**
|
|
1727
|
+
* Check if a tool is a CLI tool that should be handled locally
|
|
1728
|
+
*/
|
|
1729
|
+
isCliTool(toolName) {
|
|
1730
|
+
const cliTools = [
|
|
1731
|
+
'force_cli_detection',
|
|
1732
|
+
'get_cli_status',
|
|
1733
|
+
'send_cli_prompt',
|
|
1734
|
+
'polydev.force_cli_detection',
|
|
1735
|
+
'polydev.get_cli_status',
|
|
1736
|
+
'polydev.send_cli_prompt'
|
|
1737
|
+
];
|
|
1738
|
+
return cliTools.includes(toolName);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1662
1741
|
/**
|
|
1663
1742
|
* Handle get_perspectives with local CLIs + remote perspectives
|
|
1664
1743
|
*/
|
|
@@ -2436,6 +2515,14 @@ To re-login: /polydev:login`
|
|
|
2436
2515
|
return this.getModelPreferenceForCli(providerId);
|
|
2437
2516
|
}
|
|
2438
2517
|
|
|
2518
|
+
/**
|
|
2519
|
+
* Get model for a specific CLI provider
|
|
2520
|
+
*/
|
|
2521
|
+
async getModelForProvider(providerId) {
|
|
2522
|
+
const preferences = await this.fetchUserModelPreferences();
|
|
2523
|
+
return preferences[providerId] || null;
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2439
2526
|
/**
|
|
2440
2527
|
* Call remote perspectives for CLI prompts
|
|
2441
2528
|
* Only calls remote APIs for providers NOT covered by successful local CLIs
|
|
@@ -3213,6 +3300,45 @@ To re-login: /polydev:login`
|
|
|
3213
3300
|
}
|
|
3214
3301
|
}
|
|
3215
3302
|
|
|
3303
|
+
/**
|
|
3304
|
+
* Verify token and display auth status
|
|
3305
|
+
*/
|
|
3306
|
+
async verifyAndDisplayAuth() {
|
|
3307
|
+
try {
|
|
3308
|
+
const response = await fetch('https://www.polydev.ai/api/mcp', {
|
|
3309
|
+
method: 'POST',
|
|
3310
|
+
headers: {
|
|
3311
|
+
'Content-Type': 'application/json',
|
|
3312
|
+
'Authorization': `Bearer ${this.userToken}`,
|
|
3313
|
+
'User-Agent': 'polydev-mcp/1.0.0'
|
|
3314
|
+
},
|
|
3315
|
+
body: JSON.stringify({ action: 'check_status' })
|
|
3316
|
+
});
|
|
3317
|
+
|
|
3318
|
+
if (response.ok) {
|
|
3319
|
+
const data = await response.json();
|
|
3320
|
+
const credits = data.credits_remaining?.toLocaleString() || 0;
|
|
3321
|
+
const tier = data.subscription_tier || 'Free';
|
|
3322
|
+
|
|
3323
|
+
console.error('─'.repeat(50));
|
|
3324
|
+
console.error('Polydev - Authenticated');
|
|
3325
|
+
console.error('─'.repeat(50));
|
|
3326
|
+
console.error(`Account: ${data.email || 'Connected'}`);
|
|
3327
|
+
console.error(`Credits: ${credits} | Tier: ${tier}`);
|
|
3328
|
+
console.error('─'.repeat(50) + '\n');
|
|
3329
|
+
} else {
|
|
3330
|
+
console.error('─'.repeat(50));
|
|
3331
|
+
console.error('Polydev - Token may be invalid');
|
|
3332
|
+
console.error('─'.repeat(50));
|
|
3333
|
+
console.error('Server returned non-OK. Will re-verify on next auth check.');
|
|
3334
|
+
console.error('Use the "login" tool or run: npx polydev-ai login');
|
|
3335
|
+
console.error('─'.repeat(50) + '\n');
|
|
3336
|
+
}
|
|
3337
|
+
} catch (error) {
|
|
3338
|
+
console.error('[Polydev] Could not verify auth (offline?):', error.message || 'unknown');
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3216
3342
|
/**
|
|
3217
3343
|
* Display CLI tools status after detection
|
|
3218
3344
|
*/
|