polydev-ai 1.9.29 → 1.9.31
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 +81 -0
- package/package.json +1 -1
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -1658,6 +1658,79 @@ To re-login: /polydev:login`
|
|
|
1658
1658
|
};
|
|
1659
1659
|
}
|
|
1660
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, triggering re-authentication...');
|
|
1690
|
+
return await this.triggerReAuth(request.id, 'Token expired or invalid. Re-authenticating...');
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
return {
|
|
1694
|
+
jsonrpc: '2.0',
|
|
1695
|
+
id: request.id,
|
|
1696
|
+
error: {
|
|
1697
|
+
code: -32603,
|
|
1698
|
+
message: `Remote server error: ${response.status} - ${errorText}`
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
const result = await response.json();
|
|
1704
|
+
console.error(`[Stdio Wrapper] Got response from remote server`);
|
|
1705
|
+
return result;
|
|
1706
|
+
} catch (error) {
|
|
1707
|
+
console.error(`[Stdio Wrapper] Network error:`, error.message);
|
|
1708
|
+
return {
|
|
1709
|
+
jsonrpc: '2.0',
|
|
1710
|
+
id: request.id,
|
|
1711
|
+
error: {
|
|
1712
|
+
code: -32603,
|
|
1713
|
+
message: `Network error: ${error.message}`
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
/**
|
|
1720
|
+
* Check if a tool is a CLI tool that should be handled locally
|
|
1721
|
+
*/
|
|
1722
|
+
isCliTool(toolName) {
|
|
1723
|
+
const cliTools = [
|
|
1724
|
+
'force_cli_detection',
|
|
1725
|
+
'get_cli_status',
|
|
1726
|
+
'send_cli_prompt',
|
|
1727
|
+
'polydev.force_cli_detection',
|
|
1728
|
+
'polydev.get_cli_status',
|
|
1729
|
+
'polydev.send_cli_prompt'
|
|
1730
|
+
];
|
|
1731
|
+
return cliTools.includes(toolName);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1661
1734
|
/**
|
|
1662
1735
|
* Handle get_perspectives with local CLIs + remote perspectives
|
|
1663
1736
|
*/
|
|
@@ -2435,6 +2508,14 @@ To re-login: /polydev:login`
|
|
|
2435
2508
|
return this.getModelPreferenceForCli(providerId);
|
|
2436
2509
|
}
|
|
2437
2510
|
|
|
2511
|
+
/**
|
|
2512
|
+
* Get model for a specific CLI provider
|
|
2513
|
+
*/
|
|
2514
|
+
async getModelForProvider(providerId) {
|
|
2515
|
+
const preferences = await this.fetchUserModelPreferences();
|
|
2516
|
+
return preferences[providerId] || null;
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2438
2519
|
/**
|
|
2439
2520
|
* Call remote perspectives for CLI prompts
|
|
2440
2521
|
* Only calls remote APIs for providers NOT covered by successful local CLIs
|