@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.
Files changed (101) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +545 -0
  3. package/dist/ai/ai.d.ts +205 -0
  4. package/dist/ai/ai.js +1200 -0
  5. package/dist/ai/cloud-intent-engine.d.ts +270 -0
  6. package/dist/ai/cloud-intent-engine.js +956 -0
  7. package/dist/ai/command.d.ts +59 -0
  8. package/dist/ai/command.js +285 -0
  9. package/dist/ai/config.d.ts +66 -0
  10. package/dist/ai/config.js +211 -0
  11. package/dist/ai/enhanced-intent.d.ts +17 -0
  12. package/dist/ai/enhanced-intent.js +32 -0
  13. package/dist/ai/index.d.ts +29 -0
  14. package/dist/ai/index.js +44 -0
  15. package/dist/ai/intent.d.ts +16 -0
  16. package/dist/ai/intent.js +30 -0
  17. package/dist/core/ai-config.d.ts +25 -0
  18. package/dist/core/ai-config.js +326 -0
  19. package/dist/core/config-manager.d.ts +36 -0
  20. package/dist/core/config-manager.js +400 -0
  21. package/dist/core/config-validator.d.ts +9 -0
  22. package/dist/core/config-validator.js +184 -0
  23. package/dist/core/constants.d.ts +34 -0
  24. package/dist/core/constants.js +37 -0
  25. package/dist/core/error-ai.d.ts +23 -0
  26. package/dist/core/error-ai.js +217 -0
  27. package/dist/core/error-handler.d.ts +197 -0
  28. package/dist/core/error-handler.js +467 -0
  29. package/dist/core/index.d.ts +13 -0
  30. package/dist/core/index.js +17 -0
  31. package/dist/core/logger.d.ts +27 -0
  32. package/dist/core/logger.js +108 -0
  33. package/dist/core/performance-monitor.d.ts +74 -0
  34. package/dist/core/performance-monitor.js +260 -0
  35. package/dist/core/providers.d.ts +36 -0
  36. package/dist/core/providers.js +304 -0
  37. package/dist/core/retry-manager.d.ts +41 -0
  38. package/dist/core/retry-manager.js +204 -0
  39. package/dist/core/types.d.ts +155 -0
  40. package/dist/core/types.js +2 -0
  41. package/dist/daemon/index.d.ts +10 -0
  42. package/dist/daemon/index.js +15 -0
  43. package/dist/daemon/intent-engine.d.ts +22 -0
  44. package/dist/daemon/intent-engine.js +50 -0
  45. package/dist/daemon/orchestrator.d.ts +24 -0
  46. package/dist/daemon/orchestrator.js +100 -0
  47. package/dist/daemon/pm.d.ts +33 -0
  48. package/dist/daemon/pm.js +127 -0
  49. package/dist/daemon/process.d.ts +11 -0
  50. package/dist/daemon/process.js +49 -0
  51. package/dist/daemon/server.d.ts +17 -0
  52. package/dist/daemon/server.js +435 -0
  53. package/dist/daemon/service.d.ts +36 -0
  54. package/dist/daemon/service.js +278 -0
  55. package/dist/index.d.ts +30 -0
  56. package/dist/index.js +36 -0
  57. package/dist/mcp/client.d.ts +51 -0
  58. package/dist/mcp/client.js +276 -0
  59. package/dist/mcp/index.d.ts +162 -0
  60. package/dist/mcp/index.js +199 -0
  61. package/dist/mcp/tool-registry.d.ts +71 -0
  62. package/dist/mcp/tool-registry.js +308 -0
  63. package/dist/mcp/transport.d.ts +83 -0
  64. package/dist/mcp/transport.js +515 -0
  65. package/dist/mcp/types.d.ts +136 -0
  66. package/dist/mcp/types.js +31 -0
  67. package/dist/runtime/adapter-advanced.d.ts +184 -0
  68. package/dist/runtime/adapter-advanced.js +160 -0
  69. package/dist/runtime/adapter.d.ts +9 -0
  70. package/dist/runtime/adapter.js +2 -0
  71. package/dist/runtime/detector-advanced.d.ts +59 -0
  72. package/dist/runtime/detector-advanced.js +487 -0
  73. package/dist/runtime/detector.d.ts +5 -0
  74. package/dist/runtime/detector.js +56 -0
  75. package/dist/runtime/docker-adapter.d.ts +18 -0
  76. package/dist/runtime/docker-adapter.js +170 -0
  77. package/dist/runtime/docker.d.ts +17 -0
  78. package/dist/runtime/docker.js +71 -0
  79. package/dist/runtime/executable-analyzer.d.ts +56 -0
  80. package/dist/runtime/executable-analyzer.js +391 -0
  81. package/dist/runtime/go-adapter.d.ts +19 -0
  82. package/dist/runtime/go-adapter.js +190 -0
  83. package/dist/runtime/index.d.ts +9 -0
  84. package/dist/runtime/index.js +10 -0
  85. package/dist/runtime/node-adapter.d.ts +10 -0
  86. package/dist/runtime/node-adapter.js +23 -0
  87. package/dist/runtime/node.d.ts +20 -0
  88. package/dist/runtime/node.js +86 -0
  89. package/dist/runtime/python-adapter.d.ts +11 -0
  90. package/dist/runtime/python-adapter.js +102 -0
  91. package/dist/runtime/python.d.ts +17 -0
  92. package/dist/runtime/python.js +72 -0
  93. package/dist/runtime/rust-adapter.d.ts +21 -0
  94. package/dist/runtime/rust-adapter.js +267 -0
  95. package/dist/sdk.d.ts +500 -0
  96. package/dist/sdk.js +904 -0
  97. package/docs/README.ZH_CN.md +545 -0
  98. package/docs/api.md +888 -0
  99. package/docs/architecture.md +731 -0
  100. package/docs/development.md +744 -0
  101. package/package.json +112 -0
