polydev-ai 1.8.17 → 1.8.18
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 +50 -12
- package/package.json +1 -1
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -245,6 +245,7 @@ class StdioMCPWrapper {
|
|
|
245
245
|
|
|
246
246
|
// Cache for user model preferences (provider -> model)
|
|
247
247
|
this.userModelPreferences = null;
|
|
248
|
+
this.perspectivesPerMessage = 2; // Default to 2 perspectives
|
|
248
249
|
this.modelPreferencesCacheTime = null;
|
|
249
250
|
this.MODEL_PREFERENCES_CACHE_TTL = 5 * 60 * 1000; // 5 minutes cache
|
|
250
251
|
}
|
|
@@ -564,6 +565,7 @@ class StdioMCPWrapper {
|
|
|
564
565
|
|
|
565
566
|
/**
|
|
566
567
|
* Local CLI prompt sending with ALL available CLIs + remote perspectives
|
|
568
|
+
* Respects user's perspectives_per_message setting for total perspectives
|
|
567
569
|
*/
|
|
568
570
|
async localSendCliPrompt(args) {
|
|
569
571
|
console.error(`[Stdio Wrapper] Local CLI prompt sending with perspectives`);
|
|
@@ -585,6 +587,7 @@ class StdioMCPWrapper {
|
|
|
585
587
|
const gracefulTimeout = Math.min(timeout_ms, 600000);
|
|
586
588
|
|
|
587
589
|
// Fetch user's model preferences (cached, non-blocking on failure)
|
|
590
|
+
// This also fetches perspectivesPerMessage setting
|
|
588
591
|
let modelPreferences = {};
|
|
589
592
|
try {
|
|
590
593
|
modelPreferences = await this.fetchUserModelPreferences();
|
|
@@ -592,6 +595,10 @@ class StdioMCPWrapper {
|
|
|
592
595
|
console.error('[Stdio Wrapper] Model preferences fetch failed (will use CLI defaults):', prefError.message);
|
|
593
596
|
}
|
|
594
597
|
|
|
598
|
+
// Get the user's perspectives_per_message setting (default 2)
|
|
599
|
+
const maxPerspectives = this.perspectivesPerMessage || 2;
|
|
600
|
+
console.error(`[Stdio Wrapper] Max perspectives per message: ${maxPerspectives}`);
|
|
601
|
+
|
|
595
602
|
let localResults = [];
|
|
596
603
|
|
|
597
604
|
if (provider_id) {
|
|
@@ -606,15 +613,18 @@ class StdioMCPWrapper {
|
|
|
606
613
|
const result = await this.cliManager.sendCliPrompt(provider_id, prompt, mode, gracefulTimeout, model);
|
|
607
614
|
localResults = [{ provider_id, ...result }];
|
|
608
615
|
} else {
|
|
609
|
-
// No specific provider - use
|
|
610
|
-
console.error(`[Stdio Wrapper] Using
|
|
611
|
-
const
|
|
616
|
+
// No specific provider - use available local CLIs up to maxPerspectives limit
|
|
617
|
+
console.error(`[Stdio Wrapper] Using available local CLIs (max: ${maxPerspectives})`);
|
|
618
|
+
const allAvailableProviders = await this.getAllAvailableProviders();
|
|
619
|
+
|
|
620
|
+
// Limit to maxPerspectives
|
|
621
|
+
const availableProviders = allAvailableProviders.slice(0, maxPerspectives);
|
|
612
622
|
|
|
613
623
|
if (availableProviders.length === 0) {
|
|
614
624
|
console.error(`[Stdio Wrapper] No local CLIs available, will use remote perspectives only`);
|
|
615
625
|
localResults = [];
|
|
616
626
|
} else {
|
|
617
|
-
console.error(`[Stdio Wrapper] Found ${
|
|
627
|
+
console.error(`[Stdio Wrapper] Found ${allAvailableProviders.length} available CLIs, using ${availableProviders.length}: ${availableProviders.join(', ')}`);
|
|
618
628
|
|
|
619
629
|
// Run all CLI prompts concurrently
|
|
620
630
|
const cliPromises = availableProviders.map(async (providerId) => {
|
|
@@ -645,8 +655,25 @@ class StdioMCPWrapper {
|
|
|
645
655
|
console.error('[Stdio Wrapper] CLI results reporting failed (non-critical):', err.message);
|
|
646
656
|
});
|
|
647
657
|
|
|
648
|
-
//
|
|
649
|
-
const
|
|
658
|
+
// Calculate how many successful local perspectives we got
|
|
659
|
+
const successfulLocalCount = localResults.filter(r => r.success).length;
|
|
660
|
+
const remainingPerspectives = maxPerspectives - successfulLocalCount;
|
|
661
|
+
|
|
662
|
+
// Get remote perspectives only if we need more perspectives to reach maxPerspectives
|
|
663
|
+
let perspectivesResult;
|
|
664
|
+
if (remainingPerspectives > 0) {
|
|
665
|
+
console.error(`[Stdio Wrapper] Need ${remainingPerspectives} more perspectives from remote`);
|
|
666
|
+
perspectivesResult = await this.callPerspectivesForCli(args, localResults, remainingPerspectives);
|
|
667
|
+
} else {
|
|
668
|
+
console.error(`[Stdio Wrapper] Already have ${successfulLocalCount} perspectives, skipping remote call`);
|
|
669
|
+
perspectivesResult = {
|
|
670
|
+
success: true,
|
|
671
|
+
content: '',
|
|
672
|
+
skipped: true,
|
|
673
|
+
reason: `Already have ${successfulLocalCount} perspectives (max: ${maxPerspectives})`,
|
|
674
|
+
timestamp: new Date().toISOString()
|
|
675
|
+
};
|
|
676
|
+
}
|
|
650
677
|
|
|
651
678
|
// Record usage for all CLI responses
|
|
652
679
|
for (const localResult of localResults) {
|
|
@@ -782,8 +809,11 @@ class StdioMCPWrapper {
|
|
|
782
809
|
/**
|
|
783
810
|
* Call remote perspectives for CLI prompts
|
|
784
811
|
* Only calls remote APIs for providers NOT covered by successful local CLIs
|
|
812
|
+
* @param {Object} args - Original request arguments
|
|
813
|
+
* @param {Array} localResults - Results from local CLIs
|
|
814
|
+
* @param {number} maxPerspectives - Maximum number of remote perspectives to fetch
|
|
785
815
|
*/
|
|
786
|
-
async callPerspectivesForCli(args, localResults) {
|
|
816
|
+
async callPerspectivesForCli(args, localResults, maxPerspectives = 2) {
|
|
787
817
|
// Determine which providers succeeded locally
|
|
788
818
|
const successfulLocalProviders = localResults
|
|
789
819
|
.filter(r => r.success)
|
|
@@ -800,20 +830,21 @@ class StdioMCPWrapper {
|
|
|
800
830
|
.map(cli => cliToApiProvider[cli])
|
|
801
831
|
.filter(Boolean);
|
|
802
832
|
|
|
803
|
-
// If all major providers are covered locally, skip remote call
|
|
804
|
-
if (
|
|
833
|
+
// If all major providers are covered locally OR we don't need more perspectives, skip remote call
|
|
834
|
+
if (maxPerspectives <= 0 ||
|
|
835
|
+
excludeProviders.length >= 3 ||
|
|
805
836
|
(excludeProviders.includes('anthropic') && excludeProviders.includes('openai') && excludeProviders.includes('google'))) {
|
|
806
|
-
console.error(`[Stdio Wrapper] All providers covered by local CLIs, skipping remote perspectives`);
|
|
837
|
+
console.error(`[Stdio Wrapper] All providers covered by local CLIs or max perspectives reached, skipping remote perspectives`);
|
|
807
838
|
return {
|
|
808
839
|
success: true,
|
|
809
840
|
content: '',
|
|
810
841
|
skipped: true,
|
|
811
|
-
reason: 'All providers covered by local CLIs',
|
|
842
|
+
reason: 'All providers covered by local CLIs or max perspectives reached',
|
|
812
843
|
timestamp: new Date().toISOString()
|
|
813
844
|
};
|
|
814
845
|
}
|
|
815
846
|
|
|
816
|
-
console.error(`[Stdio Wrapper] Calling remote perspectives (excluding: ${excludeProviders.join(', ') || 'none'})`);
|
|
847
|
+
console.error(`[Stdio Wrapper] Calling remote perspectives (excluding: ${excludeProviders.join(', ') || 'none'}, max: ${maxPerspectives})`);
|
|
817
848
|
|
|
818
849
|
// Format CLI responses for logging on the server
|
|
819
850
|
const cliResponses = localResults.map(result => ({
|
|
@@ -839,6 +870,8 @@ class StdioMCPWrapper {
|
|
|
839
870
|
exclude_providers: excludeProviders,
|
|
840
871
|
// Pass CLI responses for dashboard logging
|
|
841
872
|
cli_responses: cliResponses,
|
|
873
|
+
// Limit remote perspectives to what we need
|
|
874
|
+
max_perspectives: maxPerspectives,
|
|
842
875
|
project_memory: 'none',
|
|
843
876
|
temperature: 0.7,
|
|
844
877
|
max_tokens: 20000
|
|
@@ -1307,6 +1340,7 @@ class StdioMCPWrapper {
|
|
|
1307
1340
|
/**
|
|
1308
1341
|
* Fetch user's model preferences from API keys
|
|
1309
1342
|
* Returns a map of CLI provider -> default_model
|
|
1343
|
+
* Also fetches and caches perspectivesPerMessage setting
|
|
1310
1344
|
*/
|
|
1311
1345
|
async fetchUserModelPreferences() {
|
|
1312
1346
|
// Check cache first
|
|
@@ -1342,7 +1376,11 @@ class StdioMCPWrapper {
|
|
|
1342
1376
|
this.userModelPreferences = result.modelPreferences;
|
|
1343
1377
|
this.modelPreferencesCacheTime = Date.now();
|
|
1344
1378
|
|
|
1379
|
+
// Also cache perspectives_per_message setting (default 2)
|
|
1380
|
+
this.perspectivesPerMessage = result.perspectivesPerMessage || 2;
|
|
1381
|
+
|
|
1345
1382
|
console.error('[Stdio Wrapper] Model preferences loaded:', JSON.stringify(result.modelPreferences));
|
|
1383
|
+
console.error('[Stdio Wrapper] Perspectives per message:', this.perspectivesPerMessage);
|
|
1346
1384
|
return result.modelPreferences;
|
|
1347
1385
|
} else {
|
|
1348
1386
|
console.error('[Stdio Wrapper] No model preferences in response');
|
package/package.json
CHANGED