@mcpilotx/intentorch 0.5.0
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/LICENSE +201 -0
- package/README.md +545 -0
- package/dist/ai/ai.d.ts +205 -0
- package/dist/ai/ai.js +1200 -0
- package/dist/ai/cloud-intent-engine.d.ts +270 -0
- package/dist/ai/cloud-intent-engine.js +956 -0
- package/dist/ai/command.d.ts +59 -0
- package/dist/ai/command.js +285 -0
- package/dist/ai/config.d.ts +66 -0
- package/dist/ai/config.js +211 -0
- package/dist/ai/enhanced-intent.d.ts +17 -0
- package/dist/ai/enhanced-intent.js +32 -0
- package/dist/ai/index.d.ts +29 -0
- package/dist/ai/index.js +44 -0
- package/dist/ai/intent.d.ts +16 -0
- package/dist/ai/intent.js +30 -0
- package/dist/core/ai-config.d.ts +25 -0
- package/dist/core/ai-config.js +326 -0
- package/dist/core/config-manager.d.ts +36 -0
- package/dist/core/config-manager.js +400 -0
- package/dist/core/config-validator.d.ts +9 -0
- package/dist/core/config-validator.js +184 -0
- package/dist/core/constants.d.ts +34 -0
- package/dist/core/constants.js +37 -0
- package/dist/core/error-ai.d.ts +23 -0
- package/dist/core/error-ai.js +217 -0
- package/dist/core/error-handler.d.ts +197 -0
- package/dist/core/error-handler.js +467 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +17 -0
- package/dist/core/logger.d.ts +27 -0
- package/dist/core/logger.js +108 -0
- package/dist/core/performance-monitor.d.ts +74 -0
- package/dist/core/performance-monitor.js +260 -0
- package/dist/core/providers.d.ts +36 -0
- package/dist/core/providers.js +304 -0
- package/dist/core/retry-manager.d.ts +41 -0
- package/dist/core/retry-manager.js +204 -0
- package/dist/core/types.d.ts +155 -0
- package/dist/core/types.js +2 -0
- package/dist/daemon/index.d.ts +10 -0
- package/dist/daemon/index.js +15 -0
- package/dist/daemon/intent-engine.d.ts +22 -0
- package/dist/daemon/intent-engine.js +50 -0
- package/dist/daemon/orchestrator.d.ts +24 -0
- package/dist/daemon/orchestrator.js +100 -0
- package/dist/daemon/pm.d.ts +33 -0
- package/dist/daemon/pm.js +127 -0
- package/dist/daemon/process.d.ts +11 -0
- package/dist/daemon/process.js +49 -0
- package/dist/daemon/server.d.ts +17 -0
- package/dist/daemon/server.js +435 -0
- package/dist/daemon/service.d.ts +36 -0
- package/dist/daemon/service.js +278 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +36 -0
- package/dist/mcp/client.d.ts +51 -0
- package/dist/mcp/client.js +276 -0
- package/dist/mcp/index.d.ts +162 -0
- package/dist/mcp/index.js +199 -0
- package/dist/mcp/tool-registry.d.ts +71 -0
- package/dist/mcp/tool-registry.js +308 -0
- package/dist/mcp/transport.d.ts +83 -0
- package/dist/mcp/transport.js +515 -0
- package/dist/mcp/types.d.ts +136 -0
- package/dist/mcp/types.js +31 -0
- package/dist/runtime/adapter-advanced.d.ts +184 -0
- package/dist/runtime/adapter-advanced.js +160 -0
- package/dist/runtime/adapter.d.ts +9 -0
- package/dist/runtime/adapter.js +2 -0
- package/dist/runtime/detector-advanced.d.ts +59 -0
- package/dist/runtime/detector-advanced.js +487 -0
- package/dist/runtime/detector.d.ts +5 -0
- package/dist/runtime/detector.js +56 -0
- package/dist/runtime/docker-adapter.d.ts +18 -0
- package/dist/runtime/docker-adapter.js +170 -0
- package/dist/runtime/docker.d.ts +17 -0
- package/dist/runtime/docker.js +71 -0
- package/dist/runtime/executable-analyzer.d.ts +56 -0
- package/dist/runtime/executable-analyzer.js +391 -0
- package/dist/runtime/go-adapter.d.ts +19 -0
- package/dist/runtime/go-adapter.js +190 -0
- package/dist/runtime/index.d.ts +9 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/node-adapter.d.ts +10 -0
- package/dist/runtime/node-adapter.js +23 -0
- package/dist/runtime/node.d.ts +20 -0
- package/dist/runtime/node.js +86 -0
- package/dist/runtime/python-adapter.d.ts +11 -0
- package/dist/runtime/python-adapter.js +102 -0
- package/dist/runtime/python.d.ts +17 -0
- package/dist/runtime/python.js +72 -0
- package/dist/runtime/rust-adapter.d.ts +21 -0
- package/dist/runtime/rust-adapter.js +267 -0
- package/dist/sdk.d.ts +500 -0
- package/dist/sdk.js +904 -0
- package/docs/README.ZH_CN.md +545 -0
- package/docs/api.md +888 -0
- package/docs/architecture.md +731 -0
- package/docs/development.md +744 -0
- package/package.json +112 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export interface PerformanceMetrics {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
cpuUsage: {
|
|
4
|
+
user: number;
|
|
5
|
+
system: number;
|
|
6
|
+
total: number;
|
|
7
|
+
};
|
|
8
|
+
memoryUsage: {
|
|
9
|
+
rss: number;
|
|
10
|
+
heapTotal: number;
|
|
11
|
+
heapUsed: number;
|
|
12
|
+
external: number;
|
|
13
|
+
};
|
|
14
|
+
systemMetrics: {
|
|
15
|
+
totalMemory: number;
|
|
16
|
+
freeMemory: number;
|
|
17
|
+
loadAverage: number[];
|
|
18
|
+
uptime: number;
|
|
19
|
+
};
|
|
20
|
+
serviceMetrics: {
|
|
21
|
+
[serviceName: string]: {
|
|
22
|
+
cpu: number;
|
|
23
|
+
memory: number;
|
|
24
|
+
uptime: number;
|
|
25
|
+
requestCount: number;
|
|
26
|
+
errorCount: number;
|
|
27
|
+
responseTime: number;
|
|
28
|
+
errorRate?: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface PerformanceConfig {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
collectionInterval: number;
|
|
35
|
+
retentionPeriod: number;
|
|
36
|
+
alertThresholds: {
|
|
37
|
+
cpu: number;
|
|
38
|
+
memory: number;
|
|
39
|
+
responseTime: number;
|
|
40
|
+
errorRate: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export declare class PerformanceMonitor {
|
|
44
|
+
private metrics;
|
|
45
|
+
private config;
|
|
46
|
+
private collectionTimer;
|
|
47
|
+
private serviceStats;
|
|
48
|
+
constructor(config?: Partial<PerformanceConfig>);
|
|
49
|
+
start(): void;
|
|
50
|
+
stop(): void;
|
|
51
|
+
private collectMetrics;
|
|
52
|
+
private getCpuUsage;
|
|
53
|
+
private getMemoryUsage;
|
|
54
|
+
private getSystemMetrics;
|
|
55
|
+
private getServiceMetrics;
|
|
56
|
+
private cleanupOldMetrics;
|
|
57
|
+
private checkAlerts;
|
|
58
|
+
updateServiceStats(serviceName: string, stats: any): void;
|
|
59
|
+
recordServiceRequest(serviceName: string, duration: number, success?: boolean): void;
|
|
60
|
+
getMetrics(timeRange?: {
|
|
61
|
+
start: number;
|
|
62
|
+
end: number;
|
|
63
|
+
}): PerformanceMetrics[];
|
|
64
|
+
getSummary(): any;
|
|
65
|
+
private checkForAlertsInternal;
|
|
66
|
+
reset(): void;
|
|
67
|
+
getConfig(): PerformanceConfig;
|
|
68
|
+
updateConfig(newConfig: Partial<PerformanceConfig>): void;
|
|
69
|
+
}
|
|
70
|
+
export declare function getPerformanceMonitor(config?: Partial<PerformanceConfig>): PerformanceMonitor;
|
|
71
|
+
export declare function startPerformanceMonitoring(config?: Partial<PerformanceConfig>): PerformanceMonitor;
|
|
72
|
+
export declare function stopPerformanceMonitoring(): void;
|
|
73
|
+
export declare function recordServicePerformance(serviceName: string, operation: string, duration: number, success?: boolean): void;
|
|
74
|
+
//# sourceMappingURL=performance-monitor.d.ts.map
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import { logger } from './logger.js';
|
|
3
|
+
export class PerformanceMonitor {
|
|
4
|
+
metrics = [];
|
|
5
|
+
config;
|
|
6
|
+
collectionTimer = null;
|
|
7
|
+
serviceStats = new Map();
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = {
|
|
10
|
+
enabled: true,
|
|
11
|
+
collectionInterval: 60000, // 1 minute
|
|
12
|
+
retentionPeriod: 3600000, // 1 hour
|
|
13
|
+
alertThresholds: {
|
|
14
|
+
cpu: 80,
|
|
15
|
+
memory: 80,
|
|
16
|
+
responseTime: 1000,
|
|
17
|
+
errorRate: 5,
|
|
18
|
+
},
|
|
19
|
+
...config,
|
|
20
|
+
};
|
|
21
|
+
if (this.config.enabled) {
|
|
22
|
+
this.start();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
start() {
|
|
26
|
+
if (this.collectionTimer) {
|
|
27
|
+
this.stop();
|
|
28
|
+
}
|
|
29
|
+
logger.info('Performance monitoring started');
|
|
30
|
+
this.collectionTimer = setInterval(() => {
|
|
31
|
+
this.collectMetrics();
|
|
32
|
+
this.cleanupOldMetrics();
|
|
33
|
+
this.checkAlerts();
|
|
34
|
+
}, this.config.collectionInterval);
|
|
35
|
+
// Collect metrics immediately
|
|
36
|
+
this.collectMetrics();
|
|
37
|
+
}
|
|
38
|
+
stop() {
|
|
39
|
+
if (this.collectionTimer) {
|
|
40
|
+
clearInterval(this.collectionTimer);
|
|
41
|
+
this.collectionTimer = null;
|
|
42
|
+
logger.info('Performance monitoring stopped');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
collectMetrics() {
|
|
46
|
+
try {
|
|
47
|
+
const metrics = {
|
|
48
|
+
timestamp: Date.now(),
|
|
49
|
+
cpuUsage: this.getCpuUsage(),
|
|
50
|
+
memoryUsage: this.getMemoryUsage(),
|
|
51
|
+
systemMetrics: this.getSystemMetrics(),
|
|
52
|
+
serviceMetrics: this.getServiceMetrics(),
|
|
53
|
+
};
|
|
54
|
+
this.metrics.push(metrics);
|
|
55
|
+
logger.debug('Performance metrics collected', { timestamp: metrics.timestamp });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error('Failed to collect performance metrics', { error: error.message });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getCpuUsage() {
|
|
62
|
+
const usage = process.cpuUsage();
|
|
63
|
+
return {
|
|
64
|
+
user: usage.user / 1000, // microseconds to milliseconds
|
|
65
|
+
system: usage.system / 1000,
|
|
66
|
+
total: (usage.user + usage.system) / 1000,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
getMemoryUsage() {
|
|
70
|
+
const memory = process.memoryUsage();
|
|
71
|
+
return {
|
|
72
|
+
rss: memory.rss,
|
|
73
|
+
heapTotal: memory.heapTotal,
|
|
74
|
+
heapUsed: memory.heapUsed,
|
|
75
|
+
external: memory.external,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
getSystemMetrics() {
|
|
79
|
+
return {
|
|
80
|
+
totalMemory: os.totalmem(),
|
|
81
|
+
freeMemory: os.freemem(),
|
|
82
|
+
loadAverage: os.loadavg(),
|
|
83
|
+
uptime: os.uptime(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
getServiceMetrics() {
|
|
87
|
+
const serviceMetrics = {};
|
|
88
|
+
for (const [serviceName, stats] of this.serviceStats) {
|
|
89
|
+
serviceMetrics[serviceName] = {
|
|
90
|
+
cpu: stats.cpu || 0,
|
|
91
|
+
memory: stats.memory || 0,
|
|
92
|
+
uptime: stats.uptime || 0,
|
|
93
|
+
requestCount: stats.requestCount || 0,
|
|
94
|
+
errorCount: stats.errorCount || 0,
|
|
95
|
+
responseTime: stats.responseTime || 0,
|
|
96
|
+
errorRate: stats.errorRate || 0,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return serviceMetrics;
|
|
100
|
+
}
|
|
101
|
+
cleanupOldMetrics() {
|
|
102
|
+
const cutoff = Date.now() - this.config.retentionPeriod;
|
|
103
|
+
this.metrics = this.metrics.filter(m => m.timestamp >= cutoff);
|
|
104
|
+
}
|
|
105
|
+
checkAlerts() {
|
|
106
|
+
if (this.metrics.length === 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const latest = this.metrics[this.metrics.length - 1];
|
|
110
|
+
// Check CPU usage
|
|
111
|
+
const cpuPercent = (latest.cpuUsage.total / 1000) * 100; // rough estimate
|
|
112
|
+
if (cpuPercent > this.config.alertThresholds.cpu) {
|
|
113
|
+
logger.warn(`High CPU usage detected: ${cpuPercent.toFixed(1)}%`, {
|
|
114
|
+
threshold: this.config.alertThresholds.cpu,
|
|
115
|
+
metrics: latest.cpuUsage,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Check memory usage
|
|
119
|
+
const memoryPercent = (latest.memoryUsage.heapUsed / latest.memoryUsage.heapTotal) * 100;
|
|
120
|
+
if (memoryPercent > this.config.alertThresholds.memory) {
|
|
121
|
+
logger.warn(`High memory usage detected: ${memoryPercent.toFixed(1)}%`, {
|
|
122
|
+
threshold: this.config.alertThresholds.memory,
|
|
123
|
+
metrics: latest.memoryUsage,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// Check service metrics
|
|
127
|
+
for (const [serviceName, metrics] of Object.entries(latest.serviceMetrics)) {
|
|
128
|
+
if (metrics.errorRate > this.config.alertThresholds.errorRate) {
|
|
129
|
+
logger.warn(`High error rate for service ${serviceName}: ${metrics.errorRate.toFixed(1)}%`, {
|
|
130
|
+
threshold: this.config.alertThresholds.errorRate,
|
|
131
|
+
metrics,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (metrics.responseTime > this.config.alertThresholds.responseTime) {
|
|
135
|
+
logger.warn(`High response time for service ${serviceName}: ${metrics.responseTime}ms`, {
|
|
136
|
+
threshold: this.config.alertThresholds.responseTime,
|
|
137
|
+
metrics,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
updateServiceStats(serviceName, stats) {
|
|
143
|
+
this.serviceStats.set(serviceName, {
|
|
144
|
+
...this.serviceStats.get(serviceName),
|
|
145
|
+
...stats,
|
|
146
|
+
lastUpdated: Date.now(),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
recordServiceRequest(serviceName, duration, success = true) {
|
|
150
|
+
const stats = this.serviceStats.get(serviceName) || {
|
|
151
|
+
requestCount: 0,
|
|
152
|
+
errorCount: 0,
|
|
153
|
+
totalResponseTime: 0,
|
|
154
|
+
startTime: Date.now(),
|
|
155
|
+
};
|
|
156
|
+
stats.requestCount++;
|
|
157
|
+
if (!success) {
|
|
158
|
+
stats.errorCount++;
|
|
159
|
+
}
|
|
160
|
+
stats.totalResponseTime += duration;
|
|
161
|
+
stats.responseTime = stats.totalResponseTime / stats.requestCount;
|
|
162
|
+
stats.errorRate = (stats.errorCount / stats.requestCount) * 100;
|
|
163
|
+
stats.uptime = Date.now() - stats.startTime;
|
|
164
|
+
this.updateServiceStats(serviceName, stats);
|
|
165
|
+
}
|
|
166
|
+
getMetrics(timeRange) {
|
|
167
|
+
if (!timeRange) {
|
|
168
|
+
return [...this.metrics];
|
|
169
|
+
}
|
|
170
|
+
return this.metrics.filter(m => m.timestamp >= timeRange.start && m.timestamp <= timeRange.end);
|
|
171
|
+
}
|
|
172
|
+
getSummary() {
|
|
173
|
+
if (this.metrics.length === 0) {
|
|
174
|
+
return { message: 'No metrics available' };
|
|
175
|
+
}
|
|
176
|
+
const latest = this.metrics[this.metrics.length - 1];
|
|
177
|
+
const oldest = this.metrics[0];
|
|
178
|
+
const duration = latest.timestamp - oldest.timestamp;
|
|
179
|
+
// Calculate averages
|
|
180
|
+
const avgCpu = this.metrics.reduce((sum, m) => sum + m.cpuUsage.total, 0) / this.metrics.length;
|
|
181
|
+
const avgMemory = this.metrics.reduce((sum, m) => sum + m.memoryUsage.heapUsed, 0) / this.metrics.length;
|
|
182
|
+
const avgMemoryPercent = (avgMemory / latest.memoryUsage.heapTotal) * 100;
|
|
183
|
+
return {
|
|
184
|
+
timeRange: {
|
|
185
|
+
start: oldest.timestamp,
|
|
186
|
+
end: latest.timestamp,
|
|
187
|
+
duration,
|
|
188
|
+
},
|
|
189
|
+
averages: {
|
|
190
|
+
cpuUsage: avgCpu,
|
|
191
|
+
memoryUsage: avgMemory,
|
|
192
|
+
memoryPercent: avgMemoryPercent,
|
|
193
|
+
},
|
|
194
|
+
current: {
|
|
195
|
+
cpuUsage: latest.cpuUsage,
|
|
196
|
+
memoryUsage: latest.memoryUsage,
|
|
197
|
+
systemMetrics: latest.systemMetrics,
|
|
198
|
+
},
|
|
199
|
+
services: Object.keys(latest.serviceMetrics).length,
|
|
200
|
+
alerts: this.checkForAlertsInternal(),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
checkForAlertsInternal() {
|
|
204
|
+
const alerts = [];
|
|
205
|
+
const latest = this.metrics[this.metrics.length - 1];
|
|
206
|
+
if (!latest) {
|
|
207
|
+
return alerts;
|
|
208
|
+
}
|
|
209
|
+
// More complex alert logic can be added here
|
|
210
|
+
return alerts;
|
|
211
|
+
}
|
|
212
|
+
reset() {
|
|
213
|
+
this.metrics = [];
|
|
214
|
+
this.serviceStats.clear();
|
|
215
|
+
logger.info('Performance metrics reset');
|
|
216
|
+
}
|
|
217
|
+
getConfig() {
|
|
218
|
+
return { ...this.config };
|
|
219
|
+
}
|
|
220
|
+
updateConfig(newConfig) {
|
|
221
|
+
this.config = { ...this.config, ...newConfig };
|
|
222
|
+
if (this.config.enabled && !this.collectionTimer) {
|
|
223
|
+
this.start();
|
|
224
|
+
}
|
|
225
|
+
else if (!this.config.enabled && this.collectionTimer) {
|
|
226
|
+
this.stop();
|
|
227
|
+
}
|
|
228
|
+
logger.info('Performance monitor configuration updated', { config: this.config });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Singleton instance
|
|
232
|
+
let performanceMonitor = null;
|
|
233
|
+
export function getPerformanceMonitor(config) {
|
|
234
|
+
if (!performanceMonitor) {
|
|
235
|
+
performanceMonitor = new PerformanceMonitor(config);
|
|
236
|
+
}
|
|
237
|
+
return performanceMonitor;
|
|
238
|
+
}
|
|
239
|
+
export function startPerformanceMonitoring(config) {
|
|
240
|
+
const monitor = getPerformanceMonitor(config);
|
|
241
|
+
monitor.start();
|
|
242
|
+
return monitor;
|
|
243
|
+
}
|
|
244
|
+
export function stopPerformanceMonitoring() {
|
|
245
|
+
if (performanceMonitor) {
|
|
246
|
+
performanceMonitor.stop();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export function recordServicePerformance(serviceName, operation, duration, success = true) {
|
|
250
|
+
if (performanceMonitor) {
|
|
251
|
+
performanceMonitor.recordServiceRequest(serviceName, duration, success);
|
|
252
|
+
logger.debug('Service performance recorded', {
|
|
253
|
+
service: serviceName,
|
|
254
|
+
operation,
|
|
255
|
+
duration,
|
|
256
|
+
success,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=performance-monitor.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AIProvider } from './types';
|
|
2
|
+
export interface ProviderInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
aliases: string[];
|
|
6
|
+
requiresApiKey: boolean;
|
|
7
|
+
defaultModel: string;
|
|
8
|
+
modelDescriptions?: Record<string, string>;
|
|
9
|
+
configHint?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const PROVIDER_DB: Record<AIProvider, ProviderInfo>;
|
|
12
|
+
export declare const VALID_PROVIDERS: AIProvider[];
|
|
13
|
+
export declare function getProviderDisplayName(provider: AIProvider): string;
|
|
14
|
+
export declare function getProviderInfo(provider: AIProvider): ProviderInfo | undefined;
|
|
15
|
+
export declare function findProviderByAlias(alias: string): AIProvider | null;
|
|
16
|
+
export declare function levenshteinDistance(a: string, b: string): number;
|
|
17
|
+
export declare function findSimilarProviders(input: string, threshold?: number): Array<{
|
|
18
|
+
provider: AIProvider;
|
|
19
|
+
similarity: number;
|
|
20
|
+
distance: number;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function autoCorrectProvider(input: string): {
|
|
23
|
+
corrected: AIProvider | null;
|
|
24
|
+
original: string;
|
|
25
|
+
confidence: number;
|
|
26
|
+
suggestions: AIProvider[];
|
|
27
|
+
};
|
|
28
|
+
export declare function getDefaultConfigForProvider(provider: AIProvider): any;
|
|
29
|
+
export declare function getAllProvidersForDisplay(): Array<{
|
|
30
|
+
id: AIProvider;
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
requiresKey: boolean;
|
|
34
|
+
defaultModel: string;
|
|
35
|
+
}>;
|
|
36
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
export const PROVIDER_DB = {
|
|
2
|
+
openai: {
|
|
3
|
+
name: 'OpenAI',
|
|
4
|
+
description: 'OpenAI GPT series models (ChatGPT, GPT-4, etc.)',
|
|
5
|
+
aliases: ['gpt', 'chatgpt', 'open-ai', 'openaai', 'openni'],
|
|
6
|
+
requiresApiKey: true,
|
|
7
|
+
defaultModel: 'gpt-4',
|
|
8
|
+
modelDescriptions: {
|
|
9
|
+
'gpt-4': 'Latest GPT-4, most capable',
|
|
10
|
+
'gpt-4-turbo': 'Balanced performance and cost',
|
|
11
|
+
'gpt-3.5-turbo': 'Fast response, low cost',
|
|
12
|
+
'gpt-4o': 'Multimodal support',
|
|
13
|
+
'gpt-4-mini': 'Lightweight version of GPT-4',
|
|
14
|
+
},
|
|
15
|
+
configHint: 'API key format: sk-xxx...',
|
|
16
|
+
},
|
|
17
|
+
anthropic: {
|
|
18
|
+
name: 'Anthropic',
|
|
19
|
+
description: 'Anthropic Claude models',
|
|
20
|
+
aliases: ['claude', 'anthropic-ai', 'claud'],
|
|
21
|
+
requiresApiKey: true,
|
|
22
|
+
defaultModel: 'claude-3-opus-20240229',
|
|
23
|
+
modelDescriptions: {
|
|
24
|
+
'claude-3-opus-20240229': 'Most capable',
|
|
25
|
+
'claude-3-sonnet-20240229': 'Balanced performance',
|
|
26
|
+
'claude-3-haiku-20240307': 'Fast response',
|
|
27
|
+
},
|
|
28
|
+
configHint: 'API key format: sk-ant-xxx...',
|
|
29
|
+
},
|
|
30
|
+
google: {
|
|
31
|
+
name: 'Google',
|
|
32
|
+
description: 'Google Gemini models',
|
|
33
|
+
aliases: ['gemini', 'google-ai', 'bard', 'palm'],
|
|
34
|
+
requiresApiKey: true,
|
|
35
|
+
defaultModel: 'gemini-pro',
|
|
36
|
+
modelDescriptions: {
|
|
37
|
+
'gemini-pro': 'General purpose model',
|
|
38
|
+
'gemini-pro-vision': 'Multimodal support',
|
|
39
|
+
'gemini-ultra': 'Most capable model',
|
|
40
|
+
'gemini-nano': 'Lightweight model',
|
|
41
|
+
},
|
|
42
|
+
configHint: 'API key format: AIza... (from Google AI Studio)',
|
|
43
|
+
},
|
|
44
|
+
azure: {
|
|
45
|
+
name: 'Azure',
|
|
46
|
+
description: 'Azure OpenAI services',
|
|
47
|
+
aliases: ['azure-openai', 'microsoft', 'azure-ai'],
|
|
48
|
+
requiresApiKey: true,
|
|
49
|
+
defaultModel: 'gpt-35-turbo',
|
|
50
|
+
modelDescriptions: {
|
|
51
|
+
'gpt-35-turbo': 'Azure version of GPT-3.5',
|
|
52
|
+
'gpt-4': 'Azure version of GPT-4',
|
|
53
|
+
'gpt-4-turbo': 'Azure version of GPT-4 Turbo',
|
|
54
|
+
},
|
|
55
|
+
configHint: 'Need Azure OpenAI endpoint and API key',
|
|
56
|
+
},
|
|
57
|
+
deepseek: {
|
|
58
|
+
name: 'DeepSeek',
|
|
59
|
+
description: 'DeepSeek open source models',
|
|
60
|
+
aliases: ['deep', 'ds', 'deep-seek', 'deepsek', 'deepseak'],
|
|
61
|
+
requiresApiKey: true,
|
|
62
|
+
defaultModel: 'deepseek-chat',
|
|
63
|
+
modelDescriptions: {
|
|
64
|
+
'deepseek-chat': 'Conversation optimized',
|
|
65
|
+
'deepseek-coder': 'Code generation optimized',
|
|
66
|
+
'deepseek-v3': 'Latest version',
|
|
67
|
+
},
|
|
68
|
+
configHint: 'API key format: sk-xxx or obtain from platform',
|
|
69
|
+
},
|
|
70
|
+
cohere: {
|
|
71
|
+
name: 'Cohere',
|
|
72
|
+
description: 'Cohere command models',
|
|
73
|
+
aliases: ['co', 'cohere-ai', 'coher'],
|
|
74
|
+
requiresApiKey: true,
|
|
75
|
+
defaultModel: 'command',
|
|
76
|
+
modelDescriptions: {
|
|
77
|
+
'command': 'General instruction model',
|
|
78
|
+
'command-r': 'Reasoning optimized',
|
|
79
|
+
'command-light': 'Lightweight version',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
ollama: {
|
|
83
|
+
name: 'Ollama',
|
|
84
|
+
description: 'Local Ollama services',
|
|
85
|
+
aliases: ['oll', 'local-llm', 'llama', 'ollamaa', 'olama'],
|
|
86
|
+
requiresApiKey: false,
|
|
87
|
+
defaultModel: 'llama2',
|
|
88
|
+
modelDescriptions: {
|
|
89
|
+
'llama2': 'General model, balanced',
|
|
90
|
+
'llama3': 'Latest Llama 3',
|
|
91
|
+
'codellama': 'Code generation optimized',
|
|
92
|
+
'mistral': 'Small and efficient model',
|
|
93
|
+
'gemma': 'Google lightweight model',
|
|
94
|
+
'phi': 'Microsoft small model',
|
|
95
|
+
},
|
|
96
|
+
configHint: 'Ensure Ollama services are running at http://localhost:11434',
|
|
97
|
+
},
|
|
98
|
+
local: {
|
|
99
|
+
name: 'Local',
|
|
100
|
+
description: 'Local model files',
|
|
101
|
+
aliases: ['local-model', 'file', 'local-ai'],
|
|
102
|
+
requiresApiKey: false,
|
|
103
|
+
defaultModel: 'local-model',
|
|
104
|
+
configHint: 'Need to specify local model file path',
|
|
105
|
+
},
|
|
106
|
+
custom: {
|
|
107
|
+
name: 'Custom',
|
|
108
|
+
description: 'Custom API endpoints',
|
|
109
|
+
aliases: ['custom-api', 'self-hosted', 'custom-endpoint'],
|
|
110
|
+
requiresApiKey: false,
|
|
111
|
+
defaultModel: 'custom-model',
|
|
112
|
+
configHint: 'Need to specify API endpoint URL',
|
|
113
|
+
},
|
|
114
|
+
none: {
|
|
115
|
+
name: 'None',
|
|
116
|
+
description: 'No AI provider configured',
|
|
117
|
+
aliases: ['disabled', 'off', 'no-ai'],
|
|
118
|
+
requiresApiKey: false,
|
|
119
|
+
defaultModel: 'none',
|
|
120
|
+
configHint: 'AI functionality disabled',
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
export const VALID_PROVIDERS = Object.keys(PROVIDER_DB);
|
|
124
|
+
// Get display names for all providers
|
|
125
|
+
export function getProviderDisplayName(provider) {
|
|
126
|
+
return PROVIDER_DB[provider]?.name || provider;
|
|
127
|
+
}
|
|
128
|
+
// Get provider information
|
|
129
|
+
export function getProviderInfo(provider) {
|
|
130
|
+
return PROVIDER_DB[provider];
|
|
131
|
+
}
|
|
132
|
+
// Find provider by alias
|
|
133
|
+
export function findProviderByAlias(alias) {
|
|
134
|
+
const normalized = alias.toLowerCase().trim();
|
|
135
|
+
// Exact match
|
|
136
|
+
if (PROVIDER_DB[normalized]) {
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
// Alias match
|
|
140
|
+
for (const [provider, info] of Object.entries(PROVIDER_DB)) {
|
|
141
|
+
if (info.aliases.includes(normalized)) {
|
|
142
|
+
return provider;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
// Calculate string similarity (Levenshtein distance)
|
|
148
|
+
export function levenshteinDistance(a, b) {
|
|
149
|
+
const matrix = [];
|
|
150
|
+
for (let i = 0; i <= b.length; i++) {
|
|
151
|
+
matrix[i] = [i];
|
|
152
|
+
}
|
|
153
|
+
for (let j = 0; j <= a.length; j++) {
|
|
154
|
+
matrix[0][j] = j;
|
|
155
|
+
}
|
|
156
|
+
for (let i = 1; i <= b.length; i++) {
|
|
157
|
+
for (let j = 1; j <= a.length; j++) {
|
|
158
|
+
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
159
|
+
matrix[i][j] = matrix[i - 1][j - 1];
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // Replace
|
|
163
|
+
matrix[i][j - 1] + 1, // Insert
|
|
164
|
+
matrix[i - 1][j] + 1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return matrix[b.length][a.length];
|
|
169
|
+
}
|
|
170
|
+
// Find most similar providers
|
|
171
|
+
export function findSimilarProviders(input, threshold = 2) {
|
|
172
|
+
const normalized = input.toLowerCase().trim();
|
|
173
|
+
const results = [];
|
|
174
|
+
// Check all providers
|
|
175
|
+
for (const provider of VALID_PROVIDERS) {
|
|
176
|
+
// Calculate distance to provider name
|
|
177
|
+
const distanceToName = levenshteinDistance(normalized, provider);
|
|
178
|
+
// Calculate distance to alias
|
|
179
|
+
let minDistance = distanceToName;
|
|
180
|
+
const providerInfo = PROVIDER_DB[provider];
|
|
181
|
+
for (const alias of providerInfo.aliases) {
|
|
182
|
+
const distanceToAlias = levenshteinDistance(normalized, alias);
|
|
183
|
+
if (distanceToAlias < minDistance) {
|
|
184
|
+
minDistance = distanceToAlias;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Convert to similarity percentage (distance 0 = 100%, decrease 25% for each additional distance)
|
|
188
|
+
const similarity = Math.max(0, 100 - minDistance * 25);
|
|
189
|
+
if (minDistance <= threshold) {
|
|
190
|
+
results.push({
|
|
191
|
+
provider,
|
|
192
|
+
similarity,
|
|
193
|
+
distance: minDistance,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Sort by similarity
|
|
198
|
+
return results.sort((a, b) => {
|
|
199
|
+
// First sort by distance (smaller distance first)
|
|
200
|
+
if (a.distance !== b.distance) {
|
|
201
|
+
return a.distance - b.distance;
|
|
202
|
+
}
|
|
203
|
+
// Then sort by similarity (higher similarity first)
|
|
204
|
+
return b.similarity - a.similarity;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// Auto-correct provider name
|
|
208
|
+
export function autoCorrectProvider(input) {
|
|
209
|
+
const normalized = input.toLowerCase().trim();
|
|
210
|
+
// 1. Exact match
|
|
211
|
+
if (PROVIDER_DB[normalized]) {
|
|
212
|
+
return {
|
|
213
|
+
corrected: normalized,
|
|
214
|
+
original: input,
|
|
215
|
+
confidence: 100,
|
|
216
|
+
suggestions: [],
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// 2. Alias match
|
|
220
|
+
const aliasMatch = findProviderByAlias(normalized);
|
|
221
|
+
if (aliasMatch) {
|
|
222
|
+
return {
|
|
223
|
+
corrected: aliasMatch,
|
|
224
|
+
original: input,
|
|
225
|
+
confidence: 90,
|
|
226
|
+
suggestions: [],
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// 3. Fuzzy match
|
|
230
|
+
const similar = findSimilarProviders(normalized, 3);
|
|
231
|
+
if (similar.length > 0) {
|
|
232
|
+
const bestMatch = similar[0];
|
|
233
|
+
const suggestions = similar.slice(1, 3).map(s => s.provider);
|
|
234
|
+
return {
|
|
235
|
+
corrected: bestMatch.provider,
|
|
236
|
+
original: input,
|
|
237
|
+
confidence: Math.max(30, bestMatch.similarity),
|
|
238
|
+
suggestions,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// 4. No match
|
|
242
|
+
return {
|
|
243
|
+
corrected: null,
|
|
244
|
+
original: input,
|
|
245
|
+
confidence: 0,
|
|
246
|
+
suggestions: [],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
// Get default configuration for provider
|
|
250
|
+
export function getDefaultConfigForProvider(provider) {
|
|
251
|
+
const info = PROVIDER_DB[provider];
|
|
252
|
+
if (!info) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
const baseConfig = {
|
|
256
|
+
provider,
|
|
257
|
+
model: info.defaultModel,
|
|
258
|
+
};
|
|
259
|
+
// Add specific provider default configuration
|
|
260
|
+
switch (provider) {
|
|
261
|
+
case 'ollama':
|
|
262
|
+
return {
|
|
263
|
+
...baseConfig,
|
|
264
|
+
ollamaHost: 'http://localhost:11434',
|
|
265
|
+
timeout: 60000,
|
|
266
|
+
maxTokens: 4096,
|
|
267
|
+
temperature: 0.7,
|
|
268
|
+
};
|
|
269
|
+
case 'local':
|
|
270
|
+
return {
|
|
271
|
+
...baseConfig,
|
|
272
|
+
localModelPath: '',
|
|
273
|
+
timeout: 120000,
|
|
274
|
+
maxTokens: 4096,
|
|
275
|
+
temperature: 0.7,
|
|
276
|
+
};
|
|
277
|
+
case 'custom':
|
|
278
|
+
return {
|
|
279
|
+
...baseConfig,
|
|
280
|
+
apiEndpoint: 'http://localhost:8080/v1/chat/completions',
|
|
281
|
+
timeout: 30000,
|
|
282
|
+
maxTokens: 2048,
|
|
283
|
+
temperature: 0.7,
|
|
284
|
+
};
|
|
285
|
+
default:
|
|
286
|
+
return {
|
|
287
|
+
...baseConfig,
|
|
288
|
+
timeout: 30000,
|
|
289
|
+
maxTokens: 2048,
|
|
290
|
+
temperature: 0.7,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// Get list of all providers (for display)
|
|
295
|
+
export function getAllProvidersForDisplay() {
|
|
296
|
+
return VALID_PROVIDERS.map(provider => ({
|
|
297
|
+
id: provider,
|
|
298
|
+
name: PROVIDER_DB[provider].name,
|
|
299
|
+
description: PROVIDER_DB[provider].description,
|
|
300
|
+
requiresKey: PROVIDER_DB[provider].requiresApiKey,
|
|
301
|
+
defaultModel: PROVIDER_DB[provider].defaultModel,
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=providers.js.map
|