@@ -0,0 +1,41 @@
1
+ export interface RetryOptions {
2
+ maxRetries?: number;
3
+ initialDelay?: number;
4
+ maxDelay?: number;
5
+ backoffFactor?: number;
6
+ jitter?: boolean;
7
+ retryableErrors?: string[];
8
+ nonRetryableErrors?: string[];
9
+ }
10
+ export interface RetryResult<T> {
11
+ success: boolean;
12
+ result?: T;
13
+ error?: Error;
14
+ attempts: number;
15
+ totalTime: number;
16
+ }
17
+ export declare class RetryManager {
18
+ static executeWithRetry<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<RetryResult<T>>;
19
+ private static calculateDelay;
20
+ private static isRetryableError;
21
+ private static isNonRetryableError;
22
+ private static isNetworkError;
23
+ private static isTimeoutError;
24
+ private static isConfigurationError;
25
+ private static isAuthenticationError;
26
+ private static delay;
27
+ static executeBatchWithRetry<T>(operations: Array<() => Promise<T>>, options?: RetryOptions): Promise<Array<RetryResult<T>>>;
28
+ static createCircuitBreaker(options?: {
29
+ failureThreshold?: number;
30
+ resetTimeout?: number;
31
+ halfOpenMaxAttempts?: number;
32
+ }): <T>(operation: () => Promise<T>, retryOptions?: RetryOptions) => Promise<RetryResult<T>>;
33
+ static getStats(): {
34
+ totalOperations: number;
35
+ successfulOperations: number;
36
+ failedOperations: number;
37
+ averageRetries: number;
38
+ averageTime: number;
39
+ };
40
+ }
41
+ //# sourceMappingURL=retry-manager.d.ts.map
@@ -0,0 +1,204 @@
1
+ import { logger } from './logger.js';
2
+ export class RetryManager {
3
+ static async executeWithRetry(operation, options = {}) {
4
+ const { maxRetries = 3, initialDelay = 1000, maxDelay = 30000, backoffFactor = 2, jitter = true, retryableErrors = [], nonRetryableErrors = [], } = options;
5
+ let lastError;
6
+ const startTime = Date.now();
7
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
8
+ try {
9
+ if (attempt > 0) {
10
+ const delay = this.calculateDelay(attempt, initialDelay, maxDelay, backoffFactor, jitter);
11
+ logger.info(`Retry attempt ${attempt}/${maxRetries} after ${delay}ms delay`);
12
+ await this.delay(delay);
13
+ }
14
+ const result = await operation();
15
+ if (attempt > 0) {
16
+ logger.info(`Success on retry attempt ${attempt}`);
17
+ }
18
+ return {
19
+ success: true,
20
+ result,
21
+ attempts: attempt + 1,
22
+ totalTime: Date.now() - startTime,
23
+ };
24
+ }
25
+ catch (error) {
26
+ lastError = error;
27
+ // Check if it's a non-retryable error
28
+ if (this.isNonRetryableError(error, nonRetryableErrors)) {
29
+ logger.warn(`Non-retryable error encountered: ${error.message}`);
30
+ break;
31
+ }
32
+ // Check if it's a retryable error
33
+ const shouldRetry = attempt < maxRetries &&
34
+ (retryableErrors.length === 0 || this.isRetryableError(error, retryableErrors));
35
+ logger.warn(`Attempt ${attempt + 1} failed: ${error.message}`);
36
+ if (shouldRetry) {
37
+ const nextDelay = this.calculateDelay(attempt + 1, initialDelay, maxDelay, backoffFactor, jitter);
38
+ logger.info(`Will retry in ${nextDelay}ms`);
39
+ }
40
+ else {
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ return {
46
+ success: false,
47
+ error: lastError || new Error('Operation failed'),
48
+ attempts: maxRetries + 1,
49
+ totalTime: Date.now() - startTime,
50
+ };
51
+ }
52
+ static calculateDelay(attempt, initialDelay, maxDelay, backoffFactor, jitter) {
53
+ // Exponential backoff
54
+ let delay = initialDelay * Math.pow(backoffFactor, attempt - 1);
55
+ // Add jitter (randomness)
56
+ if (jitter) {
57
+ const jitterAmount = delay * 0.1; // 10% jitter
58
+ delay += Math.random() * jitterAmount * 2 - jitterAmount;
59
+ }
60
+ // Limit maximum delay
61
+ return Math.min(delay, maxDelay);
62
+ }
63
+ static isRetryableError(error, retryableErrors) {
64
+ if (retryableErrors.length === 0) {
65
+ // Default retry network errors and timeout errors
66
+ return this.isNetworkError(error) || this.isTimeoutError(error);
67
+ }
68
+ const errorMessage = error.message.toLowerCase();
69
+ return retryableErrors.some(pattern => errorMessage.includes(pattern.toLowerCase()));
70
+ }
71
+ static isNonRetryableError(error, nonRetryableErrors) {
72
+ if (nonRetryableErrors.length === 0) {
73
+ // Default don't retry configuration errors and authentication errors
74
+ return this.isConfigurationError(error) || this.isAuthenticationError(error);
75
+ }
76
+ const errorMessage = error.message.toLowerCase();
77
+ return nonRetryableErrors.some(pattern => errorMessage.includes(pattern.toLowerCase()));
78
+ }
79
+ static isNetworkError(error) {
80
+ const networkKeywords = [
81
+ 'network', 'connection', 'socket', 'timeout', 'econnrefused',
82
+ 'econnreset', 'eaddrinuse', 'eaddrinfo', 'enetunreach',
83
+ 'fetch failed', 'request failed', 'aborted',
84
+ ];
85
+ const errorMessage = error.message.toLowerCase();
86
+ return networkKeywords.some(keyword => errorMessage.includes(keyword));
87
+ }
88
+ static isTimeoutError(error) {
89
+ const timeoutKeywords = ['timeout', 'timed out', 'aborted'];
90
+ const errorMessage = error.message.toLowerCase();
91
+ return timeoutKeywords.some(keyword => errorMessage.includes(keyword));
92
+ }
93
+ static isConfigurationError(error) {
94
+ const configKeywords = [
95
+ 'configuration', 'config', 'invalid', 'missing', 'required',
96
+ 'not found', 'undefined', 'null', 'api key', 'endpoint',
97
+ ];
98
+ const errorMessage = error.message.toLowerCase();
99
+ return configKeywords.some(keyword => errorMessage.includes(keyword));
100
+ }
101
+ static isAuthenticationError(error) {
102
+ const authKeywords = [
103
+ 'authentication', 'authorization', 'unauthorized', 'forbidden',
104
+ 'invalid token', 'api key', 'credentials', '401', '403',
105
+ ];
106
+ const errorMessage = error.message.toLowerCase();
107
+ return authKeywords.some(keyword => errorMessage.includes(keyword));
108
+ }
109
+ static delay(ms) {
110
+ return new Promise(resolve => setTimeout(resolve, ms));
111
+ }
112
+ // Batch operation retry
113
+ static async executeBatchWithRetry(operations, options = {}) {
114
+ const results = [];
115
+ for (let i = 0; i < operations.length; i++) {
116
+ logger.debug(`Executing batch operation ${i + 1}/${operations.length}`);
117
+ const result = await this.executeWithRetry(operations[i], options);
118
+ results.push(result);
119
+ // If operation fails, can choose to continue or stop
120
+ if (!result.success && options.nonRetryableErrors?.some(pattern => result.error?.message.toLowerCase().includes(pattern.toLowerCase()))) {
121
+ logger.warn(`Stopping batch execution due to non-retryable error in operation ${i + 1}`);
122
+ break;
123
+ }
124
+ }
125
+ return results;
126
+ }
127
+ // Retry with circuit breaker
128
+ static createCircuitBreaker(options = {}) {
129
+ const { failureThreshold = 5, resetTimeout = 60000, // 60seconds
130
+ halfOpenMaxAttempts = 3, } = options;
131
+ let state = 'closed';
132
+ let failureCount = 0;
133
+ let lastFailureTime = 0;
134
+ let halfOpenAttempts = 0;
135
+ return async function withCircuitBreaker(operation, retryOptions) {
136
+ const now = Date.now();
137
+ // Check circuit breaker state
138
+ if (state === 'open') {
139
+ if (now - lastFailureTime > resetTimeout) {
140
+ // Enter half-open state
141
+ state = 'half-open';
142
+ halfOpenAttempts = 0;
143
+ logger.info('Circuit breaker transitioning to half-open state');
144
+ }
145
+ else {
146
+ throw new Error('Circuit breaker is open - service unavailable');
147
+ }
148
+ }
149
+ if (state === 'half-open') {
150
+ if (halfOpenAttempts >= halfOpenMaxAttempts) {
151
+ // Too many attempts in half-open state, reopen
152
+ state = 'open';
153
+ lastFailureTime = now;
154
+ throw new Error('Circuit breaker re-opened - service still unavailable');
155
+ }
156
+ halfOpenAttempts++;
157
+ }
158
+ try {
159
+ const result = await RetryManager.executeWithRetry(operation, retryOptions);
160
+ if (result.success) {
161
+ // Operation successful, reset circuit breaker
162
+ if (state === 'half-open') {
163
+ logger.info('Circuit breaker transitioning to closed state');
164
+ }
165
+ state = 'closed';
166
+ failureCount = 0;
167
+ halfOpenAttempts = 0;
168
+ }
169
+ else {
170
+ // Operation failed, update failure count
171
+ failureCount++;
172
+ lastFailureTime = now;
173
+ if (failureCount >= failureThreshold) {
174
+ state = 'open';
175
+ logger.error(`Circuit breaker opened after ${failureCount} failures`);
176
+ }
177
+ }
178
+ return result;
179
+ }
180
+ catch (error) {
181
+ // Update failure count
182
+ failureCount++;
183
+ lastFailureTime = now;
184
+ if (failureCount >= failureThreshold) {
185
+ state = 'open';
186
+ logger.error(`Circuit breaker opened after ${failureCount} failures`);
187
+ }
188
+ throw error;
189
+ }
190
+ };
191
+ }
192
+ // Monitoring and reporting
193
+ static getStats() {
194
+ // Here you can add actual statistical tracking
195
+ return {
196
+ totalOperations: 0,
197
+ successfulOperations: 0,
198
+ failedOperations: 0,
199
+ averageRetries: 0,
200
+ averageTime: 0,
201
+ };
202
+ }
203
+ }
204
+ //# sourceMappingURL=retry-manager.js.map
@@ -0,0 +1,155 @@
1
+ export type RuntimeType = 'node' | 'python' | 'docker' | 'java' | 'go' | 'rust' | 'binary';
2
+ export interface DockerConnectionConfig {
3
+ type: 'local' | 'remote' | 'socket';
4
+ host?: string;
5
+ port?: number;
6
+ socketPath?: string;
7
+ useTLS?: boolean;
8
+ certs?: {
9
+ ca?: string;
10
+ cert?: string;
11
+ key?: string;
12
+ };
13
+ registryAuth?: {
14
+ username: string;
15
+ password: string;
16
+ serveraddress: string;
17
+ };
18
+ }
19
+ export interface RuntimeSpecificConfig {
20
+ node?: {
21
+ npmRegistry?: string;
22
+ bun?: boolean;
23
+ nodeVersion?: string;
24
+ };
25
+ python?: {
26
+ venv?: boolean;
27
+ mirror?: string;
28
+ pythonVersion?: string;
29
+ dependencies?: string[];
30
+ };
31
+ go?: {
32
+ module?: string;
33
+ build?: boolean;
34
+ goVersion?: string;
35
+ };
36
+ rust?: {
37
+ release?: boolean;
38
+ rustVersion?: string;
39
+ test?: boolean;
40
+ binary?: string;
41
+ debug?: boolean;
42
+ output?: string;
43
+ };
44
+ docker?: DockerConnectionConfig & {
45
+ image?: string;
46
+ dockerfile?: string;
47
+ buildContext?: string;
48
+ ports?: number[];
49
+ volumes?: string[];
50
+ workdir?: string;
51
+ };
52
+ java?: {
53
+ maven?: boolean;
54
+ gradle?: boolean;
55
+ javaVersion?: string;
56
+ };
57
+ }
58
+ export interface DetectionEvidence {
59
+ executableAnalysis?: {
60
+ type: string;
61
+ confidence: number;
62
+ details: any;
63
+ };
64
+ projectFiles?: {
65
+ files: string[];
66
+ confidence: number;
67
+ };
68
+ fileStatistics?: {
69
+ extensions: Record<string, number>;
70
+ confidence: number;
71
+ };
72
+ fileExtensions?: {
73
+ extensions: string[];
74
+ confidence: number;
75
+ };
76
+ }
77
+ export interface DetectionResult {
78
+ runtime: RuntimeType;
79
+ confidence: number;
80
+ evidence: DetectionEvidence;
81
+ source: 'legacy' | 'enhanced' | 'explicit';
82
+ suggestions?: string[];
83
+ warning?: string;
84
+ }
85
+ export type AIProvider = 'openai' | 'anthropic' | 'google' | 'azure' | 'deepseek' | 'cohere' | 'ollama' | 'local' | 'custom' | 'none';
86
+ export interface AIConfig {
87
+ provider: AIProvider;
88
+ model: string;
89
+ apiKey?: string;
90
+ apiEndpoint?: string;
91
+ timeout?: number;
92
+ maxTokens?: number;
93
+ temperature?: number;
94
+ apiVersion?: string;
95
+ region?: string;
96
+ embeddingProvider?: string;
97
+ embeddingApiKey?: string;
98
+ embeddingModel?: string;
99
+ embeddingEndpoint?: string;
100
+ localModelPath?: string;
101
+ ollamaHost?: string;
102
+ customConfig?: Record<string, any>;
103
+ }
104
+ export interface RegistryConfig {
105
+ preferred: string;
106
+ customRegistries?: Record<string, string>;
107
+ }
108
+ export interface ServicesConfig {
109
+ autoStart: string[];
110
+ defaultTimeout?: number;
111
+ }
112
+ export interface Config {
113
+ ai: AIConfig;
114
+ registry: RegistryConfig;
115
+ services: ServicesConfig;
116
+ detectionThreshold?: number;
117
+ defaultDockerHost?: string;
118
+ requireExplicitRuntime?: boolean;
119
+ autoSaveDetection?: boolean;
120
+ interactiveMode?: boolean;
121
+ logLevel?: string;
122
+ }
123
+ export interface ServiceConfig {
124
+ name: string;
125
+ path: string;
126
+ runtime?: RuntimeType;
127
+ detectedRuntime?: RuntimeType;
128
+ detectionConfidence?: number;
129
+ detectionSource?: 'legacy' | 'enhanced' | 'explicit';
130
+ detectionEvidence?: DetectionEvidence;
131
+ runtimeConfig?: RuntimeSpecificConfig;
132
+ dockerHost?: string;
133
+ entry?: string;
134
+ args?: string[];
135
+ env?: Record<string, string>;
136
+ image?: string;
137
+ ports?: number[];
138
+ volumes?: string[];
139
+ workdir?: string;
140
+ dockerfile?: string;
141
+ buildContext?: string;
142
+ build?: boolean;
143
+ output?: string;
144
+ binary?: string;
145
+ trim?: boolean;
146
+ installedAt?: string;
147
+ lastDetectedAt?: string;
148
+ detectionWarning?: string;
149
+ }
150
+ export interface DaemonResponse {
151
+ success: boolean;
152
+ message?: string;
153
+ data?: any;
154
+ }
155
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Daemon Module Exports
3
+ * Provides unified interface for daemon functionality
4
+ */
5
+ export { Orchestrator } from './orchestrator';
6
+ export { IntentEngine } from './intent-engine';
7
+ export { ProcessManager } from './pm';
8
+ export { DaemonServer } from './server';
9
+ export { ServiceManager } from './service';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Daemon Module Exports
3
+ * Provides unified interface for daemon functionality
4
+ */
5
+ // Export orchestrator
6
+ export { Orchestrator } from './orchestrator.js';
7
+ // Export intent engine
8
+ export { IntentEngine } from './intent-engine.js';
9
+ // Export process management
10
+ export { ProcessManager } from './pm.js';
11
+ // Export server
12
+ export { DaemonServer } from './server.js';
13
+ // Export service management
14
+ export { ServiceManager } from './service.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ export declare class IntentEngine {
2
+ private availableTools;
3
+ constructor();
4
+ parse(query: string): Promise<{
5
+ tool: string;
6
+ action: string;
7
+ params: {
8
+ path: string;
9
+ expression?: undefined;
10
+ };
11
+ } | {
12
+ tool: string;
13
+ action: string;
14
+ params: {
15
+ expression: string;
16
+ path?: undefined;
17
+ };
18
+ }>;
19
+ addTool(tool: any): void;
20
+ getTools(): any[];
21
+ }
22
+ //# sourceMappingURL=intent-engine.d.ts.map
@@ -0,0 +1,50 @@
1
+ export class IntentEngine {
2
+ availableTools = [];
3
+ constructor() {
4
+ // For now, we'll have a simple hardcoded list of tools
5
+ this.availableTools = [
6
+ {
7
+ name: 'filesystem',
8
+ description: 'Read and list files in a directory',
9
+ capabilities: ['list_directory', 'read_file'],
10
+ },
11
+ {
12
+ name: 'calculator',
13
+ description: 'Perform mathematical calculations',
14
+ capabilities: ['add', 'subtract', 'multiply', 'divide'],
15
+ },
16
+ ];
17
+ }
18
+ async parse(query) {
19
+ // Simple keyword matching for now
20
+ // In a real implementation, this would use vector search and LLM
21
+ const queryLower = query.toLowerCase();
22
+ if (queryLower.includes('file') || queryLower.includes('directory') || queryLower.includes('list')) {
23
+ return {
24
+ tool: 'filesystem',
25
+ action: 'list_directory',
26
+ params: { path: '.' },
27
+ };
28
+ }
29
+ if (queryLower.includes('calculate') || queryLower.includes('math') || queryLower.includes('add') || queryLower.includes('subtract')) {
30
+ return {
31
+ tool: 'calculator',
32
+ action: 'calculate',
33
+ params: { expression: query },
34
+ };
35
+ }
36
+ // Default fallback
37
+ return {
38
+ tool: 'filesystem',
39
+ action: 'list_directory',
40
+ params: { path: '.' },
41
+ };
42
+ }
43
+ addTool(tool) {
44
+ this.availableTools.push(tool);
45
+ }
46
+ getTools() {
47
+ return this.availableTools;
48
+ }
49
+ }
50
+ //# sourceMappingURL=intent-engine.js.map
@@ -0,0 +1,24 @@
1
+ import { ProcessManager } from './pm';
2
+ export declare class Orchestrator {
3
+ private pm;
4
+ private intentEngine;
5
+ private config;
6
+ constructor(pm: ProcessManager);
7
+ executeQuery(query: string): Promise<{
8
+ success: boolean;
9
+ service: string;
10
+ method: string;
11
+ result: any;
12
+ }>;
13
+ getConfig(): any;
14
+ updateAIConfig(newAIConfig: any): {
15
+ success: boolean;
16
+ config: import("..").AIConfig;
17
+ error?: undefined;
18
+ } | {
19
+ success: boolean;
20
+ error: any;
21
+ config?: undefined;
22
+ };
23
+ }
24
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1,100 @@
1
+ import { EnhancedIntentEngine } from '../ai/enhanced-intent.js';
2
+ import * as fs from 'fs';
3
+ import { CONFIG_PATH } from '../core/constants.js';
4
+ import { ConfigValidator } from '../core/config-validator.js';
5
+ import { logger } from '../core/logger.js';
6
+ export class Orchestrator {
7
+ pm;
8
+ intentEngine;
9
+ config;
10
+ constructor(pm) {
11
+ this.pm = pm;
12
+ // Load and validate configuration
13
+ if (fs.existsSync(CONFIG_PATH)) {
14
+ const rawConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
15
+ this.config = ConfigValidator.mergeWithDefaults(rawConfig);
16
+ logger.info('Configuration loaded and validated');
17
+ }
18
+ else {
19
+ this.config = ConfigValidator.getDefaultConfig();
20
+ logger.warn('Config file not found, using default configuration');
21
+ }
22
+ // Check if AI is enabled
23
+ if (this.config.ai?.enabled !== false) {
24
+ // Use enhanced AI intent engine
25
+ this.intentEngine = new EnhancedIntentEngine(this.config.ai);
26
+ logger.info('AI features enabled (vector database functionality removed)');
27
+ }
28
+ else {
29
+ // AI disabled
30
+ this.intentEngine = null;
31
+ logger.info('AI features disabled');
32
+ }
33
+ }
34
+ async executeQuery(query) {
35
+ logger.info(`Processing query: "${query}"`);
36
+ // Check if AI is enabled
37
+ if (!this.intentEngine) {
38
+ throw new Error('AI features are disabled. Enable AI in configuration to use natural language queries.');
39
+ }
40
+ try {
41
+ // 1. Get all available tools
42
+ const availableServices = this.pm.getRunningServices();
43
+ const availableTools = [];
44
+ for (const service of availableServices) {
45
+ const tools = this.pm.getServiceTools(service);
46
+ if (tools) {
47
+ availableTools.push(...tools.map((tool) => `${service}:${tool.name}`));
48
+ }
49
+ }
50
+ logger.debug(`Available tools: ${availableTools.join(', ')}`);
51
+ // 2. Use AI intent engine to parse user intent
52
+ const toolCall = await this.intentEngine.parse(query, availableTools);
53
+ if (!toolCall) {
54
+ throw new Error('Unable to determine which service to use for your request.');
55
+ }
56
+ logger.info(`AI selected service: ${toolCall.service}.${toolCall.method}`);
57
+ // 3. Call the selected service
58
+ const result = await this.pm.callService(toolCall.service, toolCall.method, toolCall.parameters);
59
+ return {
60
+ success: true,
61
+ service: toolCall.service,
62
+ method: toolCall.method,
63
+ result: result,
64
+ };
65
+ }
66
+ catch (error) {
67
+ logger.error(`Query execution failed: ${error.message}`);
68
+ // No vector database fallback available
69
+ throw new Error(`Query failed: ${error.message}. Vector database functionality has been removed.`);
70
+ }
71
+ }
72
+ getConfig() {
73
+ return this.config;
74
+ }
75
+ // Update AI configuration
76
+ updateAIConfig(newAIConfig) {
77
+ try {
78
+ // Validate new AI configuration
79
+ const validatedConfig = ConfigValidator.validate({ ai: newAIConfig });
80
+ this.config.ai = validatedConfig.ai;
81
+ // Update intent engine configuration if it exists
82
+ if (this.intentEngine) {
83
+ this.intentEngine.updateConfig(validatedConfig.ai);
84
+ }
85
+ // Save to configuration file
86
+ if (fs.existsSync(CONFIG_PATH)) {
87
+ const currentConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
88
+ currentConfig.ai = validatedConfig.ai;
89
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(currentConfig, null, 2));
90
+ }
91
+ logger.info(`AI configuration updated to provider: ${validatedConfig.ai.provider}`);
92
+ return { success: true, config: validatedConfig.ai };
93
+ }
94
+ catch (error) {
95
+ logger.error(`Failed to update AI config: ${error.message}`);
96
+ return { success: false, error: error.message };
97
+ }
98
+ }
99
+ }
100
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1,33 @@
1
+ import { EventEmitter } from 'events';
2
+ import { NodeAdapter } from '../runtime/node';
3
+ import { PythonAdapter } from '../runtime/python';
4
+ import { DockerAdapter } from '../runtime/docker';
5
+ export interface ServiceInstance {
6
+ name: string;
7
+ runtime: string;
8
+ path: string;
9
+ image?: string;
10
+ adapter: NodeAdapter | PythonAdapter | DockerAdapter | null;
11
+ status: 'stopped' | 'running' | 'error';
12
+ error?: string;
13
+ tools?: any[];
14
+ }
15
+ export declare class ProcessManager extends EventEmitter {
16
+ private instances;
17
+ constructor();
18
+ loadFromConfig(): void;
19
+ startService(name: string): Promise<void>;
20
+ discoverTools(name: string): Promise<void>;
21
+ callService(name: string, method: string, params?: any): Promise<any>;
22
+ getStatuses(): {
23
+ name: string;
24
+ runtime: string;
25
+ status: "running" | "stopped" | "error";
26
+ error: string;
27
+ toolsCount: number;
28
+ }[];
29
+ getRunningServices(): string[];
30
+ getServiceTools(serviceName: string): any[];
31
+ stopService(name: string): void;
32
+ }
33
+ //# sourceMappingURL=pm.d.ts.map