@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,170 @@
1
+ import { spawn } from 'child_process';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ export class DockerAdapter {
5
+ process = null;
6
+ containerName;
7
+ constructor() {
8
+ this.containerName = '';
9
+ }
10
+ getSpawnArgs(config) {
11
+ // Docker adapter doesn't use traditional spawn, but starts containers
12
+ this.containerName = `mcp-${config.name}-${Date.now()}`;
13
+ const args = ['run', '-d', '--rm', '--name', this.containerName];
14
+ // Add environment variables
15
+ if (config.env) {
16
+ Object.entries(config.env).forEach(([key, value]) => {
17
+ args.push('-e', `${key}=${value}`);
18
+ });
19
+ }
20
+ // Add port mappings
21
+ if (config.ports) {
22
+ config.ports.forEach(port => {
23
+ args.push('-p', `${port}:${port}`);
24
+ });
25
+ }
26
+ // Add volume mappings
27
+ if (config.volumes) {
28
+ config.volumes.forEach(volume => {
29
+ args.push('-v', volume);
30
+ });
31
+ }
32
+ // Add working directory
33
+ if (config.workdir) {
34
+ args.push('-w', config.workdir);
35
+ }
36
+ // Add image and command
37
+ args.push(config.image || config.name);
38
+ if (config.args && config.args.length > 0) {
39
+ args.push(...config.args);
40
+ }
41
+ return {
42
+ command: 'docker',
43
+ args: args,
44
+ };
45
+ }
46
+ async setup(config) {
47
+ console.log(`[Docker] Setting up service: ${config.name}`);
48
+ // Check if Docker is installed
49
+ try {
50
+ const { execSync } = require('child_process');
51
+ execSync('docker --version', { stdio: 'ignore' });
52
+ }
53
+ catch (error) {
54
+ throw new Error('Docker is not installed or not in PATH');
55
+ }
56
+ // Check if image exists, pull if not
57
+ if (config.image) {
58
+ try {
59
+ const { execSync } = require('child_process');
60
+ execSync(`docker image inspect ${config.image}`, { stdio: 'ignore' });
61
+ console.log(`[Docker] Image ${config.image} already exists`);
62
+ }
63
+ catch (error) {
64
+ console.log(`[Docker] Pulling image: ${config.image}`);
65
+ try {
66
+ const { execSync } = require('child_process');
67
+ execSync(`docker pull ${config.image}`, { stdio: 'inherit' });
68
+ }
69
+ catch (pullError) {
70
+ throw new Error(`Failed to pull Docker image ${config.image}: ${pullError.message}`);
71
+ }
72
+ }
73
+ }
74
+ // If Dockerfile exists, build image
75
+ if (config.dockerfile) {
76
+ const dockerfilePath = path.join(config.path || '.', config.dockerfile);
77
+ if (fs.existsSync(dockerfilePath)) {
78
+ console.log(`[Docker] Building image from ${dockerfilePath}`);
79
+ try {
80
+ const { execSync } = require('child_process');
81
+ const buildContext = config.buildContext || path.dirname(dockerfilePath);
82
+ execSync(`docker build -t ${config.name} -f ${dockerfilePath} ${buildContext}`, {
83
+ stdio: 'inherit',
84
+ cwd: config.path || '.',
85
+ });
86
+ }
87
+ catch (buildError) {
88
+ throw new Error(`Failed to build Docker image: ${buildError.message}`);
89
+ }
90
+ }
91
+ }
92
+ console.log(`[Docker] Setup completed for service: ${config.name}`);
93
+ }
94
+ async startContainer(config) {
95
+ const { command, args } = this.getSpawnArgs(config);
96
+ console.log(`[Docker] Starting container: ${this.containerName}`);
97
+ console.log(`[Docker] Command: ${command} ${args.join(' ')}`);
98
+ const process = spawn(command, args, {
99
+ stdio: ['pipe', 'pipe', 'pipe'],
100
+ detached: false,
101
+ });
102
+ process.stdout?.on('data', (data) => {
103
+ console.log(`[Docker:${config.name}] ${data.toString().trim()}`);
104
+ });
105
+ process.stderr?.on('data', (data) => {
106
+ console.error(`[Docker:${config.name}] ERR: ${data.toString().trim()}`);
107
+ });
108
+ process.on('error', (error) => {
109
+ console.error(`[Docker:${config.name}] Failed to start: ${error.message}`);
110
+ });
111
+ process.on('exit', (code, signal) => {
112
+ console.log(`[Docker:${config.name}] Container exited with code ${code}, signal ${signal}`);
113
+ this.process = null;
114
+ });
115
+ this.process = process;
116
+ return process;
117
+ }
118
+ async stopContainer() {
119
+ if (this.process) {
120
+ console.log(`[Docker] Stopping container: ${this.containerName}`);
121
+ try {
122
+ const { execSync } = require('child_process');
123
+ execSync(`docker stop ${this.containerName}`, { stdio: 'ignore' });
124
+ }
125
+ catch (error) {
126
+ // Container may already be stopped
127
+ }
128
+ this.process.kill();
129
+ this.process = null;
130
+ }
131
+ }
132
+ async getContainerStatus() {
133
+ if (!this.containerName) {
134
+ return 'not_created';
135
+ }
136
+ try {
137
+ const { execSync } = require('child_process');
138
+ const output = execSync(`docker ps -a --filter "name=${this.containerName}" --format "{{.Status}}"`, {
139
+ encoding: 'utf-8',
140
+ }).trim();
141
+ if (output.includes('Up')) {
142
+ return 'running';
143
+ }
144
+ else if (output.includes('Exited')) {
145
+ return 'stopped';
146
+ }
147
+ else {
148
+ return 'not_found';
149
+ }
150
+ }
151
+ catch (error) {
152
+ return 'error';
153
+ }
154
+ }
155
+ async getContainerLogs(tail = 50) {
156
+ if (!this.containerName) {
157
+ return 'Container not created';
158
+ }
159
+ try {
160
+ const { execSync } = require('child_process');
161
+ return execSync(`docker logs --tail ${tail} ${this.containerName}`, {
162
+ encoding: 'utf-8',
163
+ });
164
+ }
165
+ catch (error) {
166
+ return `Failed to get logs: ${error.message}`;
167
+ }
168
+ }
169
+ }
170
+ //# sourceMappingURL=docker-adapter.js.map
@@ -0,0 +1,17 @@
1
+ export interface AdapterOptions {
2
+ name: string;
3
+ image: string;
4
+ env?: Record<string, string>;
5
+ }
6
+ export declare class DockerAdapter {
7
+ private options;
8
+ private process;
9
+ private requestId;
10
+ private pendingRequests;
11
+ constructor(options: AdapterOptions);
12
+ start(): Promise<void>;
13
+ call(method: string, params?: any): Promise<any>;
14
+ stop(): void;
15
+ isRunning(): boolean;
16
+ }
17
+ //# sourceMappingURL=docker.d.ts.map
@@ -0,0 +1,71 @@
1
+ import { spawn } from 'child_process';
2
+ export class DockerAdapter {
3
+ options;
4
+ process = null;
5
+ requestId = 0;
6
+ pendingRequests = new Map();
7
+ constructor(options) {
8
+ this.options = options;
9
+ }
10
+ async start() {
11
+ return new Promise((resolve, reject) => {
12
+ console.log(`[RAL] Starting Docker service: ${this.options.name} (${this.options.image})`);
13
+ // Core command: docker run -i (interactive mode) --rm (remove after running)
14
+ // Map container stdio to host process
15
+ const args = ['run', '-i', '--rm', '--name', `mcp-${this.options.name}`];
16
+ // Inject environment variables
17
+ if (this.options.env) {
18
+ Object.entries(this.options.env).forEach(([k, v]) => {
19
+ args.push('-e', `${k}=${v}`);
20
+ });
21
+ }
22
+ args.push(this.options.image);
23
+ this.process = spawn('docker', args, {
24
+ stdio: ['pipe', 'pipe', 'pipe'],
25
+ });
26
+ this.process.stdout?.on('data', (data) => {
27
+ const raw = data.toString().trim();
28
+ try {
29
+ const json = JSON.parse(raw);
30
+ if (json.id !== undefined && this.pendingRequests.has(json.id)) {
31
+ const resolver = this.pendingRequests.get(json.id);
32
+ resolver?.(json);
33
+ this.pendingRequests.delete(json.id);
34
+ }
35
+ }
36
+ catch (e) {
37
+ console.log(`[Docker:${this.options.name}] ${raw}`);
38
+ }
39
+ });
40
+ this.process.stderr?.on('data', (data) => {
41
+ console.error(`[Docker:${this.options.name}] ERR: ${data.toString()}`);
42
+ });
43
+ // Listen for successful startup
44
+ this.process.on('spawn', () => resolve());
45
+ this.process.on('error', (err) => reject(new Error(`Docker start failed: ${err.message}`)));
46
+ });
47
+ }
48
+ async call(method, params = {}) {
49
+ if (!this.process) {
50
+ throw new Error(`Docker service ${this.options.name} is not running.`);
51
+ }
52
+ const id = ++this.requestId;
53
+ const request = { jsonrpc: '2.0', id, method, params };
54
+ return new Promise((resolve) => {
55
+ this.pendingRequests.set(id, resolve);
56
+ this.process?.stdin?.write(JSON.stringify(request) + '\n');
57
+ });
58
+ }
59
+ stop() {
60
+ if (this.process) {
61
+ // Force stop container
62
+ spawn('docker', ['stop', `mcp-${this.options.name}`]);
63
+ this.process.kill();
64
+ this.process = null;
65
+ }
66
+ }
67
+ isRunning() {
68
+ return this.process !== null;
69
+ }
70
+ }
71
+ //# sourceMappingURL=docker.js.map
@@ -0,0 +1,56 @@
1
+ import { RuntimeType } from '../core/types';
2
+ export interface ExecutableAnalysis {
3
+ type: RuntimeType;
4
+ confidence: number;
5
+ details: {
6
+ method: 'fileCommand' | 'magicNumber' | 'shebang' | 'permissions' | 'extension';
7
+ result: string;
8
+ rawOutput?: string;
9
+ };
10
+ }
11
+ export declare class ExecutableAnalyzer {
12
+ /**
13
+ * Analyze executable file type
14
+ */
15
+ static analyze(filePath: string): ExecutableAnalysis | null;
16
+ /**
17
+ * Use file command to detect file type (highest priority)
18
+ */
19
+ private static analyzeWithFileCommand;
20
+ /**
21
+ * Detect file type via magic numbers
22
+ */
23
+ private static analyzeWithMagicNumbers;
24
+ /**
25
+ * Analyze Shebang line
26
+ */
27
+ private static analyzeShebang;
28
+ /**
29
+ * Detect by file permissions
30
+ */
31
+ private static analyzeByPermissions;
32
+ /**
33
+ * Detect by file extension (last resort)
34
+ */
35
+ private static analyzeByExtension;
36
+ /**
37
+ * Check if file is executable
38
+ */
39
+ private static isExecutable;
40
+ /**
41
+ * Find executable files in directory
42
+ */
43
+ static findExecutables(dirPath: string): string[];
44
+ /**
45
+ * Get the most likely executable file in directory
46
+ */
47
+ static getPrimaryExecutable(dirPath: string): string | null;
48
+ /**
49
+ * Batch analyze executable files in directory
50
+ */
51
+ static analyzeDirectory(dirPath: string): Array<{
52
+ file: string;
53
+ analysis: ExecutableAnalysis;
54
+ }>;
55
+ }
56
+ //# sourceMappingURL=executable-analyzer.d.ts.map