polydev-ai 1.7.0 → 1.8.2
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 +129 -4
- package/package.json +1 -1
package/mcp/stdio-wrapper.js
CHANGED
|
@@ -513,6 +513,11 @@ class StdioMCPWrapper {
|
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
// Report CLI results to server for dashboard storage (non-blocking)
|
|
517
|
+
this.reportCliResultsToServer(prompt, localResults, args).catch(err => {
|
|
518
|
+
console.error('[Stdio Wrapper] CLI results reporting failed (non-critical):', err.message);
|
|
519
|
+
});
|
|
520
|
+
|
|
516
521
|
// Get remote perspectives (only for models not covered by local CLIs)
|
|
517
522
|
const perspectivesResult = await this.callPerspectivesForCli(args, localResults);
|
|
518
523
|
|
|
@@ -565,11 +570,129 @@ class StdioMCPWrapper {
|
|
|
565
570
|
}
|
|
566
571
|
}
|
|
567
572
|
|
|
573
|
+
/**
|
|
574
|
+
* Report CLI results to server for dashboard storage
|
|
575
|
+
* This stores CLI results in Supabase so they appear in the dashboard
|
|
576
|
+
*/
|
|
577
|
+
async reportCliResultsToServer(prompt, localResults, args = {}) {
|
|
578
|
+
// Only report if we have successful CLI results
|
|
579
|
+
const successfulResults = localResults.filter(r => r.success);
|
|
580
|
+
if (successfulResults.length === 0) {
|
|
581
|
+
console.error('[Stdio Wrapper] No successful CLI results to report');
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (!this.userToken) {
|
|
586
|
+
console.error('[Stdio Wrapper] No user token available for CLI results reporting');
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
try {
|
|
591
|
+
const cliResults = localResults.map(result => ({
|
|
592
|
+
provider_id: result.provider_id,
|
|
593
|
+
model: result.model || this.getDefaultModelForCli(result.provider_id),
|
|
594
|
+
content: result.content || '',
|
|
595
|
+
tokens_used: result.tokens_used || 0,
|
|
596
|
+
latency_ms: result.latency_ms || 0,
|
|
597
|
+
success: result.success || false,
|
|
598
|
+
error: result.error || null
|
|
599
|
+
}));
|
|
600
|
+
|
|
601
|
+
const reportPayload = {
|
|
602
|
+
prompt: prompt,
|
|
603
|
+
cli_results: cliResults,
|
|
604
|
+
temperature: args.temperature || 0.7,
|
|
605
|
+
max_tokens: args.max_tokens || 20000
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const response = await fetch(`${this.serverUrl.replace('/mcp', '')}/api/mcp/report-cli-results`, {
|
|
609
|
+
method: 'POST',
|
|
610
|
+
headers: {
|
|
611
|
+
'Authorization': `Bearer ${this.userToken}`,
|
|
612
|
+
'Content-Type': 'application/json',
|
|
613
|
+
'User-Agent': 'polydev-stdio-wrapper/1.0.0'
|
|
614
|
+
},
|
|
615
|
+
body: JSON.stringify(reportPayload)
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
if (!response.ok) {
|
|
619
|
+
const errorText = await response.text();
|
|
620
|
+
console.error('[Stdio Wrapper] Failed to report CLI results:', response.status, errorText);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const result = await response.json();
|
|
625
|
+
console.error(`[Stdio Wrapper] CLI results reported to dashboard: ${result.stored} results stored`);
|
|
626
|
+
|
|
627
|
+
} catch (error) {
|
|
628
|
+
// Non-critical - log and continue
|
|
629
|
+
console.error('[Stdio Wrapper] Error reporting CLI results (non-critical):', error.message);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Get default model name for a CLI tool (used when model not specified in result)
|
|
635
|
+
* These are just display labels - actual model selection is done by:
|
|
636
|
+
* 1. User's configured default_model in dashboard API keys
|
|
637
|
+
* 2. CLI tool's own default if no preference set
|
|
638
|
+
*/
|
|
639
|
+
getDefaultModelForCli(providerId) {
|
|
640
|
+
// Return a display label indicating CLI default was used
|
|
641
|
+
// The actual model depends on the CLI tool's configuration
|
|
642
|
+
const defaults = {
|
|
643
|
+
'claude_code': 'CLI Default',
|
|
644
|
+
'codex_cli': 'CLI Default',
|
|
645
|
+
'gemini_cli': 'CLI Default'
|
|
646
|
+
};
|
|
647
|
+
return defaults[providerId] || 'CLI Default';
|
|
648
|
+
}
|
|
649
|
+
|
|
568
650
|
/**
|
|
569
651
|
* Call remote perspectives for CLI prompts
|
|
652
|
+
* Only calls remote APIs for providers NOT covered by successful local CLIs
|
|
570
653
|
*/
|
|
571
654
|
async callPerspectivesForCli(args, localResults) {
|
|
572
|
-
|
|
655
|
+
// Determine which providers succeeded locally
|
|
656
|
+
const successfulLocalProviders = localResults
|
|
657
|
+
.filter(r => r.success)
|
|
658
|
+
.map(r => r.provider_id);
|
|
659
|
+
|
|
660
|
+
// Map CLI provider IDs to API provider names for exclusion
|
|
661
|
+
const cliToApiProvider = {
|
|
662
|
+
'claude_code': 'anthropic',
|
|
663
|
+
'codex_cli': 'openai',
|
|
664
|
+
'gemini_cli': 'google'
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
const excludeProviders = successfulLocalProviders
|
|
668
|
+
.map(cli => cliToApiProvider[cli])
|
|
669
|
+
.filter(Boolean);
|
|
670
|
+
|
|
671
|
+
// If all major providers are covered locally, skip remote call entirely
|
|
672
|
+
if (excludeProviders.length >= 3 ||
|
|
673
|
+
(excludeProviders.includes('anthropic') && excludeProviders.includes('openai') && excludeProviders.includes('google'))) {
|
|
674
|
+
console.error(`[Stdio Wrapper] All providers covered by local CLIs, skipping remote perspectives`);
|
|
675
|
+
return {
|
|
676
|
+
success: true,
|
|
677
|
+
content: '',
|
|
678
|
+
skipped: true,
|
|
679
|
+
reason: 'All providers covered by local CLIs',
|
|
680
|
+
timestamp: new Date().toISOString()
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
console.error(`[Stdio Wrapper] Calling remote perspectives (excluding: ${excludeProviders.join(', ') || 'none'})`);
|
|
685
|
+
|
|
686
|
+
// Format CLI responses for logging on the server
|
|
687
|
+
const cliResponses = localResults.map(result => ({
|
|
688
|
+
provider_id: result.provider_id,
|
|
689
|
+
model: result.model || this.getDefaultModelForCli(result.provider_id),
|
|
690
|
+
content: result.content || '',
|
|
691
|
+
tokens_used: result.tokens_used || 0,
|
|
692
|
+
latency_ms: result.latency_ms || 0,
|
|
693
|
+
success: result.success || false,
|
|
694
|
+
error: result.error || null
|
|
695
|
+
}));
|
|
573
696
|
|
|
574
697
|
try {
|
|
575
698
|
const perspectivesRequest = {
|
|
@@ -580,11 +703,13 @@ class StdioMCPWrapper {
|
|
|
580
703
|
arguments: {
|
|
581
704
|
prompt: args.prompt,
|
|
582
705
|
user_token: this.userToken,
|
|
583
|
-
//
|
|
584
|
-
|
|
706
|
+
// Exclude providers that succeeded locally
|
|
707
|
+
exclude_providers: excludeProviders,
|
|
708
|
+
// Pass CLI responses for dashboard logging
|
|
709
|
+
cli_responses: cliResponses,
|
|
585
710
|
project_memory: 'none',
|
|
586
711
|
temperature: 0.7,
|
|
587
|
-
max_tokens:
|
|
712
|
+
max_tokens: 20000
|
|
588
713
|
}
|
|
589
714
|
},
|
|
590
715
|
id: `perspectives-${Date.now()}`
|
package/package.json
CHANGED