@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
package/dist/ai/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Module Exports
|
|
3
|
+
* Provides unified interface for AI functionality
|
|
4
|
+
*/
|
|
5
|
+
// Export simplified AI functionality
|
|
6
|
+
export { SimpleAI, AIError } from './ai.js';
|
|
7
|
+
export { SimpleAIConfigManager } from './config.js';
|
|
8
|
+
export { SimpleAICommand } from './command.js';
|
|
9
|
+
// Export Cloud LLM Intent Engine
|
|
10
|
+
export { CloudIntentEngine, } from './cloud-intent-engine.js';
|
|
11
|
+
// Legacy exports (for backward compatibility)
|
|
12
|
+
export { EnhancedIntentEngine } from './enhanced-intent.js';
|
|
13
|
+
export { IntentEngine } from './intent.js';
|
|
14
|
+
/**
|
|
15
|
+
* Check AI capabilities
|
|
16
|
+
* Simplified version without vector database
|
|
17
|
+
*/
|
|
18
|
+
export async function checkAICapabilities(config) {
|
|
19
|
+
// Check if AI is configured
|
|
20
|
+
const aiConfig = config || {};
|
|
21
|
+
if (aiConfig.provider && aiConfig.provider !== 'none') {
|
|
22
|
+
return {
|
|
23
|
+
aiAvailable: true,
|
|
24
|
+
mode: 'api',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
aiAvailable: false,
|
|
29
|
+
mode: 'none',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get AI system status
|
|
34
|
+
*/
|
|
35
|
+
export async function getAIStatus(config) {
|
|
36
|
+
const capabilities = await checkAICapabilities(config);
|
|
37
|
+
return {
|
|
38
|
+
...capabilities,
|
|
39
|
+
timestamp: new Date().toISOString(),
|
|
40
|
+
version: '0.2.1',
|
|
41
|
+
note: 'Vector database functionality has been removed. Use external AI services for semantic search.',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Intent Engine
|
|
3
|
+
* Simple intent parsing for basic functionality
|
|
4
|
+
*/
|
|
5
|
+
export interface IntentResult {
|
|
6
|
+
service: string;
|
|
7
|
+
method: string;
|
|
8
|
+
parameters: Record<string, any>;
|
|
9
|
+
confidence: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class IntentEngine {
|
|
12
|
+
private config;
|
|
13
|
+
constructor(config: any);
|
|
14
|
+
parse(query: string, availableTools: string[]): Promise<IntentResult | null>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=intent.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Intent Engine
|
|
3
|
+
* Simple intent parsing for basic functionality
|
|
4
|
+
*/
|
|
5
|
+
export class IntentEngine {
|
|
6
|
+
config;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
// Initialize with configuration
|
|
10
|
+
}
|
|
11
|
+
async parse(query, availableTools) {
|
|
12
|
+
// Simple keyword matching
|
|
13
|
+
const queryLower = query.toLowerCase();
|
|
14
|
+
for (const tool of availableTools) {
|
|
15
|
+
const [service, method] = tool.split(':');
|
|
16
|
+
// Check if query contains service or method name
|
|
17
|
+
if (service.toLowerCase().includes(queryLower) ||
|
|
18
|
+
method.toLowerCase().includes(queryLower)) {
|
|
19
|
+
return {
|
|
20
|
+
service,
|
|
21
|
+
method,
|
|
22
|
+
parameters: {},
|
|
23
|
+
confidence: 0.6,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=intent.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AIProvider } from './types';
|
|
2
|
+
export interface SimpleAIConfig {
|
|
3
|
+
provider: AIProvider;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
model?: string;
|
|
6
|
+
options?: {
|
|
7
|
+
apiEndpoint?: string;
|
|
8
|
+
ollamaHost?: string;
|
|
9
|
+
localModelPath?: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
temperature?: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare class SimpleAIConfigParser {
|
|
16
|
+
static parse(args: string[]): SimpleAIConfig | null;
|
|
17
|
+
private static looksLikeApiKey;
|
|
18
|
+
static applyConfig(config: SimpleAIConfig, confirm?: boolean): Promise<boolean>;
|
|
19
|
+
private static showConfigSummary;
|
|
20
|
+
static showAIStatus(): void;
|
|
21
|
+
static listProviders(): void;
|
|
22
|
+
static listModels(providerInput?: string): void;
|
|
23
|
+
static close(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ai-config.d.ts.map
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { PROVIDER_DB, autoCorrectProvider, findSimilarProviders, getDefaultConfigForProvider, getProviderDisplayName, } from './providers.js';
|
|
3
|
+
import { AIErrorHandler } from './error-ai.js';
|
|
4
|
+
import { ConfigValidator } from './config-validator.js';
|
|
5
|
+
import { CONFIG_PATH } from './constants.js';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as readline from 'readline';
|
|
8
|
+
// Create readline interface
|
|
9
|
+
const rl = readline.createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
});
|
|
13
|
+
const question = (query) => {
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
rl.question(query, resolve);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export class SimpleAIConfigParser {
|
|
19
|
+
// Parse simple command: mcp ai use openai sk-xxx [model]
|
|
20
|
+
static parse(args) {
|
|
21
|
+
if (args.length === 0) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const inputProvider = args[0];
|
|
25
|
+
let apiKey;
|
|
26
|
+
let model;
|
|
27
|
+
// Try to correct provider name
|
|
28
|
+
const correction = autoCorrectProvider(inputProvider);
|
|
29
|
+
if (!correction.corrected) {
|
|
30
|
+
// Provider name error, show error message
|
|
31
|
+
const similar = findSimilarProviders(inputProvider, 3);
|
|
32
|
+
AIErrorHandler.handleProviderError(inputProvider, similar);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const provider = correction.corrected;
|
|
36
|
+
// If corrected, ask user for confirmation
|
|
37
|
+
if (correction.confidence < 100 && correction.confidence >= 30) {
|
|
38
|
+
console.log(chalk.yellow(`š¤ Detected possible spelling error: '${inputProvider}'`));
|
|
39
|
+
console.log(chalk.cyan(`š Did you mean to enter: '${provider}'?`));
|
|
40
|
+
// In actual implementation, we should ask user for confirmation
|
|
41
|
+
// For simplicity, we assume user accepts the correction
|
|
42
|
+
console.log(chalk.green(`ā
Auto-corrected to: ${provider}`));
|
|
43
|
+
}
|
|
44
|
+
// Parse API key and model
|
|
45
|
+
if (args.length >= 2) {
|
|
46
|
+
// Second argument could be API key or model
|
|
47
|
+
const secondArg = args[1];
|
|
48
|
+
const providerInfo = PROVIDER_DB[provider];
|
|
49
|
+
// Check if second argument is a known model for this provider
|
|
50
|
+
const isKnownModel = providerInfo.modelDescriptions &&
|
|
51
|
+
secondArg in providerInfo.modelDescriptions;
|
|
52
|
+
// Check if it's an API key
|
|
53
|
+
const looksLikeKey = this.looksLikeApiKey(secondArg);
|
|
54
|
+
if (providerInfo.requiresApiKey) {
|
|
55
|
+
if (looksLikeKey && !isKnownModel) {
|
|
56
|
+
// Looks like an API key and not a known model
|
|
57
|
+
apiKey = secondArg;
|
|
58
|
+
// Third argument could be model
|
|
59
|
+
if (args.length >= 3) {
|
|
60
|
+
model = args[2];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Either doesn't look like API key or is a known model name
|
|
65
|
+
model = secondArg;
|
|
66
|
+
// If provider requires API key but we're treating second arg as model,
|
|
67
|
+
// check if it might be intended as an API key
|
|
68
|
+
if (!isKnownModel && secondArg.length < 10 && !secondArg.startsWith('sk-')) {
|
|
69
|
+
console.log(chalk.yellow(`ā ļø Note: '${secondArg}' is being treated as a model name.`));
|
|
70
|
+
console.log(chalk.yellow(' If it\'s an API key, make sure it\'s at least 10 characters long'));
|
|
71
|
+
console.log(chalk.yellow(' or starts with \'sk-\' (like \'sk-xxx...\').'));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Provider doesn't require API key, so second argument must be model
|
|
77
|
+
model = secondArg;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Use default model if not specified
|
|
81
|
+
if (!model) {
|
|
82
|
+
model = PROVIDER_DB[provider].defaultModel;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
provider,
|
|
86
|
+
apiKey,
|
|
87
|
+
model,
|
|
88
|
+
options: {},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Check if string looks like an API key
|
|
92
|
+
static looksLikeApiKey(str) {
|
|
93
|
+
// OpenAI: sk-xxx
|
|
94
|
+
if (str.startsWith('sk-')) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
// Anthropic: sk-ant-xxx
|
|
98
|
+
if (str.startsWith('sk-ant-')) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
// Cohere and other providers: various formats
|
|
102
|
+
// Generic: contains at least 10 characters, may contain alphanumeric and hyphens
|
|
103
|
+
if (str.length >= 10 && /^[a-zA-Z0-9_-]+$/.test(str)) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
// Apply configuration to system
|
|
109
|
+
static async applyConfig(config, confirm = true) {
|
|
110
|
+
try {
|
|
111
|
+
// Read current configuration
|
|
112
|
+
let currentConfig;
|
|
113
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
114
|
+
const configData = fs.readFileSync(CONFIG_PATH, 'utf-8');
|
|
115
|
+
currentConfig = JSON.parse(configData);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
currentConfig = ConfigValidator.getDefaultConfig();
|
|
119
|
+
}
|
|
120
|
+
// Get default configuration for provider
|
|
121
|
+
const defaultProviderConfig = getDefaultConfigForProvider(config.provider);
|
|
122
|
+
// Build new AI configuration
|
|
123
|
+
const newAIConfig = {
|
|
124
|
+
...defaultProviderConfig,
|
|
125
|
+
...(config.apiKey && { apiKey: config.apiKey }),
|
|
126
|
+
...(config.model && { model: config.model }),
|
|
127
|
+
...config.options,
|
|
128
|
+
};
|
|
129
|
+
// Verify configuration
|
|
130
|
+
const validatedAIConfig = ConfigValidator.validateAIConfig(newAIConfig);
|
|
131
|
+
// Update complete configuration
|
|
132
|
+
currentConfig.ai = validatedAIConfig;
|
|
133
|
+
// If confirmation needed, show configuration summary
|
|
134
|
+
if (confirm) {
|
|
135
|
+
console.log(chalk.blue('\nš Configuration summary:'));
|
|
136
|
+
console.log(chalk.gray('='.repeat(40)));
|
|
137
|
+
console.log(`Provider: ${chalk.cyan(getProviderDisplayName(config.provider))}`);
|
|
138
|
+
console.log(`Model: ${chalk.cyan(validatedAIConfig.model)}`);
|
|
139
|
+
if (validatedAIConfig.apiKey) {
|
|
140
|
+
const maskedKey = '***' + validatedAIConfig.apiKey.slice(-4);
|
|
141
|
+
console.log(`API key: ${chalk.green(maskedKey)}`);
|
|
142
|
+
}
|
|
143
|
+
if (validatedAIConfig.apiEndpoint) {
|
|
144
|
+
console.log(`API endpoint: ${chalk.cyan(validatedAIConfig.apiEndpoint)}`);
|
|
145
|
+
}
|
|
146
|
+
if (validatedAIConfig.ollamaHost) {
|
|
147
|
+
console.log(`Ollama host: ${chalk.cyan(validatedAIConfig.ollamaHost)}`);
|
|
148
|
+
}
|
|
149
|
+
if (validatedAIConfig.localModelPath) {
|
|
150
|
+
console.log(`Local model path: ${chalk.cyan(validatedAIConfig.localModelPath)}`);
|
|
151
|
+
}
|
|
152
|
+
console.log(chalk.gray('='.repeat(40)));
|
|
153
|
+
const answer = await question('\nConfirm applying this configuration? (y/N): ');
|
|
154
|
+
if (answer.toLowerCase() !== 'y') {
|
|
155
|
+
console.log(chalk.yellow('Configuration cancelled'));
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Save configuration
|
|
160
|
+
const validatedConfig = ConfigValidator.validate(currentConfig);
|
|
161
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(validatedConfig, null, 2));
|
|
162
|
+
console.log(chalk.green('\nā
AI configuration updated!'));
|
|
163
|
+
// Show configuration details
|
|
164
|
+
this.showConfigSummary(validatedConfig.ai, config.provider);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
AIErrorHandler.handleError({
|
|
169
|
+
type: 'config',
|
|
170
|
+
message: `Configuration failed: ${error.message}`,
|
|
171
|
+
provider: config.provider,
|
|
172
|
+
details: error,
|
|
173
|
+
});
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Show configuration summary
|
|
178
|
+
static showConfigSummary(aiConfig, provider) {
|
|
179
|
+
const providerInfo = PROVIDER_DB[provider];
|
|
180
|
+
console.log(chalk.blue('\nšÆ Configuration details:'));
|
|
181
|
+
console.log(chalk.gray('='.repeat(40)));
|
|
182
|
+
console.log(`š¤ ${providerInfo.name}`);
|
|
183
|
+
console.log(` Model: ${chalk.cyan(aiConfig.model)}`);
|
|
184
|
+
if (aiConfig.apiKey) {
|
|
185
|
+
console.log(` API key: ${chalk.green('Configured')}`);
|
|
186
|
+
}
|
|
187
|
+
if (aiConfig.timeout) {
|
|
188
|
+
console.log(` Timeout: ${chalk.cyan(aiConfig.timeout + 'ms')}`);
|
|
189
|
+
}
|
|
190
|
+
if (aiConfig.maxTokens) {
|
|
191
|
+
console.log(` Max tokens: ${chalk.cyan(aiConfig.maxTokens)}`);
|
|
192
|
+
}
|
|
193
|
+
if (aiConfig.temperature !== undefined) {
|
|
194
|
+
console.log(` Temperature: ${chalk.cyan(aiConfig.temperature)}`);
|
|
195
|
+
}
|
|
196
|
+
console.log(chalk.gray('='.repeat(40)));
|
|
197
|
+
console.log(chalk.green('\nš” Next steps:'));
|
|
198
|
+
console.log(` ⢠Test connection: ${chalk.cyan('mcp ai test')}`);
|
|
199
|
+
console.log(` ⢠Use AI: ${chalk.cyan('mcp ai "your question"')}`);
|
|
200
|
+
console.log(` ⢠View configuration: ${chalk.cyan('mcp ai config')}`);
|
|
201
|
+
}
|
|
202
|
+
// Show current AI status
|
|
203
|
+
static showAIStatus() {
|
|
204
|
+
try {
|
|
205
|
+
let config;
|
|
206
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
207
|
+
const configData = fs.readFileSync(CONFIG_PATH, 'utf-8');
|
|
208
|
+
config = JSON.parse(configData);
|
|
209
|
+
config = ConfigValidator.validate(config);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
config = ConfigValidator.getDefaultConfig();
|
|
213
|
+
}
|
|
214
|
+
const aiConfig = config.ai;
|
|
215
|
+
const provider = aiConfig.provider;
|
|
216
|
+
const providerInfo = PROVIDER_DB[provider];
|
|
217
|
+
console.log(chalk.blue('\nš¤ AI configuration status'));
|
|
218
|
+
console.log(chalk.gray('='.repeat(50)));
|
|
219
|
+
if (providerInfo) {
|
|
220
|
+
console.log(`Provider: ${chalk.cyan(providerInfo.name)}`);
|
|
221
|
+
console.log(`Status: ${chalk.green('Configured')}`);
|
|
222
|
+
console.log(`Model: ${chalk.cyan(aiConfig.model)}`);
|
|
223
|
+
if (aiConfig.apiKey) {
|
|
224
|
+
console.log(`API key: ${chalk.green('Set')}`);
|
|
225
|
+
}
|
|
226
|
+
else if (providerInfo.requiresApiKey) {
|
|
227
|
+
console.log(`API key: ${chalk.yellow('Not set')}`);
|
|
228
|
+
}
|
|
229
|
+
// Show specific configuration
|
|
230
|
+
if (aiConfig.apiEndpoint) {
|
|
231
|
+
console.log(`API endpoint: ${chalk.cyan(aiConfig.apiEndpoint)}`);
|
|
232
|
+
}
|
|
233
|
+
if (aiConfig.ollamaHost) {
|
|
234
|
+
console.log(`Ollama host: ${chalk.cyan(aiConfig.ollamaHost)}`);
|
|
235
|
+
}
|
|
236
|
+
if (aiConfig.localModelPath) {
|
|
237
|
+
console.log(`Local model: ${chalk.cyan(aiConfig.localModelPath)}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
console.log(`Provider: ${chalk.yellow(provider)}`);
|
|
242
|
+
console.log(`Status: ${chalk.yellow('Unknown provider')}`);
|
|
243
|
+
}
|
|
244
|
+
console.log(chalk.gray('='.repeat(50)));
|
|
245
|
+
console.log(chalk.green('\nš” Available commands:'));
|
|
246
|
+
console.log(` ⢠Configure AI: ${chalk.cyan('mcp ai use <provider> [api-key] [model]')}`);
|
|
247
|
+
console.log(` ⢠Test connection: ${chalk.cyan('mcp ai test')}`);
|
|
248
|
+
console.log(` ⢠View providers: ${chalk.cyan('mcp ai providers')}`);
|
|
249
|
+
console.log(` ⢠Use AI: ${chalk.cyan('mcp ai "your question"')}`);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
console.log(chalk.red(`ā Unable to read configuration: ${error.message}`));
|
|
253
|
+
console.log(chalk.yellow('\nš” Try reconfiguring:'));
|
|
254
|
+
console.log(' mcp ai use openai <your-api-key>');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// List all providers
|
|
258
|
+
static listProviders() {
|
|
259
|
+
console.log(chalk.blue('\nš Supported AI providers'));
|
|
260
|
+
console.log(chalk.gray('='.repeat(60)));
|
|
261
|
+
Object.entries(PROVIDER_DB).forEach(([id, info], index) => {
|
|
262
|
+
console.log(chalk.yellow(`\n${index + 1}. ${info.name} (${chalk.cyan(id)})`));
|
|
263
|
+
console.log(` ${info.description}`);
|
|
264
|
+
if (info.requiresApiKey) {
|
|
265
|
+
console.log(` š Requires API key: ${chalk.yellow('Yes')}`);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
console.log(` š Requires API key: ${chalk.green('No')}`);
|
|
269
|
+
}
|
|
270
|
+
console.log(` š¤ Default model: ${chalk.cyan(info.defaultModel)}`);
|
|
271
|
+
if (info.aliases.length > 0) {
|
|
272
|
+
console.log(` š¤ Aliases: ${chalk.gray(info.aliases.join(', '))}`);
|
|
273
|
+
}
|
|
274
|
+
if (info.configHint) {
|
|
275
|
+
console.log(` š” ${info.configHint}`);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
console.log(chalk.gray('='.repeat(60)));
|
|
279
|
+
console.log(chalk.green('\nš” Usage examples:'));
|
|
280
|
+
console.log(` ⢠Configure OpenAI: ${chalk.cyan('mcp ai use openai sk-xxx')}`);
|
|
281
|
+
console.log(` ⢠Configure Ollama: ${chalk.cyan('mcp ai use ollama')}`);
|
|
282
|
+
console.log(` ⢠Specify model: ${chalk.cyan('mcp ai use openai sk-xxx gpt-3.5-turbo')}`);
|
|
283
|
+
}
|
|
284
|
+
// List provider's models
|
|
285
|
+
static listModels(providerInput) {
|
|
286
|
+
if (!providerInput) {
|
|
287
|
+
console.log(chalk.yellow('Please specify provider, for example:'));
|
|
288
|
+
console.log(` ${chalk.cyan('mcp ai models openai')}`);
|
|
289
|
+
console.log(` ${chalk.cyan('mcp ai models ollama')}`);
|
|
290
|
+
console.log(chalk.green('\nAvailable providers:'));
|
|
291
|
+
console.log(` ${Object.keys(PROVIDER_DB).join(', ')}`);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
// Try to correct provider name
|
|
295
|
+
const correction = autoCorrectProvider(providerInput);
|
|
296
|
+
if (!correction.corrected) {
|
|
297
|
+
const similar = findSimilarProviders(providerInput, 3);
|
|
298
|
+
AIErrorHandler.handleProviderError(providerInput, similar);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const provider = correction.corrected;
|
|
302
|
+
const providerInfo = PROVIDER_DB[provider];
|
|
303
|
+
console.log(chalk.blue(`\nš ${providerInfo.name} available models`));
|
|
304
|
+
console.log(chalk.gray('='.repeat(50)));
|
|
305
|
+
if (providerInfo.modelDescriptions) {
|
|
306
|
+
Object.entries(providerInfo.modelDescriptions).forEach(([model, description]) => {
|
|
307
|
+
const isDefault = model === providerInfo.defaultModel;
|
|
308
|
+
console.log(` ⢠${chalk.cyan(model)} ${isDefault ? chalk.green('(default)') : ''}`);
|
|
309
|
+
console.log(` ${description}`);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.log(` ${chalk.yellow('This provider has no predefined model list')}`);
|
|
314
|
+
console.log(` ${chalk.gray('Please check provider documentation for available models')}`);
|
|
315
|
+
}
|
|
316
|
+
console.log(chalk.gray('='.repeat(50)));
|
|
317
|
+
console.log(chalk.green('\nš” Configuration examples:'));
|
|
318
|
+
console.log(` ⢠Use default model: ${chalk.cyan(`mcp ai use ${provider}`)}`);
|
|
319
|
+
console.log(` ⢠Specify model: ${chalk.cyan(`mcp ai use ${provider} [api-key] <model-name>`)}`);
|
|
320
|
+
}
|
|
321
|
+
// Close readline interface
|
|
322
|
+
static close() {
|
|
323
|
+
rl.close();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=ai-config.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ServiceConfig, RuntimeType, RuntimeSpecificConfig, DockerConnectionConfig, DetectionResult, Config } from './types';
|
|
2
|
+
export declare class ConfigManager {
|
|
3
|
+
private static CONFIG_DIR;
|
|
4
|
+
private static SERVICES_DIR;
|
|
5
|
+
private static DOCKER_HOSTS_DIR;
|
|
6
|
+
private static RUNTIME_PROFILES_DIR;
|
|
7
|
+
private static GLOBAL_CONFIG_PATH;
|
|
8
|
+
private static serviceConfigCache;
|
|
9
|
+
private static servicesListCache;
|
|
10
|
+
private static globalConfigCache;
|
|
11
|
+
private static dockerHostsCache;
|
|
12
|
+
private static runtimeProfilesCache;
|
|
13
|
+
static init(): void;
|
|
14
|
+
static getServiceConfig(serviceName: string): ServiceConfig | null;
|
|
15
|
+
static saveServiceConfig(serviceName: string, config: ServiceConfig): void;
|
|
16
|
+
static updateServiceDetection(serviceName: string, detection: DetectionResult): ServiceConfig;
|
|
17
|
+
static setServiceRuntime(serviceName: string, runtime: RuntimeType, runtimeConfig?: RuntimeSpecificConfig): ServiceConfig;
|
|
18
|
+
static getDockerHostConfig(hostName: string): DockerConnectionConfig | null;
|
|
19
|
+
static saveDockerHostConfig(hostName: string, config: DockerConnectionConfig): void;
|
|
20
|
+
static deleteDockerHostConfig(hostName: string): void;
|
|
21
|
+
static listDockerHosts(): string[];
|
|
22
|
+
static getRuntimeProfile(runtime: RuntimeType): RuntimeSpecificConfig | null;
|
|
23
|
+
static saveRuntimeProfile(runtime: RuntimeType, config: RuntimeSpecificConfig): void;
|
|
24
|
+
static getGlobalConfig(): Config;
|
|
25
|
+
static saveGlobalConfig(config: Partial<Config>): void;
|
|
26
|
+
private static getServiceConfigPath;
|
|
27
|
+
private static ensureDefaultDockerHosts;
|
|
28
|
+
private static ensureDefaultRuntimeProfiles;
|
|
29
|
+
private static getDefaultGlobalConfig;
|
|
30
|
+
static resolveServiceConfig(userConfig: Partial<ServiceConfig>, servicePath: string): ServiceConfig;
|
|
31
|
+
static validateServiceConfig(config: ServiceConfig): string[];
|
|
32
|
+
static getAllServices(): string[];
|
|
33
|
+
static getServiceDetectionCache(serviceName: string): DetectionResult | null;
|
|
34
|
+
static saveServiceDetectionCache(serviceName: string, detection: DetectionResult): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=config-manager.d.ts.map
|