@enactprotocol/shared 1.2.13 → 2.0.1
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/README.md +44 -0
- package/dist/config.d.ts +164 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +386 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +15 -5
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -8
- package/dist/constants.js.map +1 -0
- package/dist/execution/command.d.ts +102 -0
- package/dist/execution/command.d.ts.map +1 -0
- package/dist/execution/command.js +262 -0
- package/dist/execution/command.js.map +1 -0
- package/dist/execution/index.d.ts +12 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +17 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/runtime.d.ts +82 -0
- package/dist/execution/runtime.d.ts.map +1 -0
- package/dist/execution/runtime.js +273 -0
- package/dist/execution/runtime.js.map +1 -0
- package/dist/execution/types.d.ts +306 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +14 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/validation.d.ts +43 -0
- package/dist/execution/validation.d.ts.map +1 -0
- package/dist/execution/validation.js +430 -0
- package/dist/execution/validation.js.map +1 -0
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -25
- package/dist/index.js.map +1 -0
- package/dist/manifest/index.d.ts +7 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +10 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/loader.d.ts +76 -0
- package/dist/manifest/loader.d.ts.map +1 -0
- package/dist/manifest/loader.js +146 -0
- package/dist/manifest/loader.js.map +1 -0
- package/dist/manifest/parser.d.ts +64 -0
- package/dist/manifest/parser.d.ts.map +1 -0
- package/dist/manifest/parser.js +135 -0
- package/dist/manifest/parser.js.map +1 -0
- package/dist/manifest/validator.d.ts +95 -0
- package/dist/manifest/validator.d.ts.map +1 -0
- package/dist/manifest/validator.js +258 -0
- package/dist/manifest/validator.js.map +1 -0
- package/dist/paths.d.ts +57 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +93 -0
- package/dist/paths.js.map +1 -0
- package/dist/registry.d.ts +73 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +147 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolver.d.ts +89 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +282 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/manifest.d.ts +201 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/manifest.js +13 -0
- package/dist/types/manifest.js.map +1 -0
- package/dist/types.d.ts +5 -132
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -0
- package/dist/utils/fs.d.ts +105 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +233 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +102 -25
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +214 -57
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/version.d.ts +60 -2
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +255 -31
- package/dist/utils/version.js.map +1 -0
- package/package.json +16 -58
- package/src/config.ts +510 -0
- package/src/constants.ts +36 -0
- package/src/execution/command.ts +314 -0
- package/src/execution/index.ts +73 -0
- package/src/execution/runtime.ts +308 -0
- package/src/execution/types.ts +379 -0
- package/src/execution/validation.ts +508 -0
- package/src/index.ts +238 -30
- package/src/manifest/index.ts +36 -0
- package/src/manifest/loader.ts +187 -0
- package/src/manifest/parser.ts +173 -0
- package/src/manifest/validator.ts +309 -0
- package/src/paths.ts +108 -0
- package/src/registry.ts +219 -0
- package/src/resolver.ts +345 -0
- package/src/types/index.ts +30 -0
- package/src/types/manifest.ts +255 -0
- package/src/types.ts +5 -188
- package/src/utils/fs.ts +281 -0
- package/src/utils/logger.ts +270 -59
- package/src/utils/version.ts +304 -36
- package/tests/config.test.ts +515 -0
- package/tests/execution/command.test.ts +317 -0
- package/tests/execution/validation.test.ts +384 -0
- package/tests/fixtures/invalid-tool.yaml +4 -0
- package/tests/fixtures/valid-tool.md +62 -0
- package/tests/fixtures/valid-tool.yaml +40 -0
- package/tests/index.test.ts +8 -0
- package/tests/manifest/loader.test.ts +291 -0
- package/tests/manifest/parser.test.ts +345 -0
- package/tests/manifest/validator.test.ts +394 -0
- package/tests/manifest-types.test.ts +358 -0
- package/tests/paths.test.ts +153 -0
- package/tests/registry.test.ts +231 -0
- package/tests/resolver.test.ts +272 -0
- package/tests/utils/fs.test.ts +388 -0
- package/tests/utils/logger.test.ts +480 -0
- package/tests/utils/version.test.ts +390 -0
- package/tsconfig.json +12 -0
- package/dist/LocalToolResolver.d.ts +0 -84
- package/dist/LocalToolResolver.js +0 -353
- package/dist/api/enact-api.d.ts +0 -130
- package/dist/api/enact-api.js +0 -428
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.js +0 -2
- package/dist/api/types.d.ts +0 -103
- package/dist/api/types.js +0 -1
- package/dist/core/DaggerExecutionProvider.d.ts +0 -169
- package/dist/core/DaggerExecutionProvider.js +0 -1029
- package/dist/core/DirectExecutionProvider.d.ts +0 -23
- package/dist/core/DirectExecutionProvider.js +0 -406
- package/dist/core/EnactCore.d.ts +0 -162
- package/dist/core/EnactCore.js +0 -597
- package/dist/core/NativeExecutionProvider.d.ts +0 -9
- package/dist/core/NativeExecutionProvider.js +0 -16
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -3
- package/dist/exec/index.d.ts +0 -3
- package/dist/exec/index.js +0 -3
- package/dist/exec/logger.d.ts +0 -11
- package/dist/exec/logger.js +0 -57
- package/dist/exec/validate.d.ts +0 -5
- package/dist/exec/validate.js +0 -167
- package/dist/lib/enact-direct.d.ts +0 -150
- package/dist/lib/enact-direct.js +0 -159
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.js +0 -1
- package/dist/security/index.d.ts +0 -3
- package/dist/security/index.js +0 -3
- package/dist/security/security.d.ts +0 -23
- package/dist/security/security.js +0 -137
- package/dist/security/sign.d.ts +0 -103
- package/dist/security/sign.js +0 -666
- package/dist/security/verification-enforcer.d.ts +0 -53
- package/dist/security/verification-enforcer.js +0 -204
- package/dist/services/McpCoreService.d.ts +0 -98
- package/dist/services/McpCoreService.js +0 -124
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/utils/config.d.ts +0 -111
- package/dist/utils/config.js +0 -342
- package/dist/utils/env-loader.d.ts +0 -54
- package/dist/utils/env-loader.js +0 -270
- package/dist/utils/help.d.ts +0 -36
- package/dist/utils/help.js +0 -248
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/index.js +0 -7
- package/dist/utils/silent-monitor.d.ts +0 -67
- package/dist/utils/silent-monitor.js +0 -242
- package/dist/utils/timeout.d.ts +0 -5
- package/dist/utils/timeout.js +0 -23
- package/dist/web/env-manager-server.d.ts +0 -29
- package/dist/web/env-manager-server.js +0 -367
- package/dist/web/index.d.ts +0 -1
- package/dist/web/index.js +0 -1
- package/src/LocalToolResolver.ts +0 -424
- package/src/api/enact-api.ts +0 -604
- package/src/api/index.ts +0 -2
- package/src/api/types.ts +0 -114
- package/src/core/DaggerExecutionProvider.ts +0 -1357
- package/src/core/DirectExecutionProvider.ts +0 -484
- package/src/core/EnactCore.ts +0 -847
- package/src/core/index.ts +0 -3
- package/src/exec/index.ts +0 -3
- package/src/exec/logger.ts +0 -63
- package/src/exec/validate.ts +0 -238
- package/src/lib/enact-direct.ts +0 -254
- package/src/lib/index.ts +0 -1
- package/src/services/McpCoreService.ts +0 -201
- package/src/services/index.ts +0 -1
- package/src/utils/config.ts +0 -438
- package/src/utils/env-loader.ts +0 -370
- package/src/utils/help.ts +0 -257
- package/src/utils/index.ts +0 -7
- package/src/utils/silent-monitor.ts +0 -328
- package/src/utils/timeout.ts +0 -26
- package/src/web/env-manager-server.ts +0 -465
- package/src/web/index.ts +0 -1
- package/src/web/static/app.js +0 -663
- package/src/web/static/index.html +0 -117
- package/src/web/static/style.css +0 -291
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ExecutionProvider, type EnactTool, type ExecutionEnvironment, type ExecutionResult } from "../types.js";
|
|
2
|
-
export declare class DirectExecutionProvider extends ExecutionProvider {
|
|
3
|
-
resolveEnvironmentVariables(envConfig: Record<string, any>, namespace?: string): Promise<Record<string, any>>;
|
|
4
|
-
executeCommand(command: string, inputs: Record<string, any>, environment: ExecutionEnvironment, timeout?: string, options?: {
|
|
5
|
-
verbose?: boolean;
|
|
6
|
-
showSpinner?: boolean;
|
|
7
|
-
streamOutput?: boolean;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
stdout: string;
|
|
10
|
-
stderr: string;
|
|
11
|
-
exitCode: number;
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* Execute command with exec.ts compatible interface
|
|
15
|
-
* This method provides the same interface as the exec.ts executeCommand function
|
|
16
|
-
*/
|
|
17
|
-
executeCommandExecStyle(command: string, timeout: string, verbose?: boolean, envVars?: Record<string, string>): Promise<void>;
|
|
18
|
-
setup(tool: EnactTool): Promise<boolean>;
|
|
19
|
-
execute(tool: EnactTool, inputs: Record<string, any>, environment: ExecutionEnvironment): Promise<ExecutionResult>;
|
|
20
|
-
cleanup(): Promise<boolean>;
|
|
21
|
-
private generateExecutionId;
|
|
22
|
-
private parseCommand;
|
|
23
|
-
}
|
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
// src/core/DirectExecutionProvider.ts - Direct execution provider that doesn't use external CLI
|
|
2
|
-
import { spawn } from "child_process";
|
|
3
|
-
import { ExecutionProvider, } from "../types.js";
|
|
4
|
-
import logger from "../exec/logger.js";
|
|
5
|
-
import { parseTimeout } from "../utils/timeout.js";
|
|
6
|
-
export class DirectExecutionProvider extends ExecutionProvider {
|
|
7
|
-
async resolveEnvironmentVariables(envConfig, namespace) {
|
|
8
|
-
const resolved = {};
|
|
9
|
-
for (const [key, config] of Object.entries(envConfig)) {
|
|
10
|
-
if (typeof config === "object" && config.source) {
|
|
11
|
-
// Handle different sources
|
|
12
|
-
switch (config.source) {
|
|
13
|
-
case "env":
|
|
14
|
-
resolved[key] = process.env[key] || config.default;
|
|
15
|
-
break;
|
|
16
|
-
case "user":
|
|
17
|
-
// Could get from user config file
|
|
18
|
-
resolved[key] = config.default;
|
|
19
|
-
break;
|
|
20
|
-
default:
|
|
21
|
-
resolved[key] = config.default;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// Direct value
|
|
26
|
-
resolved[key] = config;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return resolved;
|
|
30
|
-
}
|
|
31
|
-
async executeCommand(command, inputs, environment, timeout, options) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
let stdout = "";
|
|
34
|
-
let stderr = "";
|
|
35
|
-
// UI Setup
|
|
36
|
-
const verbose = options?.verbose ?? false;
|
|
37
|
-
const showSpinner = options?.showSpinner ?? false;
|
|
38
|
-
const streamOutput = options?.streamOutput ?? true;
|
|
39
|
-
let spinner = null;
|
|
40
|
-
if (showSpinner) {
|
|
41
|
-
// Dynamic import to avoid dependency issues when not needed
|
|
42
|
-
try {
|
|
43
|
-
const p = require("@clack/prompts");
|
|
44
|
-
spinner = p.spinner();
|
|
45
|
-
spinner.start("Executing tool...");
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
// Fallback if @clack/prompts not available
|
|
49
|
-
console.log("Executing tool...");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (verbose) {
|
|
53
|
-
try {
|
|
54
|
-
const pc = require("picocolors");
|
|
55
|
-
console.error(pc.cyan("\n🚀 Executing command:"));
|
|
56
|
-
console.error(pc.white(command));
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
console.error("\n🚀 Executing command:");
|
|
60
|
-
console.error(command);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Substitute template variables in command with input values
|
|
64
|
-
let substitutedCommand = command;
|
|
65
|
-
for (const [key, value] of Object.entries(inputs)) {
|
|
66
|
-
const templateVar = `\${${key}}`;
|
|
67
|
-
// Handle different value types
|
|
68
|
-
let substitutionValue;
|
|
69
|
-
if (typeof value === "string") {
|
|
70
|
-
substitutionValue = value;
|
|
71
|
-
}
|
|
72
|
-
else if (typeof value === "object") {
|
|
73
|
-
substitutionValue = JSON.stringify(value);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
substitutionValue = String(value);
|
|
77
|
-
}
|
|
78
|
-
substitutedCommand = substitutedCommand.replace(new RegExp(`\\$\\{${key}\\}`, "g"), substitutionValue);
|
|
79
|
-
}
|
|
80
|
-
// Prepare environment
|
|
81
|
-
const env = {
|
|
82
|
-
...process.env,
|
|
83
|
-
...environment.vars,
|
|
84
|
-
};
|
|
85
|
-
// Parse command and arguments properly handling quoted strings
|
|
86
|
-
const commandParts = this.parseCommand(substitutedCommand);
|
|
87
|
-
const cmd = commandParts[0];
|
|
88
|
-
const args = commandParts.slice(1);
|
|
89
|
-
logger.info(`Executing command: ${command}`);
|
|
90
|
-
try {
|
|
91
|
-
const proc = spawn(cmd, args, {
|
|
92
|
-
env,
|
|
93
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
94
|
-
// Create a new process group for better cleanup of child processes
|
|
95
|
-
detached: process.platform !== "win32",
|
|
96
|
-
});
|
|
97
|
-
// Cleanup function to ensure process and children are properly terminated
|
|
98
|
-
let isCleanedUp = false;
|
|
99
|
-
let cleanupTimer = null;
|
|
100
|
-
const cleanup = () => {
|
|
101
|
-
if (isCleanedUp)
|
|
102
|
-
return;
|
|
103
|
-
isCleanedUp = true;
|
|
104
|
-
// Clear any pending cleanup timer
|
|
105
|
-
if (cleanupTimer) {
|
|
106
|
-
clearTimeout(cleanupTimer);
|
|
107
|
-
cleanupTimer = null;
|
|
108
|
-
}
|
|
109
|
-
if (proc && !proc.killed) {
|
|
110
|
-
try {
|
|
111
|
-
logger.debug(`Cleaning up process PID: ${proc.pid}`);
|
|
112
|
-
// For Dagger and other tools that may spawn child processes
|
|
113
|
-
if (process.platform === "win32") {
|
|
114
|
-
proc.kill("SIGKILL");
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// Try graceful termination first
|
|
118
|
-
proc.kill("SIGTERM");
|
|
119
|
-
// Set a cleanup timer for force kill if needed
|
|
120
|
-
cleanupTimer = setTimeout(() => {
|
|
121
|
-
if (!proc.killed && !isCleanedUp) {
|
|
122
|
-
logger.debug(`Force killing process PID: ${proc.pid}`);
|
|
123
|
-
try {
|
|
124
|
-
proc.kill("SIGKILL");
|
|
125
|
-
}
|
|
126
|
-
catch (killError) {
|
|
127
|
-
// Process might already be dead, ignore
|
|
128
|
-
logger.debug(`Force kill error (likely harmless): ${killError}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
cleanupTimer = null;
|
|
132
|
-
}, 1000); // Reduced from 2000ms to 1000ms
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch (killError) {
|
|
136
|
-
// Process might already be dead, ignore
|
|
137
|
-
logger.debug(`Process cleanup error (likely harmless): ${killError}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
// Collect stdout and stream it in real-time
|
|
142
|
-
proc.stdout.on("data", (data) => {
|
|
143
|
-
const chunk = data.toString();
|
|
144
|
-
stdout += chunk;
|
|
145
|
-
// Stream stdout to console in real-time if enabled
|
|
146
|
-
if (streamOutput) {
|
|
147
|
-
process.stdout.write(chunk);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
// Collect stderr and stream it in real-time
|
|
151
|
-
proc.stderr.on("data", (data) => {
|
|
152
|
-
const chunk = data.toString();
|
|
153
|
-
stderr += chunk;
|
|
154
|
-
// Stream stderr to console in real-time if enabled
|
|
155
|
-
if (streamOutput) {
|
|
156
|
-
process.stderr.write(chunk);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
// Handle process completion with more robust cleanup
|
|
160
|
-
proc.on("close", (code) => {
|
|
161
|
-
logger.debug(`Process closed with code: ${code}, PID: ${proc.pid}`);
|
|
162
|
-
// Force cleanup any remaining resources
|
|
163
|
-
cleanup();
|
|
164
|
-
// Handle spinner cleanup and success/error messaging
|
|
165
|
-
if (spinner) {
|
|
166
|
-
spinner.stop("Execution completed");
|
|
167
|
-
}
|
|
168
|
-
if (code === 0) {
|
|
169
|
-
if (showSpinner || verbose) {
|
|
170
|
-
try {
|
|
171
|
-
const pc = require("picocolors");
|
|
172
|
-
console.error(pc.green("\n✅ Tool executed successfully"));
|
|
173
|
-
if (stdout.trim() && !streamOutput) {
|
|
174
|
-
console.error(pc.cyan("\n📤 Output:"));
|
|
175
|
-
console.error(stdout.trim());
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
console.error("\n✅ Tool executed successfully");
|
|
180
|
-
if (stdout.trim() && !streamOutput) {
|
|
181
|
-
console.error("\n📤 Output:");
|
|
182
|
-
console.error(stdout.trim());
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
if (showSpinner || verbose) {
|
|
189
|
-
try {
|
|
190
|
-
const pc = require("picocolors");
|
|
191
|
-
console.error(pc.red(`\n❌ Tool execution failed (exit code: ${code})`));
|
|
192
|
-
if (stderr.trim() && !streamOutput) {
|
|
193
|
-
console.error(pc.red("\n📤 Error output:"));
|
|
194
|
-
console.error(stderr.trim());
|
|
195
|
-
}
|
|
196
|
-
if (stdout.trim() && !streamOutput) {
|
|
197
|
-
console.error(pc.yellow("\n📤 Standard output:"));
|
|
198
|
-
console.error(stdout.trim());
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
catch (e) {
|
|
202
|
-
console.error(`\n❌ Tool execution failed (exit code: ${code})`);
|
|
203
|
-
if (stderr.trim() && !streamOutput) {
|
|
204
|
-
console.error("\n📤 Error output:");
|
|
205
|
-
console.error(stderr.trim());
|
|
206
|
-
}
|
|
207
|
-
if (stdout.trim() && !streamOutput) {
|
|
208
|
-
console.error("\n📤 Standard output:");
|
|
209
|
-
console.error(stdout.trim());
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
resolve({
|
|
215
|
-
stdout: stdout.trim(),
|
|
216
|
-
stderr: stderr.trim(),
|
|
217
|
-
exitCode: code || 0,
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
// Handle process errors
|
|
221
|
-
proc.on("error", (error) => {
|
|
222
|
-
cleanup();
|
|
223
|
-
if (spinner) {
|
|
224
|
-
spinner.stop("Execution failed");
|
|
225
|
-
}
|
|
226
|
-
if (showSpinner || verbose) {
|
|
227
|
-
try {
|
|
228
|
-
const pc = require("picocolors");
|
|
229
|
-
console.error(pc.red(`\n❌ Failed to execute command: ${error.message}`));
|
|
230
|
-
}
|
|
231
|
-
catch (e) {
|
|
232
|
-
console.error(`\n❌ Failed to execute command: ${error.message}`);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
reject(new Error(`Command execution error: ${error.message}`));
|
|
236
|
-
});
|
|
237
|
-
// Set timeout if specified
|
|
238
|
-
if (timeout) {
|
|
239
|
-
const timeoutMs = parseTimeout(timeout);
|
|
240
|
-
setTimeout(() => {
|
|
241
|
-
cleanup();
|
|
242
|
-
if (spinner) {
|
|
243
|
-
spinner.stop("Execution failed");
|
|
244
|
-
}
|
|
245
|
-
reject(new Error(`Command timed out after ${timeout}`));
|
|
246
|
-
}, timeoutMs);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
catch (spawnError) {
|
|
250
|
-
reject(new Error(`Failed to spawn command: ${spawnError}`));
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Execute command with exec.ts compatible interface
|
|
256
|
-
* This method provides the same interface as the exec.ts executeCommand function
|
|
257
|
-
*/
|
|
258
|
-
async executeCommandExecStyle(command, timeout, verbose = false, envVars = {}) {
|
|
259
|
-
const environment = {
|
|
260
|
-
vars: envVars,
|
|
261
|
-
resources: { timeout },
|
|
262
|
-
};
|
|
263
|
-
const result = await this.executeCommand(command, {}, // No template substitution needed for this interface
|
|
264
|
-
environment, timeout, {
|
|
265
|
-
verbose,
|
|
266
|
-
showSpinner: true,
|
|
267
|
-
streamOutput: false, // Don't stream since exec.ts shows output at the end
|
|
268
|
-
});
|
|
269
|
-
if (result.exitCode !== 0) {
|
|
270
|
-
throw new Error(`Command failed with exit code ${result.exitCode}`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async setup(tool) {
|
|
274
|
-
// No special setup needed for direct execution
|
|
275
|
-
logger.debug(`Setting up direct execution for tool: ${tool.name}`);
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
async execute(tool, inputs, environment) {
|
|
279
|
-
const executionId = this.generateExecutionId();
|
|
280
|
-
const timeout = tool.timeout || environment.resources?.timeout;
|
|
281
|
-
// Substitute template variables in command with input values
|
|
282
|
-
let substitutedCommand = tool.command;
|
|
283
|
-
for (const [key, value] of Object.entries(inputs)) {
|
|
284
|
-
const templateVar = `\${${key}}`;
|
|
285
|
-
// Handle different value types
|
|
286
|
-
let substitutionValue;
|
|
287
|
-
if (typeof value === "string") {
|
|
288
|
-
substitutionValue = value;
|
|
289
|
-
}
|
|
290
|
-
else if (typeof value === "object") {
|
|
291
|
-
substitutionValue = JSON.stringify(value);
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
substitutionValue = String(value);
|
|
295
|
-
}
|
|
296
|
-
substitutedCommand = substitutedCommand.replace(new RegExp(`\\$\\{${key}\\}`, "g"), substitutionValue);
|
|
297
|
-
}
|
|
298
|
-
try {
|
|
299
|
-
// Execute the command
|
|
300
|
-
const result = await this.executeCommand(substitutedCommand, inputs, environment, timeout);
|
|
301
|
-
// Parse output
|
|
302
|
-
let parsedOutput;
|
|
303
|
-
try {
|
|
304
|
-
// Try to parse as JSON first
|
|
305
|
-
parsedOutput = JSON.parse(result.stdout);
|
|
306
|
-
}
|
|
307
|
-
catch {
|
|
308
|
-
// If not JSON, return structured output
|
|
309
|
-
parsedOutput = {
|
|
310
|
-
stdout: result.stdout,
|
|
311
|
-
stderr: result.stderr,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
success: result.exitCode === 0,
|
|
316
|
-
output: parsedOutput,
|
|
317
|
-
...(result.exitCode !== 0 && {
|
|
318
|
-
error: {
|
|
319
|
-
message: `Command failed with exit code ${result.exitCode}`,
|
|
320
|
-
code: "COMMAND_FAILED",
|
|
321
|
-
details: {
|
|
322
|
-
stdout: result.stdout,
|
|
323
|
-
stderr: result.stderr,
|
|
324
|
-
command: substitutedCommand, // Show the substituted command
|
|
325
|
-
exitCode: result.exitCode,
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
}),
|
|
329
|
-
metadata: {
|
|
330
|
-
executionId,
|
|
331
|
-
toolName: tool.name,
|
|
332
|
-
version: tool.version,
|
|
333
|
-
executedAt: new Date().toISOString(),
|
|
334
|
-
environment: "direct",
|
|
335
|
-
timeout,
|
|
336
|
-
command: substitutedCommand, // Show the substituted command in metadata
|
|
337
|
-
},
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
catch (error) {
|
|
341
|
-
return {
|
|
342
|
-
success: false,
|
|
343
|
-
error: {
|
|
344
|
-
message: error.message,
|
|
345
|
-
code: "EXECUTION_ERROR",
|
|
346
|
-
details: error,
|
|
347
|
-
},
|
|
348
|
-
metadata: {
|
|
349
|
-
executionId,
|
|
350
|
-
toolName: tool.name,
|
|
351
|
-
version: tool.version,
|
|
352
|
-
executedAt: new Date().toISOString(),
|
|
353
|
-
environment: "direct",
|
|
354
|
-
},
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
async cleanup() {
|
|
359
|
-
// No cleanup needed for direct execution
|
|
360
|
-
return true;
|
|
361
|
-
}
|
|
362
|
-
generateExecutionId() {
|
|
363
|
-
return `exec_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
364
|
-
}
|
|
365
|
-
parseCommand(command) {
|
|
366
|
-
const parts = [];
|
|
367
|
-
let current = "";
|
|
368
|
-
let inQuotes = false;
|
|
369
|
-
let quoteChar = "";
|
|
370
|
-
let i = 0;
|
|
371
|
-
while (i < command.length) {
|
|
372
|
-
const char = command[i];
|
|
373
|
-
if (!inQuotes && (char === '"' || char === "'")) {
|
|
374
|
-
// Start of quoted section
|
|
375
|
-
inQuotes = true;
|
|
376
|
-
quoteChar = char;
|
|
377
|
-
}
|
|
378
|
-
else if (inQuotes && char === quoteChar) {
|
|
379
|
-
// End of quoted section
|
|
380
|
-
inQuotes = false;
|
|
381
|
-
quoteChar = "";
|
|
382
|
-
}
|
|
383
|
-
else if (!inQuotes && char === " ") {
|
|
384
|
-
// Space outside quotes - end current part
|
|
385
|
-
if (current.length > 0) {
|
|
386
|
-
parts.push(current);
|
|
387
|
-
current = "";
|
|
388
|
-
}
|
|
389
|
-
// Skip whitespace
|
|
390
|
-
while (i + 1 < command.length && command[i + 1] === " ") {
|
|
391
|
-
i++;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
// Regular character or space inside quotes
|
|
396
|
-
current += char;
|
|
397
|
-
}
|
|
398
|
-
i++;
|
|
399
|
-
}
|
|
400
|
-
// Add the last part if it exists
|
|
401
|
-
if (current.length > 0) {
|
|
402
|
-
parts.push(current);
|
|
403
|
-
}
|
|
404
|
-
return parts;
|
|
405
|
-
}
|
|
406
|
-
}
|
package/dist/core/EnactCore.d.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import type { EnactTool, ExecutionResult } from "../types.js";
|
|
2
|
-
import { EnactToolDefinition } from "../api/types.js";
|
|
3
|
-
export interface EnactCoreOptions {
|
|
4
|
-
apiUrl?: string;
|
|
5
|
-
supabaseUrl?: string;
|
|
6
|
-
executionProvider?: "direct" | "docker" | "dagger" | "cloud";
|
|
7
|
-
authToken?: string;
|
|
8
|
-
verbose?: boolean;
|
|
9
|
-
defaultTimeout?: string;
|
|
10
|
-
daggerOptions?: {
|
|
11
|
-
baseImage?: string;
|
|
12
|
-
enableNetwork?: boolean;
|
|
13
|
-
enableHostFS?: boolean;
|
|
14
|
-
maxMemory?: string;
|
|
15
|
-
maxCPU?: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface ToolSearchOptions {
|
|
19
|
-
query: string;
|
|
20
|
-
limit?: number;
|
|
21
|
-
tags?: string[];
|
|
22
|
-
author?: string;
|
|
23
|
-
format?: "json" | "table" | "list";
|
|
24
|
-
}
|
|
25
|
-
export interface ToolExecuteOptions {
|
|
26
|
-
timeout?: string;
|
|
27
|
-
force?: boolean;
|
|
28
|
-
dryRun?: boolean;
|
|
29
|
-
verbose?: boolean;
|
|
30
|
-
isLocalFile?: boolean;
|
|
31
|
-
dangerouslySkipVerification?: boolean;
|
|
32
|
-
mount?: string;
|
|
33
|
-
}
|
|
34
|
-
export declare class EnactCore {
|
|
35
|
-
private apiClient;
|
|
36
|
-
private executionProvider;
|
|
37
|
-
private options;
|
|
38
|
-
constructor(options?: EnactCoreOptions);
|
|
39
|
-
/**
|
|
40
|
-
* Create EnactCore with config-based URLs
|
|
41
|
-
*/
|
|
42
|
-
static create(options?: EnactCoreOptions): Promise<EnactCore>;
|
|
43
|
-
/**
|
|
44
|
-
* Set authentication token for API operations
|
|
45
|
-
*/
|
|
46
|
-
setAuthToken(token: string): void;
|
|
47
|
-
/**
|
|
48
|
-
* Static method to search for tools (no execution provider needed)
|
|
49
|
-
*/
|
|
50
|
-
static searchTools(options: ToolSearchOptions, coreOptions?: Pick<EnactCoreOptions, 'apiUrl' | 'supabaseUrl'>): Promise<EnactTool[]>;
|
|
51
|
-
/**
|
|
52
|
-
* Instance method wrapper for backward compatibility
|
|
53
|
-
*/
|
|
54
|
-
searchTools(options: ToolSearchOptions): Promise<EnactTool[]>;
|
|
55
|
-
/**
|
|
56
|
-
* Static fallback search method that gets all tools and filters locally
|
|
57
|
-
*/
|
|
58
|
-
private static searchToolsFallback;
|
|
59
|
-
/**
|
|
60
|
-
* Static method to get a specific tool by name
|
|
61
|
-
*/
|
|
62
|
-
static getToolByName(name: string, version?: string, coreOptions?: Pick<EnactCoreOptions, 'apiUrl' | 'supabaseUrl'>): Promise<EnactTool | null>;
|
|
63
|
-
/**
|
|
64
|
-
* Instance method wrapper for backward compatibility
|
|
65
|
-
*/
|
|
66
|
-
getToolByName(name: string, version?: string): Promise<EnactTool | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Execute a tool by name
|
|
69
|
-
*/
|
|
70
|
-
executeToolByName(name: string, inputs?: Record<string, any>, options?: ToolExecuteOptions): Promise<ExecutionResult>;
|
|
71
|
-
static checkToolVerificationStatus(tool: EnactToolDefinition): Promise<boolean>;
|
|
72
|
-
private verifyTool;
|
|
73
|
-
/**
|
|
74
|
-
* Execute a tool directly
|
|
75
|
-
*/
|
|
76
|
-
executeTool(tool: EnactTool, inputs?: Record<string, any>, options?: ToolExecuteOptions): Promise<ExecutionResult>;
|
|
77
|
-
/**
|
|
78
|
-
* Execute a tool from raw YAML definition
|
|
79
|
-
*/
|
|
80
|
-
executeRawTool(toolYaml: string, inputs?: Record<string, any>, options?: ToolExecuteOptions): Promise<ExecutionResult>;
|
|
81
|
-
/**
|
|
82
|
-
* Static method to check if a tool exists
|
|
83
|
-
*/
|
|
84
|
-
static toolExists(name: string, coreOptions?: Pick<EnactCoreOptions, 'apiUrl' | 'supabaseUrl'>): Promise<boolean>;
|
|
85
|
-
/**
|
|
86
|
-
* Instance method wrapper for backward compatibility
|
|
87
|
-
*/
|
|
88
|
-
toolExists(name: string): Promise<boolean>;
|
|
89
|
-
/**
|
|
90
|
-
* Get tools by tags
|
|
91
|
-
*/
|
|
92
|
-
getToolsByTags(tags: string[], limit?: number): Promise<EnactTool[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Get tools by author
|
|
95
|
-
*/
|
|
96
|
-
getToolsByAuthor(author: string, limit?: number): Promise<EnactTool[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Static method to get all tools with filters
|
|
99
|
-
*/
|
|
100
|
-
static getTools(options?: {
|
|
101
|
-
limit?: number;
|
|
102
|
-
offset?: number;
|
|
103
|
-
tags?: string[];
|
|
104
|
-
author?: string;
|
|
105
|
-
}, coreOptions?: Pick<EnactCoreOptions, 'apiUrl' | 'supabaseUrl'>): Promise<EnactTool[]>;
|
|
106
|
-
/**
|
|
107
|
-
* Instance method wrapper for backward compatibility
|
|
108
|
-
*/
|
|
109
|
-
getTools(options?: {
|
|
110
|
-
limit?: number;
|
|
111
|
-
offset?: number;
|
|
112
|
-
tags?: string[];
|
|
113
|
-
author?: string;
|
|
114
|
-
}): Promise<EnactTool[]>;
|
|
115
|
-
/**
|
|
116
|
-
* Get authentication status (placeholder - would need actual auth implementation)
|
|
117
|
-
*/
|
|
118
|
-
getAuthStatus(): Promise<{
|
|
119
|
-
authenticated: boolean;
|
|
120
|
-
user?: string;
|
|
121
|
-
server?: string;
|
|
122
|
-
}>;
|
|
123
|
-
/**
|
|
124
|
-
* Static method to publish a tool
|
|
125
|
-
*/
|
|
126
|
-
static publishTool(tool: EnactTool, authToken: string, coreOptions?: Pick<EnactCoreOptions, 'apiUrl' | 'supabaseUrl'>): Promise<{
|
|
127
|
-
success: boolean;
|
|
128
|
-
message: string;
|
|
129
|
-
}>;
|
|
130
|
-
/**
|
|
131
|
-
* Instance method wrapper for backward compatibility
|
|
132
|
-
*/
|
|
133
|
-
publishTool(tool: EnactTool): Promise<{
|
|
134
|
-
success: boolean;
|
|
135
|
-
message: string;
|
|
136
|
-
}>;
|
|
137
|
-
/**
|
|
138
|
-
* Get tool information (alias for getToolByName for consistency)
|
|
139
|
-
*/
|
|
140
|
-
getToolInfo(name: string, version?: string): Promise<EnactTool | null>;
|
|
141
|
-
/**
|
|
142
|
-
* Get core library status
|
|
143
|
-
*/
|
|
144
|
-
getStatus(): Promise<{
|
|
145
|
-
executionProvider: string;
|
|
146
|
-
apiUrl: string;
|
|
147
|
-
defaultTimeout: string;
|
|
148
|
-
authenticated: boolean;
|
|
149
|
-
}>;
|
|
150
|
-
/**
|
|
151
|
-
* Create the appropriate execution provider based on options
|
|
152
|
-
*/
|
|
153
|
-
private createExecutionProvider;
|
|
154
|
-
/**
|
|
155
|
-
* Switch execution provider at runtime
|
|
156
|
-
*/
|
|
157
|
-
switchExecutionProvider(provider: "direct" | "dagger", options?: any): void;
|
|
158
|
-
/**
|
|
159
|
-
* Generate execution ID
|
|
160
|
-
*/
|
|
161
|
-
private generateExecutionId;
|
|
162
|
-
}
|