@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.
Files changed (207) hide show
  1. package/README.md +44 -0
  2. package/dist/config.d.ts +164 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/config.js +386 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/constants.d.ts +15 -5
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/constants.js +24 -8
  9. package/dist/constants.js.map +1 -0
  10. package/dist/execution/command.d.ts +102 -0
  11. package/dist/execution/command.d.ts.map +1 -0
  12. package/dist/execution/command.js +262 -0
  13. package/dist/execution/command.js.map +1 -0
  14. package/dist/execution/index.d.ts +12 -0
  15. package/dist/execution/index.d.ts.map +1 -0
  16. package/dist/execution/index.js +17 -0
  17. package/dist/execution/index.js.map +1 -0
  18. package/dist/execution/runtime.d.ts +82 -0
  19. package/dist/execution/runtime.d.ts.map +1 -0
  20. package/dist/execution/runtime.js +273 -0
  21. package/dist/execution/runtime.js.map +1 -0
  22. package/dist/execution/types.d.ts +306 -0
  23. package/dist/execution/types.d.ts.map +1 -0
  24. package/dist/execution/types.js +14 -0
  25. package/dist/execution/types.js.map +1 -0
  26. package/dist/execution/validation.d.ts +43 -0
  27. package/dist/execution/validation.d.ts.map +1 -0
  28. package/dist/execution/validation.js +430 -0
  29. package/dist/execution/validation.js.map +1 -0
  30. package/dist/index.d.ts +21 -21
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +49 -25
  33. package/dist/index.js.map +1 -0
  34. package/dist/manifest/index.d.ts +7 -0
  35. package/dist/manifest/index.d.ts.map +1 -0
  36. package/dist/manifest/index.js +10 -0
  37. package/dist/manifest/index.js.map +1 -0
  38. package/dist/manifest/loader.d.ts +76 -0
  39. package/dist/manifest/loader.d.ts.map +1 -0
  40. package/dist/manifest/loader.js +146 -0
  41. package/dist/manifest/loader.js.map +1 -0
  42. package/dist/manifest/parser.d.ts +64 -0
  43. package/dist/manifest/parser.d.ts.map +1 -0
  44. package/dist/manifest/parser.js +135 -0
  45. package/dist/manifest/parser.js.map +1 -0
  46. package/dist/manifest/validator.d.ts +95 -0
  47. package/dist/manifest/validator.d.ts.map +1 -0
  48. package/dist/manifest/validator.js +258 -0
  49. package/dist/manifest/validator.js.map +1 -0
  50. package/dist/paths.d.ts +57 -0
  51. package/dist/paths.d.ts.map +1 -0
  52. package/dist/paths.js +93 -0
  53. package/dist/paths.js.map +1 -0
  54. package/dist/registry.d.ts +73 -0
  55. package/dist/registry.d.ts.map +1 -0
  56. package/dist/registry.js +147 -0
  57. package/dist/registry.js.map +1 -0
  58. package/dist/resolver.d.ts +89 -0
  59. package/dist/resolver.d.ts.map +1 -0
  60. package/dist/resolver.js +282 -0
  61. package/dist/resolver.js.map +1 -0
  62. package/dist/types/index.d.ts +6 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +5 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/types/manifest.d.ts +201 -0
  67. package/dist/types/manifest.d.ts.map +1 -0
  68. package/dist/types/manifest.js +13 -0
  69. package/dist/types/manifest.js.map +1 -0
  70. package/dist/types.d.ts +5 -132
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +5 -3
  73. package/dist/types.js.map +1 -0
  74. package/dist/utils/fs.d.ts +105 -0
  75. package/dist/utils/fs.d.ts.map +1 -0
  76. package/dist/utils/fs.js +233 -0
  77. package/dist/utils/fs.js.map +1 -0
  78. package/dist/utils/logger.d.ts +102 -25
  79. package/dist/utils/logger.d.ts.map +1 -0
  80. package/dist/utils/logger.js +214 -57
  81. package/dist/utils/logger.js.map +1 -0
  82. package/dist/utils/version.d.ts +60 -2
  83. package/dist/utils/version.d.ts.map +1 -0
  84. package/dist/utils/version.js +255 -31
  85. package/dist/utils/version.js.map +1 -0
  86. package/package.json +16 -58
  87. package/src/config.ts +510 -0
  88. package/src/constants.ts +36 -0
  89. package/src/execution/command.ts +314 -0
  90. package/src/execution/index.ts +73 -0
  91. package/src/execution/runtime.ts +308 -0
  92. package/src/execution/types.ts +379 -0
  93. package/src/execution/validation.ts +508 -0
  94. package/src/index.ts +238 -30
  95. package/src/manifest/index.ts +36 -0
  96. package/src/manifest/loader.ts +187 -0
  97. package/src/manifest/parser.ts +173 -0
  98. package/src/manifest/validator.ts +309 -0
  99. package/src/paths.ts +108 -0
  100. package/src/registry.ts +219 -0
  101. package/src/resolver.ts +345 -0
  102. package/src/types/index.ts +30 -0
  103. package/src/types/manifest.ts +255 -0
  104. package/src/types.ts +5 -188
  105. package/src/utils/fs.ts +281 -0
  106. package/src/utils/logger.ts +270 -59
  107. package/src/utils/version.ts +304 -36
  108. package/tests/config.test.ts +515 -0
  109. package/tests/execution/command.test.ts +317 -0
  110. package/tests/execution/validation.test.ts +384 -0
  111. package/tests/fixtures/invalid-tool.yaml +4 -0
  112. package/tests/fixtures/valid-tool.md +62 -0
  113. package/tests/fixtures/valid-tool.yaml +40 -0
  114. package/tests/index.test.ts +8 -0
  115. package/tests/manifest/loader.test.ts +291 -0
  116. package/tests/manifest/parser.test.ts +345 -0
  117. package/tests/manifest/validator.test.ts +394 -0
  118. package/tests/manifest-types.test.ts +358 -0
  119. package/tests/paths.test.ts +153 -0
  120. package/tests/registry.test.ts +231 -0
  121. package/tests/resolver.test.ts +272 -0
  122. package/tests/utils/fs.test.ts +388 -0
  123. package/tests/utils/logger.test.ts +480 -0
  124. package/tests/utils/version.test.ts +390 -0
  125. package/tsconfig.json +12 -0
  126. package/dist/LocalToolResolver.d.ts +0 -84
  127. package/dist/LocalToolResolver.js +0 -353
  128. package/dist/api/enact-api.d.ts +0 -130
  129. package/dist/api/enact-api.js +0 -428
  130. package/dist/api/index.d.ts +0 -2
  131. package/dist/api/index.js +0 -2
  132. package/dist/api/types.d.ts +0 -103
  133. package/dist/api/types.js +0 -1
  134. package/dist/core/DaggerExecutionProvider.d.ts +0 -169
  135. package/dist/core/DaggerExecutionProvider.js +0 -1029
  136. package/dist/core/DirectExecutionProvider.d.ts +0 -23
  137. package/dist/core/DirectExecutionProvider.js +0 -406
  138. package/dist/core/EnactCore.d.ts +0 -162
  139. package/dist/core/EnactCore.js +0 -597
  140. package/dist/core/NativeExecutionProvider.d.ts +0 -9
  141. package/dist/core/NativeExecutionProvider.js +0 -16
  142. package/dist/core/index.d.ts +0 -3
  143. package/dist/core/index.js +0 -3
  144. package/dist/exec/index.d.ts +0 -3
  145. package/dist/exec/index.js +0 -3
  146. package/dist/exec/logger.d.ts +0 -11
  147. package/dist/exec/logger.js +0 -57
  148. package/dist/exec/validate.d.ts +0 -5
  149. package/dist/exec/validate.js +0 -167
  150. package/dist/lib/enact-direct.d.ts +0 -150
  151. package/dist/lib/enact-direct.js +0 -159
  152. package/dist/lib/index.d.ts +0 -1
  153. package/dist/lib/index.js +0 -1
  154. package/dist/security/index.d.ts +0 -3
  155. package/dist/security/index.js +0 -3
  156. package/dist/security/security.d.ts +0 -23
  157. package/dist/security/security.js +0 -137
  158. package/dist/security/sign.d.ts +0 -103
  159. package/dist/security/sign.js +0 -666
  160. package/dist/security/verification-enforcer.d.ts +0 -53
  161. package/dist/security/verification-enforcer.js +0 -204
  162. package/dist/services/McpCoreService.d.ts +0 -98
  163. package/dist/services/McpCoreService.js +0 -124
  164. package/dist/services/index.d.ts +0 -1
  165. package/dist/services/index.js +0 -1
  166. package/dist/utils/config.d.ts +0 -111
  167. package/dist/utils/config.js +0 -342
  168. package/dist/utils/env-loader.d.ts +0 -54
  169. package/dist/utils/env-loader.js +0 -270
  170. package/dist/utils/help.d.ts +0 -36
  171. package/dist/utils/help.js +0 -248
  172. package/dist/utils/index.d.ts +0 -7
  173. package/dist/utils/index.js +0 -7
  174. package/dist/utils/silent-monitor.d.ts +0 -67
  175. package/dist/utils/silent-monitor.js +0 -242
  176. package/dist/utils/timeout.d.ts +0 -5
  177. package/dist/utils/timeout.js +0 -23
  178. package/dist/web/env-manager-server.d.ts +0 -29
  179. package/dist/web/env-manager-server.js +0 -367
  180. package/dist/web/index.d.ts +0 -1
  181. package/dist/web/index.js +0 -1
  182. package/src/LocalToolResolver.ts +0 -424
  183. package/src/api/enact-api.ts +0 -604
  184. package/src/api/index.ts +0 -2
  185. package/src/api/types.ts +0 -114
  186. package/src/core/DaggerExecutionProvider.ts +0 -1357
  187. package/src/core/DirectExecutionProvider.ts +0 -484
  188. package/src/core/EnactCore.ts +0 -847
  189. package/src/core/index.ts +0 -3
  190. package/src/exec/index.ts +0 -3
  191. package/src/exec/logger.ts +0 -63
  192. package/src/exec/validate.ts +0 -238
  193. package/src/lib/enact-direct.ts +0 -254
  194. package/src/lib/index.ts +0 -1
  195. package/src/services/McpCoreService.ts +0 -201
  196. package/src/services/index.ts +0 -1
  197. package/src/utils/config.ts +0 -438
  198. package/src/utils/env-loader.ts +0 -370
  199. package/src/utils/help.ts +0 -257
  200. package/src/utils/index.ts +0 -7
  201. package/src/utils/silent-monitor.ts +0 -328
  202. package/src/utils/timeout.ts +0 -26
  203. package/src/web/env-manager-server.ts +0 -465
  204. package/src/web/index.ts +0 -1
  205. package/src/web/static/app.js +0 -663
  206. package/src/web/static/index.html +0 -117
  207. package/src/web/static/style.css +0 -291
