mcp-prompt-optimizer 1.3.2 โ 1.3.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/CHANGELOG.md +85 -0
- package/README.md +286 -130
- package/index.js +1092 -724
- package/lib/api-key-manager.js +538 -46
- package/lib/check-status.js +356 -111
- package/lib/clear-cache.js +113 -79
- package/lib/diagnose.js +252 -0
- package/lib/diagnose.js file.txt +252 -0
- package/lib/test-integration.js +250 -0
- package/lib/validate-key.js +171 -54
- package/package.json +224 -28
package/lib/clear-cache.js
CHANGED
|
@@ -1,100 +1,134 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Clear Cache
|
|
5
|
-
*
|
|
4
|
+
* Clear Cache Command for MCP Prompt Optimizer
|
|
5
|
+
* Enhanced with network health data clearing and development mode support
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const CloudApiKeyManager = require('./api-key-manager');
|
|
9
|
-
const
|
|
10
|
-
const path = require('path');
|
|
11
|
-
const os = require('os');
|
|
9
|
+
const packageJson = require('../package.json');
|
|
12
10
|
|
|
13
11
|
async function clearCache() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const developmentMode = process.env.NODE_ENV === 'development' || process.env.OPTIMIZER_DEV_MODE === 'true';
|
|
13
|
+
const modeText = developmentMode ? ' (Development Mode)' : '';
|
|
14
|
+
|
|
15
|
+
console.log(`๐งน MCP Prompt Optimizer v${packageJson.version} - Clear Cache${modeText}\n`);
|
|
16
|
+
|
|
19
17
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const cacheContent = await fs.readFile(cacheFile, 'utf8');
|
|
26
|
-
const cacheData = JSON.parse(cacheContent);
|
|
27
|
-
const cacheAge = Date.now() - cacheData.timestamp;
|
|
28
|
-
const ageHours = Math.floor(cacheAge / (1000 * 60 * 60));
|
|
29
|
-
const ageMinutes = Math.floor((cacheAge % (1000 * 60 * 60)) / (1000 * 60));
|
|
30
|
-
|
|
31
|
-
console.log('๐ Found cache file:');
|
|
32
|
-
console.log(` Location: ${cacheFile}`);
|
|
33
|
-
console.log(` Age: ${ageHours}h ${ageMinutes}m`);
|
|
34
|
-
if (cacheData.data && cacheData.data.tier) {
|
|
35
|
-
console.log(` Cached tier: ${cacheData.data.tier}`);
|
|
36
|
-
}
|
|
37
|
-
} catch (parseError) {
|
|
38
|
-
console.log('๐ Found cache file (invalid format)');
|
|
18
|
+
const apiKey = process.env.OPTIMIZER_API_KEY;
|
|
19
|
+
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
console.log('โ ๏ธ No API key found, clearing system caches only');
|
|
39
22
|
}
|
|
40
23
|
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
// Create manager instance for cache operations
|
|
25
|
+
const manager = new CloudApiKeyManager(apiKey || 'dummy-key-for-cache-clear', {
|
|
26
|
+
developmentMode
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log('๐ Analyzing cache status...');
|
|
30
|
+
|
|
31
|
+
// Check what caches exist before clearing
|
|
32
|
+
const diagnostic = await manager.getDiagnosticInfo();
|
|
33
|
+
|
|
34
|
+
let cachesFound = 0;
|
|
35
|
+
let healthDataFound = false;
|
|
36
|
+
|
|
37
|
+
if (diagnostic.cache.exists) {
|
|
38
|
+
cachesFound++;
|
|
39
|
+
console.log(`๐ Found validation cache (${diagnostic.cache.age} minutes old)`);
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
path.join(os.homedir(), '.mcp-prompt-optimizer-cache.json'),
|
|
57
|
-
path.join(os.homedir(), '.optimizer-cache.json'),
|
|
58
|
-
path.join(os.homedir(), '.mcp-cache.json')
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
for (const cacheFile of additionalCaches) {
|
|
62
|
-
try {
|
|
63
|
-
await fs.access(cacheFile);
|
|
64
|
-
await fs.unlink(cacheFile);
|
|
65
|
-
console.log(`โ
Cleared additional cache: ${path.basename(cacheFile)}`);
|
|
66
|
-
cacheCleared = true;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
// File doesn't exist, that's fine
|
|
41
|
+
|
|
42
|
+
if (diagnostic.networkHealth.lastSuccessful || diagnostic.networkHealth.consecutiveFailures > 0) {
|
|
43
|
+
healthDataFound = true;
|
|
44
|
+
console.log(`๐ฅ Found network health data (${diagnostic.networkHealth.consecutiveFailures} failures recorded)`);
|
|
69
45
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
46
|
+
|
|
47
|
+
if (cachesFound === 0 && !healthDataFound) {
|
|
48
|
+
console.log('โจ No caches found - system is already clean!');
|
|
49
|
+
console.log('\n๐ Cache Status: Clean');
|
|
50
|
+
console.log('๐ฅ Network Health: Clean');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log('\n๐งน Clearing caches...');
|
|
55
|
+
|
|
56
|
+
// Clear all caches
|
|
57
|
+
await manager.clearCache();
|
|
58
|
+
|
|
59
|
+
console.log('โ
Cache clearing completed successfully!\n');
|
|
60
|
+
|
|
61
|
+
// Report what was cleared
|
|
62
|
+
console.log('๐ Cleared Items:');
|
|
63
|
+
if (cachesFound > 0) {
|
|
64
|
+
console.log(' โ
API key validation cache');
|
|
65
|
+
console.log(' โ
Subscription status cache');
|
|
66
|
+
console.log(' โ
Backend response cache');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (healthDataFound) {
|
|
70
|
+
console.log(' โ
Network health metrics');
|
|
71
|
+
console.log(' โ
Connection failure history');
|
|
72
|
+
console.log(' โ
Response time statistics');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log('\n๐ฏ Benefits of Cache Clearing:');
|
|
76
|
+
console.log(' ๐ Forces fresh API key validation');
|
|
77
|
+
console.log(' ๐ก Tests current backend connectivity');
|
|
78
|
+
console.log(' ๐งน Removes stale network health data');
|
|
79
|
+
console.log(' ๐ Enables accurate diagnostic information');
|
|
80
|
+
console.log(' โก May resolve authentication issues');
|
|
81
|
+
|
|
82
|
+
if (developmentMode) {
|
|
83
|
+
console.log('\n๐งช Development Mode Notes:');
|
|
84
|
+
console.log(' ๐ Mock cache data cleared');
|
|
85
|
+
console.log(' ๐ด Ready for fresh offline testing');
|
|
86
|
+
console.log(' ๐งช Development flags reset');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log('\n๐ Next Steps:');
|
|
90
|
+
console.log(' 1. Run validation: mcp-prompt-optimizer validate-key');
|
|
81
91
|
console.log(' 2. Check status: mcp-prompt-optimizer check-status');
|
|
82
|
-
console.log(' 3.
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
console.log(' 3. Test integration: mcp-prompt-optimizer test');
|
|
93
|
+
console.log(' 4. Run diagnostic: mcp-prompt-optimizer diagnose');
|
|
94
|
+
|
|
95
|
+
console.log('\n๐ก When to Clear Cache:');
|
|
96
|
+
console.log(' ๐ After updating API key');
|
|
97
|
+
console.log(' ๐ When experiencing connection issues');
|
|
98
|
+
console.log(' ๐ After changing backend URL');
|
|
99
|
+
console.log(' ๐งช Before switching between dev/production modes');
|
|
100
|
+
console.log(' ๐ ๏ธ When troubleshooting authentication problems');
|
|
101
|
+
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(`โ Cache clearing failed: ${error.message}\n`);
|
|
104
|
+
|
|
105
|
+
if (error.message.includes('ENOENT')) {
|
|
106
|
+
console.log('โน๏ธ Cache files not found - nothing to clear');
|
|
107
|
+
console.log('โจ System is already clean!');
|
|
108
|
+
} else if (error.message.includes('EACCES') || error.message.includes('permission')) {
|
|
109
|
+
console.log('๐ Permission Issue:');
|
|
110
|
+
console.log(' - Cache files may be locked by another process');
|
|
111
|
+
console.log(' - Try running with elevated permissions');
|
|
112
|
+
console.log(' - Ensure no other MCP processes are running');
|
|
113
|
+
} else {
|
|
114
|
+
console.log('๐ ๏ธ Troubleshooting:');
|
|
115
|
+
console.log(' 1. Check file system permissions');
|
|
116
|
+
console.log(' 2. Ensure no processes are using cache files');
|
|
117
|
+
console.log(' 3. Try restarting terminal/command prompt');
|
|
118
|
+
console.log(' 4. Contact support if issue persists');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log('\n๐ Manual Cache Locations:');
|
|
122
|
+
console.log(` Validation: ${diagnostic?.cacheFile || '~/.mcp-cloud-api-cache.json'}`);
|
|
123
|
+
console.log(` Health: ${diagnostic?.healthFile || '~/.mcp-cloud-health.json'}`);
|
|
124
|
+
console.log(' You can manually delete these files if needed');
|
|
125
|
+
|
|
126
|
+
process.exit(1);
|
|
85
127
|
}
|
|
86
|
-
|
|
87
|
-
// Offer to validate immediately
|
|
88
|
-
console.log('\n๐ก Want to validate your API key now?');
|
|
89
|
-
console.log(' Run: mcp-prompt-optimizer validate-key');
|
|
90
128
|
}
|
|
91
129
|
|
|
92
|
-
// Run if called directly
|
|
93
130
|
if (require.main === module) {
|
|
94
|
-
clearCache()
|
|
95
|
-
console.error(`โ Error clearing cache: ${error.message}`);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
});
|
|
131
|
+
clearCache();
|
|
98
132
|
}
|
|
99
133
|
|
|
100
134
|
module.exports = clearCache;
|
package/lib/diagnose.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Diagnostic Command for MCP Prompt Optimizer
|
|
5
|
+
* Enhanced with comprehensive network analysis and development mode support
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const CloudApiKeyManager = require('./api-key-manager');
|
|
9
|
+
const packageJson = require('../package.json');
|
|
10
|
+
|
|
11
|
+
async function runDiagnostic() {
|
|
12
|
+
const developmentMode = process.env.NODE_ENV === 'development' || process.env.OPTIMIZER_DEV_MODE === 'true';
|
|
13
|
+
const modeText = developmentMode ? ' (Development Mode)' : '';
|
|
14
|
+
|
|
15
|
+
console.log(`๐ฌ MCP Prompt Optimizer v${packageJson.version} - Comprehensive Diagnostic${modeText}\n`);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const apiKey = process.env.OPTIMIZER_API_KEY;
|
|
19
|
+
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
console.log('โ ๏ธ No API key found, running partial diagnostic');
|
|
22
|
+
console.log('Set OPTIMIZER_API_KEY for complete analysis\n');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const manager = new CloudApiKeyManager(apiKey || 'dummy-key-for-diagnostic', {
|
|
26
|
+
developmentMode
|
|
27
|
+
});
|
|
28
|
+
const diagnostic = await manager.getDiagnosticInfo();
|
|
29
|
+
|
|
30
|
+
console.log('๐ Diagnostic Information:');
|
|
31
|
+
console.log('=' .repeat(60));
|
|
32
|
+
|
|
33
|
+
// Basic system information
|
|
34
|
+
console.log(`๐ API Key: ${diagnostic.apiKey}`);
|
|
35
|
+
console.log(`๐ Backend URL: ${diagnostic.backendUrl}`);
|
|
36
|
+
console.log(`๐พ Cache File: ${diagnostic.cacheFile}`);
|
|
37
|
+
console.log(`๐ฅ Health File: ${diagnostic.healthFile}`);
|
|
38
|
+
console.log(`โฐ Cache Expiry: ${diagnostic.cacheExpiry / 1000 / 60} minutes`);
|
|
39
|
+
console.log(`โฐ Fallback Cache Expiry: ${diagnostic.fallbackCacheExpiry / 1000 / 60 / 60} hours`);
|
|
40
|
+
console.log(`๐ฑ Offline Mode: ${diagnostic.offlineMode}`);
|
|
41
|
+
console.log(`๐งช Development Mode: ${diagnostic.developmentMode}`);
|
|
42
|
+
console.log(`๐ Max Retries: ${diagnostic.maxRetries}`);
|
|
43
|
+
console.log(`โฑ๏ธ Request Timeout: ${diagnostic.requestTimeout}ms`);
|
|
44
|
+
console.log(`๐ง Node Environment: ${diagnostic.nodeEnv || 'not set'}`);
|
|
45
|
+
console.log(`๐ฆ Package Version: ${diagnostic.packageVersion}`);
|
|
46
|
+
|
|
47
|
+
// Network health section
|
|
48
|
+
console.log('\n๐ Network Health:');
|
|
49
|
+
const health = diagnostic.networkHealth;
|
|
50
|
+
console.log(` ๐ Consecutive Failures: ${health.consecutiveFailures}`);
|
|
51
|
+
console.log(` โ
Last Successful: ${health.lastSuccessful ? new Date(health.lastSuccessful).toLocaleString() : 'Never'}`);
|
|
52
|
+
console.log(` โก Avg Response Time: ${health.avgResponseTime ? health.avgResponseTime + 'ms' : 'Unknown'}`);
|
|
53
|
+
console.log(` โ Last Error Type: ${health.lastErrorType || 'None'}`);
|
|
54
|
+
|
|
55
|
+
// Cache status
|
|
56
|
+
console.log('\n๐ Cache Status:');
|
|
57
|
+
if (diagnostic.cache.error) {
|
|
58
|
+
console.log(` โ Error: ${diagnostic.cache.error}`);
|
|
59
|
+
} else {
|
|
60
|
+
console.log(` ๐ Exists: ${diagnostic.cache.exists}`);
|
|
61
|
+
console.log(` โณ Normal Cache Expired: ${diagnostic.cache.expired}`);
|
|
62
|
+
console.log(` ๐ Fallback Cache Expired: ${diagnostic.cache.fallbackExpired}`);
|
|
63
|
+
console.log(` ๐
Age: ${diagnostic.cache.age} minutes`);
|
|
64
|
+
|
|
65
|
+
if (diagnostic.cache.backendUrl) {
|
|
66
|
+
console.log(` ๐ Cached Backend: ${diagnostic.cache.backendUrl}`);
|
|
67
|
+
}
|
|
68
|
+
if (diagnostic.cache.packageVersion) {
|
|
69
|
+
console.log(` ๐ฆ Cached Version: ${diagnostic.cache.packageVersion}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// API key format check
|
|
74
|
+
console.log('\n๐ API Key Format Check:');
|
|
75
|
+
if (diagnostic.keyFormat.valid) {
|
|
76
|
+
console.log(` โ
Valid: ${diagnostic.keyFormat.keyType}`);
|
|
77
|
+
} else {
|
|
78
|
+
console.log(` โ Invalid: ${diagnostic.keyFormat.error}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Backend connectivity analysis
|
|
82
|
+
console.log('\n๐ Backend Connectivity Analysis:');
|
|
83
|
+
const connectivity = diagnostic.backendConnectivity;
|
|
84
|
+
if (connectivity.status === 'success') {
|
|
85
|
+
console.log(' โ
Connection successful');
|
|
86
|
+
if (connectivity.responseTime) {
|
|
87
|
+
console.log(` โก Response time: ${connectivity.responseTime}ms`);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
console.log(` โ Connection failed: ${connectivity.error}`);
|
|
91
|
+
|
|
92
|
+
// Enhanced error analysis
|
|
93
|
+
if (connectivity.dns) {
|
|
94
|
+
console.log(' ๐ Issue Type: DNS Resolution Failure');
|
|
95
|
+
console.log(' ๐ก Likely Causes:');
|
|
96
|
+
console.log(' - Internet connection issues');
|
|
97
|
+
console.log(' - DNS server problems');
|
|
98
|
+
console.log(' - Corporate firewall blocking DNS');
|
|
99
|
+
console.log(' - VPN/proxy configuration issues');
|
|
100
|
+
} else if (connectivity.connection) {
|
|
101
|
+
console.log(' ๐ Issue Type: Connection Refused/Reset');
|
|
102
|
+
console.log(' ๐ก Likely Causes:');
|
|
103
|
+
console.log(' - Backend server is down');
|
|
104
|
+
console.log(' - Port blocking by firewall');
|
|
105
|
+
console.log(' - Network routing issues');
|
|
106
|
+
console.log(' - Load balancer problems');
|
|
107
|
+
} else if (connectivity.timeout) {
|
|
108
|
+
console.log(' ๐ Issue Type: Connection Timeout');
|
|
109
|
+
console.log(' ๐ก Likely Causes:');
|
|
110
|
+
console.log(' - Slow network connection');
|
|
111
|
+
console.log(' - Backend server overload');
|
|
112
|
+
console.log(' - Proxy/firewall delays');
|
|
113
|
+
console.log(' - Geographic distance');
|
|
114
|
+
} else if (connectivity.network) {
|
|
115
|
+
console.log(' ๐ Issue Type: General Network Error');
|
|
116
|
+
console.log(' ๐ก Likely Causes:');
|
|
117
|
+
console.log(' - Network instability');
|
|
118
|
+
console.log(' - ISP issues');
|
|
119
|
+
console.log(' - WiFi connectivity problems');
|
|
120
|
+
console.log(' - Mobile data limitations');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Development mode specific information
|
|
125
|
+
if (developmentMode) {
|
|
126
|
+
console.log('\n๐งช Development Mode Analysis:');
|
|
127
|
+
console.log(' โ
Development mode active');
|
|
128
|
+
console.log(' ๐ Mock responses available');
|
|
129
|
+
console.log(' ๐ด Offline operation supported');
|
|
130
|
+
console.log(' ๐งช No backend dependency required');
|
|
131
|
+
|
|
132
|
+
if (apiKey && (apiKey.startsWith('sk-dev-') || apiKey.startsWith('sk-local-'))) {
|
|
133
|
+
console.log(' โ
Development API key detected');
|
|
134
|
+
} else {
|
|
135
|
+
console.log(' โ ๏ธ Consider using development API key (sk-dev-* or sk-local-*)');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Recommendations section
|
|
140
|
+
console.log('\n๐ก Recommendations:');
|
|
141
|
+
|
|
142
|
+
if (!apiKey) {
|
|
143
|
+
console.log(' ๐ Set API key: export OPTIMIZER_API_KEY=sk-opt-your-key');
|
|
144
|
+
console.log(' ๐ Get free trial: https://promptoptimizer-blog.vercel.app/pricing');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (health.consecutiveFailures > 0) {
|
|
148
|
+
console.log(` ๐ ${health.consecutiveFailures} consecutive network failures detected`);
|
|
149
|
+
console.log(' ๐งช Consider development mode: export OPTIMIZER_DEV_MODE=true');
|
|
150
|
+
console.log(' ๐ก Check network connectivity and firewall settings');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (diagnostic.cache.exists && diagnostic.cache.expired && !diagnostic.cache.fallbackExpired) {
|
|
154
|
+
console.log(' ๐พ Cache available for fallback mode');
|
|
155
|
+
console.log(' ๐ Package can operate with reduced functionality');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!developmentMode && connectivity.status === 'failed') {
|
|
159
|
+
console.log(' ๐งช Try development mode for offline testing:');
|
|
160
|
+
console.log(' export OPTIMIZER_DEV_MODE=true');
|
|
161
|
+
console.log(' export OPTIMIZER_API_KEY=sk-dev-test-key');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (connectivity.status === 'success' && health.avgResponseTime > 5000) {
|
|
165
|
+
console.log(' โก Network latency is high (>5s)');
|
|
166
|
+
console.log(' ๐ Consider checking network quality or VPN settings');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Action items
|
|
170
|
+
console.log('\n๐ฏ Suggested Actions:');
|
|
171
|
+
|
|
172
|
+
if (connectivity.status === 'failed') {
|
|
173
|
+
console.log(' 1. ๐ Test basic internet: ping google.com');
|
|
174
|
+
console.log(' 2. ๐ Check DNS: nslookup p01--project-optimizer--fvrdk8m9k9j.code.run');
|
|
175
|
+
console.log(' 3. ๐ก๏ธ Verify firewall allows HTTPS traffic');
|
|
176
|
+
console.log(' 4. ๐ Try again in a few minutes');
|
|
177
|
+
console.log(' 5. ๐งช Use development mode for immediate testing');
|
|
178
|
+
} else {
|
|
179
|
+
console.log(' 1. โ
Network connectivity is working well');
|
|
180
|
+
console.log(' 2. ๐ Ready for production use');
|
|
181
|
+
|
|
182
|
+
if (!apiKey || !diagnostic.keyFormat.valid) {
|
|
183
|
+
console.log(' 3. ๐ Set up proper API key for full functionality');
|
|
184
|
+
} else {
|
|
185
|
+
console.log(' 3. ๐ฏ All systems operational');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Network environment detection
|
|
190
|
+
console.log('\n๐ Network Environment:');
|
|
191
|
+
const userAgent = `mcp-prompt-optimizer/${diagnostic.packageVersion}`;
|
|
192
|
+
console.log(` ๐ฑ User Agent: ${userAgent}`);
|
|
193
|
+
console.log(` ๐ข Corporate Network: ${connectivity.timeout || connectivity.dns ? 'Likely' : 'Unlikely'}`);
|
|
194
|
+
console.log(` ๐ Firewall/Proxy: ${connectivity.timeout ? 'Possible' : 'Unlikely'}`);
|
|
195
|
+
console.log(` ๐ถ Connection Quality: ${health.avgResponseTime ?
|
|
196
|
+
(health.avgResponseTime < 1000 ? 'Excellent' :
|
|
197
|
+
health.avgResponseTime < 3000 ? 'Good' :
|
|
198
|
+
health.avgResponseTime < 5000 ? 'Fair' : 'Poor') : 'Unknown'}`);
|
|
199
|
+
|
|
200
|
+
console.log(`\n๐ Generated: ${diagnostic.timestamp}`);
|
|
201
|
+
|
|
202
|
+
// Final status summary
|
|
203
|
+
console.log('\n' + '='.repeat(60));
|
|
204
|
+
console.log('๐ DIAGNOSTIC SUMMARY:');
|
|
205
|
+
|
|
206
|
+
const issues = [];
|
|
207
|
+
const working = [];
|
|
208
|
+
|
|
209
|
+
if (!apiKey) issues.push('No API key configured');
|
|
210
|
+
else working.push('API key present');
|
|
211
|
+
|
|
212
|
+
if (!diagnostic.keyFormat.valid) issues.push('Invalid API key format');
|
|
213
|
+
else working.push('API key format valid');
|
|
214
|
+
|
|
215
|
+
if (connectivity.status === 'failed') issues.push('Backend connectivity failed');
|
|
216
|
+
else working.push('Backend connectivity working');
|
|
217
|
+
|
|
218
|
+
if (diagnostic.cache.error) issues.push('Cache system error');
|
|
219
|
+
else working.push('Cache system working');
|
|
220
|
+
|
|
221
|
+
if (health.consecutiveFailures > 3) issues.push('Multiple network failures');
|
|
222
|
+
else working.push('Network stability good');
|
|
223
|
+
|
|
224
|
+
console.log(`โ
Working (${working.length}): ${working.join(', ')}`);
|
|
225
|
+
if (issues.length > 0) {
|
|
226
|
+
console.log(`โ ๏ธ Issues (${issues.length}): ${issues.join(', ')}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const overallStatus = issues.length === 0 ? 'EXCELLENT' :
|
|
230
|
+
issues.length <= 2 ? 'GOOD' : 'NEEDS ATTENTION';
|
|
231
|
+
console.log(`\n๐ฏ Overall Status: ${overallStatus}`);
|
|
232
|
+
|
|
233
|
+
if (developmentMode) {
|
|
234
|
+
console.log('๐งช Development mode provides full offline functionality');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.error('โ Diagnostic failed:', error.message);
|
|
239
|
+
console.log('\n๐ Emergency Diagnostic:');
|
|
240
|
+
console.log(' - Package installation may be corrupted');
|
|
241
|
+
console.log(' - Try: npm install --force');
|
|
242
|
+
console.log(' - Ensure Node.js version >= 16.0.0');
|
|
243
|
+
console.log(' - Contact support: support@promptoptimizer.help');
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (require.main === module) {
|
|
249
|
+
runDiagnostic();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = runDiagnostic;
|