@@ -1,597 +0,0 @@
1
- import { EnactApiClient } from "../api/enact-api.js";
2
- import { validateToolStructure, validateInputs, } from "../exec/validate.js";
3
- import { DirectExecutionProvider } from "./DirectExecutionProvider.js";
4
- import { DaggerExecutionProvider } from "./DaggerExecutionProvider.js";
5
- import { resolveToolEnvironmentVariables } from "../utils/env-loader.js";
6
- import logger from "../exec/logger.js";
7
- import yaml from "yaml";
8
- import { SecurityConfigManager, SigningService } from "@enactprotocol/security";
9
- import { getFrontendUrl, getApiUrl } from "../utils/config";
10
- export class EnactCore {
11
- constructor(options = {}) {
12
- this.options = {
13
- apiUrl: "https://enact.tools", // Default, will be overridden by factory
14
- supabaseUrl: "https://xjnhhxwxovjifdxdwzih.supabase.co", // Default, will be overridden by factory
15
- executionProvider: "dagger",
16
- defaultTimeout: "30s",
17
- ...options,
18
- };
19
- this.apiClient = new EnactApiClient(this.options.apiUrl, this.options.supabaseUrl);
20
- // Initialize the appropriate execution provider
21
- this.executionProvider = this.createExecutionProvider();
22
- }
23
- /**
24
- * Create EnactCore with config-based URLs
25
- */
26
- static async create(options = {}) {
27
- const frontendUrl = options.apiUrl || await getFrontendUrl();
28
- const apiUrl = options.supabaseUrl || await getApiUrl();
29
- return new EnactCore({
30
- ...options,
31
- apiUrl: frontendUrl,
32
- supabaseUrl: apiUrl,
33
- });
34
- }
35
- /**
36
- * Set authentication token for API operations
37
- */
38
- setAuthToken(token) {
39
- this.options.authToken = token;
40
- }
41
- /**
42
- * Static method to search for tools (no execution provider needed)
43
- */
44
- static async searchTools(options, coreOptions = {}) {
45
- const apiClient = new EnactApiClient(coreOptions.apiUrl || "https://enact.tools", coreOptions.supabaseUrl || "https://xjnhhxwxovjifdxdwzih.supabase.co");
46
- try {
47
- logger.info(`Searching for tools with query: "${options.query}"`);
48
- const searchParams = {
49
- query: options.query,
50
- limit: options.limit,
51
- tags: options.tags,
52
- };
53
- const results = await apiClient.searchTools(searchParams);
54
- // Parse and validate results
55
- const tools = [];
56
- for (const result of results) {
57
- if (result.name) {
58
- try {
59
- const tool = await EnactCore.getToolByName(result.name, undefined, coreOptions);
60
- if (tool) {
61
- tools.push(tool);
62
- }
63
- }
64
- catch (error) {
65
- logger.warn(`Failed to fetch tool ${result.name}:`, error);
66
- }
67
- }
68
- }
69
- logger.info(`Found ${tools.length} tools`);
70
- return tools;
71
- }
72
- catch (error) {
73
- logger.error("Error searching tools:", error);
74
- // If it's a 502 error (API server issue), try fallback to local filtering
75
- if (error instanceof Error && error.message.includes("502")) {
76
- logger.info("Search API unavailable, trying fallback to local filtering...");
77
- return EnactCore.searchToolsFallback(options, coreOptions);
78
- }
79
- throw new Error(`Search failed: ${error instanceof Error ? error.message : String(error)}`);
80
- }
81
- }
82
- /**
83
- * Instance method wrapper for backward compatibility
84
- */
85
- async searchTools(options) {
86
- return EnactCore.searchTools(options, this.options);
87
- }
88
- /**
89
- * Static fallback search method that gets all tools and filters locally
90
- */
91
- static async searchToolsFallback(options, coreOptions = {}) {
92
- const apiClient = new EnactApiClient(coreOptions.apiUrl || "https://enact.tools", coreOptions.supabaseUrl || "https://xjnhhxwxovjifdxdwzih.supabase.co");
93
- try {
94
- logger.info("Using fallback search method...");
95
- // Get all tools (limited to avoid overwhelming the API)
96
- const allTools = await apiClient.getTools({
97
- limit: options.limit || 100,
98
- });
99
- // Filter tools locally based on search criteria
100
- const filteredTools = [];
101
- const query = options.query.toLowerCase();
102
- for (const result of allTools) {
103
- if (result.name) {
104
- try {
105
- const tool = await EnactCore.getToolByName(result.name, undefined, coreOptions);
106
- if (tool) {
107
- // Check if tool matches search criteria
108
- const matchesQuery = tool.name.toLowerCase().includes(query) ||
109
- (tool.description &&
110
- tool.description.toLowerCase().includes(query)) ||
111
- (tool.tags &&
112
- tool.tags.some((tag) => tag.toLowerCase().includes(query)));
113
- const matchesTags = !options.tags ||
114
- !options.tags.length ||
115
- (tool.tags &&
116
- options.tags.some((searchTag) => tool.tags.some((toolTag) => toolTag.toLowerCase().includes(searchTag.toLowerCase()))));
117
- const matchesAuthor = !options.author ||
118
- (tool.authors &&
119
- tool.authors.some((author) => author.name &&
120
- author.name
121
- .toLowerCase()
122
- .includes(options.author.toLowerCase())));
123
- if (matchesQuery && matchesTags && matchesAuthor) {
124
- filteredTools.push(tool);
125
- // Apply limit if specified
126
- if (options.limit && filteredTools.length >= options.limit) {
127
- break;
128
- }
129
- }
130
- }
131
- }
132
- catch (error) {
133
- logger.warn(`Failed to fetch tool ${result.name} in fallback search:`, error);
134
- }
135
- }
136
- }
137
- logger.info(`Fallback search found ${filteredTools.length} tools`);
138
- return filteredTools;
139
- }
140
- catch (fallbackError) {
141
- logger.error("Fallback search also failed:", fallbackError);
142
- throw new Error(`Search failed (including fallback): ${fallbackError instanceof Error ? fallbackError.message : String(fallbackError)}`);
143
- }
144
- }
145
- /**
146
- * Static method to get a specific tool by name
147
- */
148
- static async getToolByName(name, version, coreOptions = {}) {
149
- const apiClient = new EnactApiClient(coreOptions.apiUrl || "https://enact.tools", coreOptions.supabaseUrl || "https://xjnhhxwxovjifdxdwzih.supabase.co");
150
- try {
151
- logger.info(`Fetching tool: ${name}${version ? `@${version}` : ""}`);
152
- const response = await apiClient.getTool(name);
153
- if (!response) {
154
- logger.info(`Tool not found: ${name}`);
155
- return null;
156
- }
157
- // Parse tool from response - prefer raw_content for signature compatibility
158
- let tool;
159
- // Try raw_content first (contains original tool definition with correct field names for signatures)
160
- if (response.raw_content && typeof response.raw_content === "string") {
161
- try {
162
- tool = JSON.parse(response.raw_content);
163
- }
164
- catch {
165
- tool = yaml.parse(response.raw_content);
166
- }
167
- // Merge signature information from response if not already in raw content
168
- if (!tool.signature && response.signature) {
169
- tool.signature = response.signature;
170
- }
171
- if (!tool.signatures && response.signatures) {
172
- // Convert object format to array format
173
- if (Array.isArray(response.signatures)) {
174
- tool.signatures = response.signatures;
175
- }
176
- else {
177
- // Convert object format {keyId: signatureData} to array format
178
- tool.signatures = Object.values(response.signatures);
179
- }
180
- }
181
- }
182
- else if (response.content && typeof response.content === "string") {
183
- tool = yaml.parse(response.content);
184
- // Merge signature information
185
- if (!tool.signature && response.signature) {
186
- tool.signature = response.signature;
187
- }
188
- if (!tool.signatures && response.signatures) {
189
- // Convert object format to array format
190
- if (Array.isArray(response.signatures)) {
191
- tool.signatures = response.signatures;
192
- }
193
- else {
194
- // Convert object format {keyId: signatureData} to array format
195
- tool.signatures = Object.values(response.signatures);
196
- }
197
- }
198
- }
199
- else {
200
- // Fallback: map database fields to tool format (may cause signature verification issues)
201
- tool = {
202
- name: response.name,
203
- description: response.description,
204
- command: response.command,
205
- timeout: response.timeout || "30s",
206
- tags: response.tags || [],
207
- license: response.license || response.spdx_license,
208
- outputSchema: response.output_schema || response.outputSchema,
209
- enact: response.protocol_version || response.enact || "1.0.0",
210
- version: response.version,
211
- inputSchema: response.input_schema || response.inputSchema,
212
- examples: response.examples,
213
- annotations: response.annotations,
214
- env: response.env_vars || response.env,
215
- resources: response.resources,
216
- signature: response.signature,
217
- signatures: response.signatures ? (Array.isArray(response.signatures) ? response.signatures : Object.values(response.signatures)) : undefined,
218
- namespace: response.namespace,
219
- };
220
- }
221
- logger.info(`Successfully fetched tool: ${tool.name}`);
222
- return tool;
223
- }
224
- catch (error) {
225
- if (error instanceof Error && error.message.includes("404")) {
226
- logger.info(`Tool not found: ${name}`);
227
- return null;
228
- }
229
- logger.error(`Error fetching tool: ${error instanceof Error ? error.message : String(error)}`);
230
- throw error;
231
- }
232
- }
233
- /**
234
- * Instance method wrapper for backward compatibility
235
- */
236
- async getToolByName(name, version) {
237
- return EnactCore.getToolByName(name, version, this.options);
238
- }
239
- /**
240
- * Execute a tool by name
241
- */
242
- async executeToolByName(name, inputs = {}, options = {}) {
243
- const executionId = this.generateExecutionId();
244
- try {
245
- // Fetch the tool
246
- const tool = await this.getToolByName(name);
247
- if (!tool) {
248
- return {
249
- success: false,
250
- error: {
251
- message: `Tool not found: ${name}`,
252
- code: "NOT_FOUND",
253
- },
254
- metadata: {
255
- executionId,
256
- toolName: name,
257
- executedAt: new Date().toISOString(),
258
- environment: "direct",
259
- },
260
- };
261
- }
262
- // Execute the tool
263
- return await this.executeTool(tool, inputs, options);
264
- }
265
- catch (error) {
266
- return {
267
- success: false,
268
- error: {
269
- message: error.message,
270
- code: "EXECUTION_ERROR",
271
- },
272
- metadata: {
273
- executionId,
274
- toolName: name,
275
- executedAt: new Date().toISOString(),
276
- environment: "direct",
277
- },
278
- };
279
- }
280
- }
281
- static async checkToolVerificationStatus(tool) {
282
- const documentForVerification = {
283
- command: tool.command,
284
- description: tool.description,
285
- from: tool.from,
286
- name: tool.name,
287
- signatures: tool.signatures?.map(sig => ({
288
- signature: sig.value,
289
- publicKey: "", // TODO: Look up the correct public key
290
- algorithm: sig.algorithm,
291
- timestamp: new Date(sig.created).getTime(),
292
- })),
293
- };
294
- let isValid = false;
295
- if (tool.signatures && tool.signatures.length > 0) {
296
- isValid = tool.signatures.some(sig => {
297
- const referenceSignature = {
298
- signature: sig.value,
299
- publicKey: "", // TODO: Lookup correct public key based on signature UUID
300
- algorithm: sig.algorithm,
301
- timestamp: new Date(sig.created).getTime()
302
- };
303
- return SigningService.verifyDocument(documentForVerification, referenceSignature, { includeFields: ['command', 'description', 'from', 'name'] });
304
- });
305
- }
306
- return isValid;
307
- }
308
- async verifyTool(tool, dangerouslySkipVerification = false) {
309
- if (dangerouslySkipVerification) {
310
- logger.warn(`Skipping signature verification for tool: ${tool.name}`);
311
- return;
312
- }
313
- try {
314
- if (!tool.signatures || tool.signatures.length === 0) {
315
- throw new Error(`Tool ${tool.name} does not have any signatures`);
316
- }
317
- // const documentForVerification = {
318
- // command: tool.command,
319
- // description: tool.description,
320
- // from: tool.from,
321
- // name: tool.name,
322
- // };
323
- // const referenceSignature = {
324
- // signature: tool.signatures[0].value,
325
- // publicKey: "", // Correct public key for UUID 71e02e2c-148c-4534-9900-bd9646e99333
326
- // algorithm: tool.signatures[0].algorithm,
327
- // timestamp: new Date(tool.signatures[0].created).getTime()
328
- // };
329
- // // Check what canonical document looks like
330
- // const canonicalDoc = SigningService.getCanonicalDocument(documentForVerification, { includeFields: ['command', 'description', 'from', 'name'] }
331
- // );
332
- // const docString = JSON.stringify(canonicalDoc);
333
- // const messageHash = CryptoUtils.hash(docString);
334
- // // Test direct crypto verification
335
- // const directVerify = CryptoUtils.verify(
336
- // referenceSignature.publicKey,
337
- // messageHash,
338
- // referenceSignature.signature
339
- // );
340
- // Check trusted keys
341
- // const trustedKeys = KeyManager.getAllTrustedPublicKeys();
342
- const isValid = await EnactCore.checkToolVerificationStatus(tool);
343
- console.log("Final verification result:", isValid);
344
- if (!isValid) {
345
- throw new Error(`Tool ${tool.name} has invalid signatures`);
346
- }
347
- logger.info(`Tool ${tool.name} signature verification passed`);
348
- }
349
- catch (error) {
350
- logger.error(`Signature verification failed for tool ${tool.name}:`, error);
351
- throw new Error(`Signature verification failed: ${error instanceof Error ? error.message : String(error)}`);
352
- }
353
- }
354
- /**
355
- * Execute a tool directly
356
- */
357
- async executeTool(tool, inputs = {}, options = {}) {
358
- const executionId = this.generateExecutionId();
359
- try {
360
- logger.info(`Executing tool: ${tool.name}`);
361
- // Validate tool structure
362
- validateToolStructure(tool);
363
- // Validate inputs
364
- const validatedInputs = validateInputs(tool, inputs);
365
- const config = SecurityConfigManager.loadConfig();
366
- if (options.isLocalFile && config.allowLocalUnsigned) {
367
- logger.warn(`Executing local file without signature verification: ${tool.name} (you can disallow in your security config)`);
368
- }
369
- if (options.dangerouslySkipVerification) {
370
- logger.warn(`Skipping signature verification for tool: ${tool.name} because of dangerouslySkipVerification option`);
371
- }
372
- const skipVerification = (options.isLocalFile && config.allowLocalUnsigned) || Boolean(options.dangerouslySkipVerification);
373
- // Verify tool signatures (unless explicitly skipped)
374
- await this.verifyTool(tool, skipVerification);
375
- // Resolve environment variables
376
- const { resolved: envVars } = await resolveToolEnvironmentVariables(tool.name, tool.env || {});
377
- // Execute the tool via the execution provider
378
- return await this.executionProvider.execute(tool, { ...validatedInputs, ...envVars }, {
379
- vars: { ...envVars, ...validatedInputs },
380
- resources: {
381
- timeout: options.timeout || tool.timeout || this.options.defaultTimeout,
382
- },
383
- mount: options.mount,
384
- });
385
- }
386
- catch (error) {
387
- return {
388
- success: false,
389
- error: {
390
- message: error.message,
391
- code: "EXECUTION_ERROR",
392
- },
393
- metadata: {
394
- executionId,
395
- toolName: tool.name,
396
- executedAt: new Date().toISOString(),
397
- environment: "direct",
398
- },
399
- };
400
- }
401
- }
402
- /**
403
- * Execute a tool from raw YAML definition
404
- */
405
- async executeRawTool(toolYaml, inputs = {}, options = {}) {
406
- try {
407
- // Parse the YAML
408
- const tool = yaml.parse(toolYaml);
409
- // Validate that it's a proper tool definition
410
- if (!tool || typeof tool !== "object") {
411
- throw new Error("Invalid tool definition: YAML must contain a tool object");
412
- }
413
- // Check for required fields
414
- if (!tool.name || !tool.description || !tool.command) {
415
- throw new Error("Invalid tool definition: missing required fields (name, description, command)");
416
- }
417
- // Execute the tool
418
- return await this.executeTool(tool, inputs, options);
419
- }
420
- catch (error) {
421
- const executionId = this.generateExecutionId();
422
- return {
423
- success: false,
424
- error: {
425
- message: error.message,
426
- code: "PARSE_ERROR",
427
- },
428
- metadata: {
429
- executionId,
430
- toolName: "unknown",
431
- executedAt: new Date().toISOString(),
432
- environment: "direct",
433
- },
434
- };
435
- }
436
- }
437
- /**
438
- * Static method to check if a tool exists
439
- */
440
- static async toolExists(name, coreOptions = {}) {
441
- try {
442
- const tool = await EnactCore.getToolByName(name, undefined, coreOptions);
443
- return tool !== null;
444
- }
445
- catch (error) {
446
- return false;
447
- }
448
- }
449
- /**
450
- * Instance method wrapper for backward compatibility
451
- */
452
- async toolExists(name) {
453
- return EnactCore.toolExists(name, this.options);
454
- }
455
- /**
456
- * Get tools by tags
457
- */
458
- async getToolsByTags(tags, limit = 20) {
459
- return EnactCore.searchTools({
460
- query: tags.join(" "),
461
- tags,
462
- limit,
463
- }, this.options);
464
- }
465
- /**
466
- * Get tools by author
467
- */
468
- async getToolsByAuthor(author, limit = 20) {
469
- return EnactCore.searchTools({
470
- query: `author:${author}`,
471
- author,
472
- limit,
473
- }, this.options);
474
- }
475
- /**
476
- * Static method to get all tools with filters
477
- */
478
- static async getTools(options = {}, coreOptions = {}) {
479
- const apiClient = new EnactApiClient(coreOptions.apiUrl || "https://enact.tools", coreOptions.supabaseUrl || "https://xjnhhxwxovjifdxdwzih.supabase.co");
480
- try {
481
- const apiResults = await apiClient.getTools(options);
482
- // Parse and validate results
483
- const tools = [];
484
- for (const result of apiResults) {
485
- if (result.name) {
486
- try {
487
- const tool = await EnactCore.getToolByName(result.name, undefined, coreOptions);
488
- if (tool) {
489
- tools.push(tool);
490
- }
491
- }
492
- catch (error) {
493
- logger.warn(`Failed to fetch tool ${result.name}:`, error);
494
- }
495
- }
496
- }
497
- return tools;
498
- }
499
- catch (error) {
500
- logger.error("Error getting tools:", error);
501
- throw new Error(`Failed to get tools: ${error instanceof Error ? error.message : String(error)}`);
502
- }
503
- }
504
- /**
505
- * Instance method wrapper for backward compatibility
506
- */
507
- async getTools(options = {}) {
508
- return EnactCore.getTools(options, this.options);
509
- }
510
- /**
511
- * Get authentication status (placeholder - would need actual auth implementation)
512
- */
513
- async getAuthStatus() {
514
- // This would need to check actual auth state
515
- // For now, return based on whether we have a token
516
- return {
517
- authenticated: !!this.options.authToken,
518
- server: this.options.apiUrl,
519
- };
520
- }
521
- /**
522
- * Static method to publish a tool
523
- */
524
- static async publishTool(tool, authToken, coreOptions = {}) {
525
- const apiClient = new EnactApiClient(coreOptions.apiUrl || "https://enact.tools", coreOptions.supabaseUrl || "https://xjnhhxwxovjifdxdwzih.supabase.co");
526
- try {
527
- validateToolStructure(tool);
528
- await apiClient.publishTool(tool, authToken);
529
- return {
530
- success: true,
531
- message: `Successfully published tool: ${tool.name}`,
532
- };
533
- }
534
- catch (error) {
535
- return {
536
- success: false,
537
- message: `Failed to publish tool: ${error instanceof Error ? error.message : String(error)}`,
538
- };
539
- }
540
- }
541
- /**
542
- * Instance method wrapper for backward compatibility
543
- */
544
- async publishTool(tool) {
545
- if (!this.options.authToken) {
546
- return {
547
- success: false,
548
- message: "Authentication required to publish tools",
549
- };
550
- }
551
- return EnactCore.publishTool(tool, this.options.authToken, this.options);
552
- }
553
- /**
554
- * Get tool information (alias for getToolByName for consistency)
555
- */
556
- async getToolInfo(name, version) {
557
- return EnactCore.getToolByName(name, version, this.options);
558
- }
559
- /**
560
- * Get core library status
561
- */
562
- async getStatus() {
563
- const authStatus = await this.getAuthStatus();
564
- return {
565
- executionProvider: this.options.executionProvider || "direct",
566
- apiUrl: this.options.apiUrl || "https://enact.tools",
567
- defaultTimeout: this.options.defaultTimeout || "30s",
568
- authenticated: authStatus.authenticated,
569
- };
570
- }
571
- /**
572
- * Create the appropriate execution provider based on options
573
- */
574
- createExecutionProvider() {
575
- switch (this.options.executionProvider) {
576
- case "direct":
577
- return new DirectExecutionProvider();
578
- case "dagger":
579
- default:
580
- return new DaggerExecutionProvider(this.options.daggerOptions);
581
- }
582
- }
583
- /**
584
- * Switch execution provider at runtime
585
- */
586
- switchExecutionProvider(provider, options) {
587
- this.options.executionProvider = provider;
588
- this.executionProvider = this.createExecutionProvider();
589
- }
590
- /**
591
- * Generate execution ID
592
- */
593
- generateExecutionId() {
594
- return `exec_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
595
- }
596
- }
597
- // No default instance to avoid eager initialization of Dagger
@@ -1,9 +0,0 @@
1
- import { ExecutionProvider, type EnactTool, type ExecutionEnvironment, type ExecutionResult } from "../types.js";
2
- /**
3
- * Native execution provider that throws an error if used for actual execution.
4
- * This is for CLI commands that use Core for API operations only.
5
- */
6
- export declare class NativeExecutionProvider extends ExecutionProvider {
7
- resolveEnvironmentVariables(envConfig: Record<string, any>, namespace?: string): Promise<Record<string, any>>;
8
- execute(tool: EnactTool, input: Record<string, any>, environment: ExecutionEnvironment): Promise<ExecutionResult>;
9
- }
@@ -1,16 +0,0 @@
1
- // src/core/NativeExecutionProvider.ts - No-op execution provider for CLI commands
2
- import { ExecutionProvider, } from "../types.js";
3
- /**
4
- * Native execution provider that throws an error if used for actual execution.
5
- * This is for CLI commands that use Core for API operations only.
6
- */
7
- export class NativeExecutionProvider extends ExecutionProvider {
8
- async resolveEnvironmentVariables(envConfig, namespace) {
9
- // This should never be called for native CLI commands
10
- throw new Error("Native execution provider cannot resolve environment variables");
11
- }
12
- async execute(tool, input, environment) {
13
- // This should never be called for native CLI commands
14
- throw new Error(`Native execution provider cannot execute tools. Tool "${tool.name}" should be executed via direct or dagger provider.`);
15
- }
16
- }
@@ -1,3 +0,0 @@
1
- export * from './EnactCore';
2
- export * from './DirectExecutionProvider';
3
- export * from './DaggerExecutionProvider';
@@ -1,3 +0,0 @@
1
- export * from './EnactCore';
2
- export * from './DirectExecutionProvider';
3
- export * from './DaggerExecutionProvider';
@@ -1,3 +0,0 @@
1
- export { default } from './logger';
2
- export { default as logger } from './logger';
3
- export * from './validate';
@@ -1,3 +0,0 @@
1
- export { default } from './logger';
2
- export { default as logger } from './logger';
3
- export * from './validate';
@@ -1,11 +0,0 @@
1
- declare const logger: import("pino").Logger<never, boolean>;
2
- declare const wrappedLogger: {
3
- info: (msg: string, ...args: any[]) => void;
4
- warn: (msg: string, ...args: any[]) => void;
5
- error: (msg: string, ...args: any[]) => void;
6
- debug: (msg: string, ...args: any[]) => void;
7
- clientLoggingEnabled: () => boolean;
8
- isLevelEnabled: (level: string) => boolean;
9
- pino: import("pino").Logger<never, boolean>;
10
- };
11
- export default wrappedLogger;