@enactprotocol/shared 1.2.11 → 2.0.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 (134) hide show
  1. package/README.md +44 -0
  2. package/package.json +16 -58
  3. package/src/config.ts +476 -0
  4. package/src/constants.ts +36 -0
  5. package/src/execution/command.ts +314 -0
  6. package/src/execution/index.ts +73 -0
  7. package/src/execution/runtime.ts +308 -0
  8. package/src/execution/types.ts +379 -0
  9. package/src/execution/validation.ts +508 -0
  10. package/src/index.ts +237 -30
  11. package/src/manifest/index.ts +36 -0
  12. package/src/manifest/loader.ts +187 -0
  13. package/src/manifest/parser.ts +173 -0
  14. package/src/manifest/validator.ts +309 -0
  15. package/src/paths.ts +108 -0
  16. package/src/registry.ts +219 -0
  17. package/src/resolver.ts +345 -0
  18. package/src/types/index.ts +30 -0
  19. package/src/types/manifest.ts +255 -0
  20. package/src/types.ts +5 -188
  21. package/src/utils/fs.ts +281 -0
  22. package/src/utils/logger.ts +270 -59
  23. package/src/utils/version.ts +304 -36
  24. package/tests/config.test.ts +515 -0
  25. package/tests/execution/command.test.ts +317 -0
  26. package/tests/execution/validation.test.ts +384 -0
  27. package/tests/fixtures/invalid-tool.yaml +4 -0
  28. package/tests/fixtures/valid-tool.md +62 -0
  29. package/tests/fixtures/valid-tool.yaml +40 -0
  30. package/tests/index.test.ts +8 -0
  31. package/tests/manifest/loader.test.ts +291 -0
  32. package/tests/manifest/parser.test.ts +345 -0
  33. package/tests/manifest/validator.test.ts +394 -0
  34. package/tests/manifest-types.test.ts +358 -0
  35. package/tests/paths.test.ts +153 -0
  36. package/tests/registry.test.ts +231 -0
  37. package/tests/resolver.test.ts +272 -0
  38. package/tests/utils/fs.test.ts +388 -0
  39. package/tests/utils/logger.test.ts +480 -0
  40. package/tests/utils/version.test.ts +390 -0
  41. package/tsconfig.json +12 -0
  42. package/tsconfig.tsbuildinfo +1 -0
  43. package/dist/LocalToolResolver.d.ts +0 -84
  44. package/dist/LocalToolResolver.js +0 -353
  45. package/dist/api/enact-api.d.ts +0 -130
  46. package/dist/api/enact-api.js +0 -428
  47. package/dist/api/index.d.ts +0 -2
  48. package/dist/api/index.js +0 -2
  49. package/dist/api/types.d.ts +0 -103
  50. package/dist/api/types.js +0 -1
  51. package/dist/constants.d.ts +0 -7
  52. package/dist/constants.js +0 -10
  53. package/dist/core/DaggerExecutionProvider.d.ts +0 -169
  54. package/dist/core/DaggerExecutionProvider.js +0 -1029
  55. package/dist/core/DirectExecutionProvider.d.ts +0 -23
  56. package/dist/core/DirectExecutionProvider.js +0 -406
  57. package/dist/core/EnactCore.d.ts +0 -162
  58. package/dist/core/EnactCore.js +0 -597
  59. package/dist/core/NativeExecutionProvider.d.ts +0 -9
  60. package/dist/core/NativeExecutionProvider.js +0 -16
  61. package/dist/core/index.d.ts +0 -3
  62. package/dist/core/index.js +0 -3
  63. package/dist/exec/index.d.ts +0 -3
  64. package/dist/exec/index.js +0 -3
  65. package/dist/exec/logger.d.ts +0 -11
  66. package/dist/exec/logger.js +0 -57
  67. package/dist/exec/validate.d.ts +0 -5
  68. package/dist/exec/validate.js +0 -167
  69. package/dist/index.d.ts +0 -21
  70. package/dist/index.js +0 -25
  71. package/dist/lib/enact-direct.d.ts +0 -150
  72. package/dist/lib/enact-direct.js +0 -159
  73. package/dist/lib/index.d.ts +0 -1
  74. package/dist/lib/index.js +0 -1
  75. package/dist/security/index.d.ts +0 -3
  76. package/dist/security/index.js +0 -3
  77. package/dist/security/security.d.ts +0 -23
  78. package/dist/security/security.js +0 -137
  79. package/dist/security/sign.d.ts +0 -103
  80. package/dist/security/sign.js +0 -666
  81. package/dist/security/verification-enforcer.d.ts +0 -53
  82. package/dist/security/verification-enforcer.js +0 -204
  83. package/dist/services/McpCoreService.d.ts +0 -98
  84. package/dist/services/McpCoreService.js +0 -124
  85. package/dist/services/index.d.ts +0 -1
  86. package/dist/services/index.js +0 -1
  87. package/dist/types.d.ts +0 -132
  88. package/dist/types.js +0 -3
  89. package/dist/utils/config.d.ts +0 -111
  90. package/dist/utils/config.js +0 -342
  91. package/dist/utils/env-loader.d.ts +0 -54
  92. package/dist/utils/env-loader.js +0 -270
  93. package/dist/utils/help.d.ts +0 -36
  94. package/dist/utils/help.js +0 -248
  95. package/dist/utils/index.d.ts +0 -7
  96. package/dist/utils/index.js +0 -7
  97. package/dist/utils/logger.d.ts +0 -35
  98. package/dist/utils/logger.js +0 -75
  99. package/dist/utils/silent-monitor.d.ts +0 -67
  100. package/dist/utils/silent-monitor.js +0 -242
  101. package/dist/utils/timeout.d.ts +0 -5
  102. package/dist/utils/timeout.js +0 -23
  103. package/dist/utils/version.d.ts +0 -4
  104. package/dist/utils/version.js +0 -35
  105. package/dist/web/env-manager-server.d.ts +0 -29
  106. package/dist/web/env-manager-server.js +0 -367
  107. package/dist/web/index.d.ts +0 -1
  108. package/dist/web/index.js +0 -1
  109. package/src/LocalToolResolver.ts +0 -424
  110. package/src/api/enact-api.ts +0 -604
  111. package/src/api/index.ts +0 -2
  112. package/src/api/types.ts +0 -114
  113. package/src/core/DaggerExecutionProvider.ts +0 -1357
  114. package/src/core/DirectExecutionProvider.ts +0 -484
  115. package/src/core/EnactCore.ts +0 -847
  116. package/src/core/index.ts +0 -3
  117. package/src/exec/index.ts +0 -3
  118. package/src/exec/logger.ts +0 -63
  119. package/src/exec/validate.ts +0 -238
  120. package/src/lib/enact-direct.ts +0 -254
  121. package/src/lib/index.ts +0 -1
  122. package/src/services/McpCoreService.ts +0 -201
  123. package/src/services/index.ts +0 -1
  124. package/src/utils/config.ts +0 -438
  125. package/src/utils/env-loader.ts +0 -370
  126. package/src/utils/help.ts +0 -257
  127. package/src/utils/index.ts +0 -7
  128. package/src/utils/silent-monitor.ts +0 -328
  129. package/src/utils/timeout.ts +0 -26
  130. package/src/web/env-manager-server.ts +0 -465
  131. package/src/web/index.ts +0 -1
  132. package/src/web/static/app.js +0 -663
  133. package/src/web/static/index.html +0 -117
  134. package/src/web/static/style.css +0 -291
@@ -1,111 +0,0 @@
1
- export interface EnactConfig {
2
- defaultUrl?: string;
3
- history?: string[];
4
- urls?: {
5
- frontend?: string;
6
- api?: string;
7
- };
8
- }
9
- /**
10
- * Ensure config directory and file exist
11
- */
12
- export declare function ensureConfig(): Promise<void>;
13
- /**
14
- * Read the config file
15
- */
16
- export declare function readConfig(): Promise<EnactConfig>;
17
- /**
18
- * Write to the config file
19
- */
20
- export declare function writeConfig(config: EnactConfig): Promise<void>;
21
- /**
22
- * Add a file to the publish history
23
- */
24
- export declare function addToHistory(filePath: string): Promise<void>;
25
- /**
26
- * Get the publish history
27
- */
28
- export declare function getHistory(): Promise<string[]>;
29
- /**
30
- * Set the default publish URL
31
- */
32
- export declare function setDefaultUrl(url: string): Promise<void>;
33
- /**
34
- * Get the default publish URL
35
- */
36
- export declare function getDefaultUrl(): Promise<string | undefined>;
37
- export interface TrustedKeyMeta {
38
- name: string;
39
- description?: string;
40
- addedAt: string;
41
- source: "default" | "user" | "organization";
42
- keyFile: string;
43
- }
44
- export interface TrustedKey {
45
- id: string;
46
- name: string;
47
- publicKey: string;
48
- description?: string;
49
- addedAt: string;
50
- source: "default" | "user" | "organization";
51
- keyFile: string;
52
- }
53
- /**
54
- * Get the frontend URL with fallbacks
55
- */
56
- export declare function getFrontendUrl(): Promise<string>;
57
- /**
58
- * Get the API URL with fallbacks
59
- */
60
- export declare function getApiUrl(): Promise<string>;
61
- /**
62
- * Set the frontend URL in config
63
- */
64
- export declare function setFrontendUrl(url: string): Promise<void>;
65
- /**
66
- * Set the API URL in config
67
- */
68
- export declare function setApiUrl(url: string): Promise<void>;
69
- /**
70
- * Reset URLs to defaults
71
- */
72
- export declare function resetUrls(): Promise<void>;
73
- /**
74
- * Get current URL configuration
75
- */
76
- export declare function getUrlConfig(): Promise<{
77
- frontend: {
78
- value: string;
79
- source: string;
80
- };
81
- api: {
82
- value: string;
83
- source: string;
84
- };
85
- }>;
86
- /**
87
- * Read all trusted keys from directory
88
- */
89
- export declare function getTrustedKeys(): Promise<TrustedKey[]>;
90
- /**
91
- * Add a trusted key
92
- */
93
- export declare function addTrustedKey(keyData: {
94
- id: string;
95
- name: string;
96
- publicKey: string;
97
- description?: string;
98
- source?: "user" | "organization";
99
- }): Promise<void>;
100
- /**
101
- * Remove a trusted key
102
- */
103
- export declare function removeTrustedKey(keyId: string): Promise<void>;
104
- /**
105
- * Get a specific trusted key
106
- */
107
- export declare function getTrustedKey(keyId: string): Promise<TrustedKey | null>;
108
- /**
109
- * Check if a public key is trusted
110
- */
111
- export declare function isKeyTrusted(publicKey: string): Promise<boolean>;
@@ -1,342 +0,0 @@
1
- // src/utils/config.ts
2
- import { homedir } from "os";
3
- import { join } from "path";
4
- import { existsSync } from "fs";
5
- import { mkdir, readFile, writeFile } from "fs/promises";
6
- // Define config paths
7
- const CONFIG_DIR = join(homedir(), ".enact");
8
- const CONFIG_FILE = join(CONFIG_DIR, "config.json");
9
- const TRUSTED_KEYS_DIR = join(CONFIG_DIR, "trusted-keys");
10
- /**
11
- * Ensure config directory and file exist
12
- */
13
- export async function ensureConfig() {
14
- if (!existsSync(CONFIG_DIR)) {
15
- await mkdir(CONFIG_DIR, { recursive: true });
16
- }
17
- if (!existsSync(CONFIG_FILE)) {
18
- const defaultConfig = {
19
- history: [],
20
- urls: {
21
- frontend: DEFAULT_FRONTEND_URL,
22
- api: DEFAULT_API_URL,
23
- },
24
- };
25
- await writeFile(CONFIG_FILE, JSON.stringify(defaultConfig, null, 2));
26
- }
27
- }
28
- /**
29
- * Read the config file
30
- */
31
- export async function readConfig() {
32
- await ensureConfig();
33
- try {
34
- const data = await readFile(CONFIG_FILE, "utf8");
35
- const config = JSON.parse(data);
36
- // Migrate old configs that don't have URLs section
37
- if (!config.urls) {
38
- config.urls = {
39
- frontend: DEFAULT_FRONTEND_URL,
40
- api: DEFAULT_API_URL,
41
- };
42
- await writeConfig(config);
43
- }
44
- return config;
45
- }
46
- catch (error) {
47
- console.error("Failed to read config:", error.message);
48
- return {
49
- history: [],
50
- urls: {
51
- frontend: DEFAULT_FRONTEND_URL,
52
- api: DEFAULT_API_URL,
53
- },
54
- };
55
- }
56
- }
57
- /**
58
- * Write to the config file
59
- */
60
- export async function writeConfig(config) {
61
- await ensureConfig();
62
- await writeFile(CONFIG_FILE, JSON.stringify(config, null, 2));
63
- }
64
- /**
65
- * Add a file to the publish history
66
- */
67
- export async function addToHistory(filePath) {
68
- const config = await readConfig();
69
- if (!config.history) {
70
- config.history = [];
71
- }
72
- // Add to history if not already there
73
- if (!config.history.includes(filePath)) {
74
- config.history.unshift(filePath);
75
- // Keep history to a reasonable size
76
- config.history = config.history.slice(0, 10);
77
- await writeConfig(config);
78
- }
79
- }
80
- /**
81
- * Get the publish history
82
- */
83
- export async function getHistory() {
84
- const config = await readConfig();
85
- return config.history || [];
86
- }
87
- /**
88
- * Set the default publish URL
89
- */
90
- export async function setDefaultUrl(url) {
91
- const config = await readConfig();
92
- config.defaultUrl = url;
93
- await writeConfig(config);
94
- }
95
- /**
96
- * Get the default publish URL
97
- */
98
- export async function getDefaultUrl() {
99
- const config = await readConfig();
100
- return config.defaultUrl;
101
- }
102
- // Default URLs
103
- const DEFAULT_FRONTEND_URL = "https://enact.tools";
104
- const DEFAULT_API_URL = "https://xjnhhxwxovjifdxdwzih.supabase.co";
105
- // Default trusted public key (Enact Protocol official key)
106
- const DEFAULT_ENACT_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
107
- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE8VyE3jGm5yT2mKnPx1dQF7q8Z2Kv
108
- 7mX9YnE2mK8vF3tY9pL6xH2dF8sK3mN7wQ5vT2gR8sL4xN6pM9uE3wF2Qw==
109
- -----END PUBLIC KEY-----`;
110
- /**
111
- * Get the frontend URL with fallbacks
112
- */
113
- export async function getFrontendUrl() {
114
- // 1. Environment variable override
115
- if (process.env.ENACT_FRONTEND_URL) {
116
- return process.env.ENACT_FRONTEND_URL;
117
- }
118
- // 2. Config file setting
119
- const config = await readConfig();
120
- if (config.urls?.frontend) {
121
- return config.urls.frontend;
122
- }
123
- // 3. Default
124
- return DEFAULT_FRONTEND_URL;
125
- }
126
- /**
127
- * Get the API URL with fallbacks
128
- */
129
- export async function getApiUrl() {
130
- // 1. Environment variable override
131
- if (process.env.ENACT_API_URL) {
132
- return process.env.ENACT_API_URL;
133
- }
134
- // 2. Config file setting
135
- const config = await readConfig();
136
- if (config.urls?.api) {
137
- return config.urls.api;
138
- }
139
- // 3. Default
140
- return DEFAULT_API_URL;
141
- }
142
- /**
143
- * Set the frontend URL in config
144
- */
145
- export async function setFrontendUrl(url) {
146
- const config = await readConfig();
147
- if (!config.urls) {
148
- config.urls = {};
149
- }
150
- config.urls.frontend = url;
151
- await writeConfig(config);
152
- }
153
- /**
154
- * Set the API URL in config
155
- */
156
- export async function setApiUrl(url) {
157
- const config = await readConfig();
158
- if (!config.urls) {
159
- config.urls = {};
160
- }
161
- config.urls.api = url;
162
- await writeConfig(config);
163
- }
164
- /**
165
- * Reset URLs to defaults
166
- */
167
- export async function resetUrls() {
168
- const config = await readConfig();
169
- if (config.urls) {
170
- delete config.urls.frontend;
171
- delete config.urls.api;
172
- }
173
- await writeConfig(config);
174
- }
175
- /**
176
- * Get current URL configuration
177
- */
178
- export async function getUrlConfig() {
179
- const config = await readConfig();
180
- // Determine frontend URL source
181
- let frontendValue = DEFAULT_FRONTEND_URL;
182
- let frontendSource = "default";
183
- if (config.urls?.frontend) {
184
- frontendValue = config.urls.frontend;
185
- frontendSource = "config";
186
- }
187
- if (process.env.ENACT_FRONTEND_URL) {
188
- frontendValue = process.env.ENACT_FRONTEND_URL;
189
- frontendSource = "environment";
190
- }
191
- // Determine API URL source
192
- let apiValue = DEFAULT_API_URL;
193
- let apiSource = "default";
194
- if (config.urls?.api) {
195
- apiValue = config.urls.api;
196
- apiSource = "config";
197
- }
198
- if (process.env.ENACT_API_URL) {
199
- apiValue = process.env.ENACT_API_URL;
200
- apiSource = "environment";
201
- }
202
- return {
203
- frontend: { value: frontendValue, source: frontendSource },
204
- api: { value: apiValue, source: apiSource },
205
- };
206
- }
207
- /**
208
- * Ensure trusted keys directory exists with default key
209
- */
210
- async function ensureTrustedKeysDir() {
211
- if (!existsSync(CONFIG_DIR)) {
212
- await mkdir(CONFIG_DIR, { recursive: true });
213
- }
214
- if (!existsSync(TRUSTED_KEYS_DIR)) {
215
- await mkdir(TRUSTED_KEYS_DIR, { recursive: true });
216
- }
217
- // Create default Enact Protocol key if it doesn't exist
218
- const defaultKeyFile = join(TRUSTED_KEYS_DIR, "enact-protocol-official.pem");
219
- const defaultMetaFile = join(TRUSTED_KEYS_DIR, "enact-protocol-official.meta");
220
- if (!existsSync(defaultKeyFile)) {
221
- await writeFile(defaultKeyFile, DEFAULT_ENACT_PUBLIC_KEY);
222
- }
223
- if (!existsSync(defaultMetaFile)) {
224
- const defaultMeta = {
225
- name: "Enact Protocol Official",
226
- description: "Official Enact Protocol signing key for verified tools",
227
- addedAt: new Date().toISOString(),
228
- source: "default",
229
- keyFile: "enact-protocol-official.pem"
230
- };
231
- await writeFile(defaultMetaFile, JSON.stringify(defaultMeta, null, 2));
232
- }
233
- }
234
- /**
235
- * Read all trusted keys from directory
236
- */
237
- export async function getTrustedKeys() {
238
- await ensureTrustedKeysDir();
239
- const keys = [];
240
- try {
241
- const { readdir } = await import('fs/promises');
242
- const files = await readdir(TRUSTED_KEYS_DIR);
243
- // Get all .pem files
244
- const pemFiles = files.filter(f => f.endsWith('.pem'));
245
- for (const pemFile of pemFiles) {
246
- try {
247
- const keyId = pemFile.replace('.pem', '');
248
- const keyPath = join(TRUSTED_KEYS_DIR, pemFile);
249
- const metaPath = join(TRUSTED_KEYS_DIR, `${keyId}.meta`);
250
- // Read the public key
251
- const publicKey = await readFile(keyPath, 'utf8');
252
- // Read metadata if it exists
253
- let meta = {
254
- name: keyId,
255
- addedAt: new Date().toISOString(),
256
- source: "user",
257
- keyFile: pemFile
258
- };
259
- if (existsSync(metaPath)) {
260
- try {
261
- const metaData = await readFile(metaPath, 'utf8');
262
- meta = { ...meta, ...JSON.parse(metaData) };
263
- }
264
- catch {
265
- // Use defaults if meta file is corrupted
266
- }
267
- }
268
- keys.push({
269
- id: keyId,
270
- name: meta.name,
271
- publicKey: publicKey.trim(),
272
- description: meta.description,
273
- addedAt: meta.addedAt,
274
- source: meta.source,
275
- keyFile: pemFile
276
- });
277
- }
278
- catch (error) {
279
- console.warn(`Warning: Could not read key file ${pemFile}:`, error);
280
- }
281
- }
282
- }
283
- catch (error) {
284
- console.error("Failed to read trusted keys directory:", error);
285
- }
286
- return keys;
287
- }
288
- /**
289
- * Add a trusted key
290
- */
291
- export async function addTrustedKey(keyData) {
292
- await ensureTrustedKeysDir();
293
- const keyFile = `${keyData.id}.pem`;
294
- const metaFile = `${keyData.id}.meta`;
295
- const keyPath = join(TRUSTED_KEYS_DIR, keyFile);
296
- const metaPath = join(TRUSTED_KEYS_DIR, metaFile);
297
- // Check if key already exists
298
- if (existsSync(keyPath)) {
299
- throw new Error(`Key with ID '${keyData.id}' already exists`);
300
- }
301
- // Write the public key file
302
- await writeFile(keyPath, keyData.publicKey);
303
- // Write the metadata file
304
- const meta = {
305
- name: keyData.name,
306
- description: keyData.description,
307
- addedAt: new Date().toISOString(),
308
- source: keyData.source || "user",
309
- keyFile
310
- };
311
- await writeFile(metaPath, JSON.stringify(meta, null, 2));
312
- }
313
- /**
314
- * Remove a trusted key
315
- */
316
- export async function removeTrustedKey(keyId) {
317
- const keyPath = join(TRUSTED_KEYS_DIR, `${keyId}.pem`);
318
- const metaPath = join(TRUSTED_KEYS_DIR, `${keyId}.meta`);
319
- if (!existsSync(keyPath)) {
320
- throw new Error(`Trusted key '${keyId}' not found`);
321
- }
322
- // Remove both files
323
- const { unlink } = await import('fs/promises');
324
- await unlink(keyPath);
325
- if (existsSync(metaPath)) {
326
- await unlink(metaPath);
327
- }
328
- }
329
- /**
330
- * Get a specific trusted key
331
- */
332
- export async function getTrustedKey(keyId) {
333
- const keys = await getTrustedKeys();
334
- return keys.find(k => k.id === keyId) || null;
335
- }
336
- /**
337
- * Check if a public key is trusted
338
- */
339
- export async function isKeyTrusted(publicKey) {
340
- const keys = await getTrustedKeys();
341
- return keys.some(k => k.publicKey.trim() === publicKey.trim());
342
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Extract package namespace from tool name (excluding tool name)
3
- * e.g., "kgroves88/dagger/social/bluesky-poster" -> "kgroves88/dagger/social"
4
- */
5
- declare function extractPackageNamespace(toolName: string): string;
6
- /**
7
- * Load environment variables from Enact configuration for a specific package namespace
8
- */
9
- export declare function loadPackageEnvironmentVariables(packageNamespace: string): Promise<Record<string, string>>;
10
- /**
11
- * Resolve environment variables for a tool definition with package namespace support
12
- * Combines system environment, Enact package configuration, and tool-specific requirements
13
- * Following the Enact protocol format:
14
- * env:
15
- * VARIABLE_NAME:
16
- * description: string
17
- * source: string
18
- * required: boolean
19
- * default: string (optional)
20
- */
21
- export declare function resolveToolEnvironmentVariables(toolName: string, toolEnvConfig?: Record<string, any>): Promise<{
22
- resolved: Record<string, string>;
23
- missing: string[];
24
- configLink?: string;
25
- }>;
26
- /**
27
- * Get available environment variables for a package namespace
28
- */
29
- export declare function getPackageEnvironmentVariables(packageNamespace: string): Promise<{
30
- package: Record<string, {
31
- value: string;
32
- encrypted: boolean;
33
- description?: string;
34
- }>;
35
- system: Record<string, string>;
36
- }>;
37
- /**
38
- * Validate that all required environment variables are available
39
- * Following the Enact protocol format for environment variables
40
- */
41
- export declare function validateRequiredEnvironmentVariables(toolEnvConfig: Record<string, any> | undefined, availableVars: Record<string, string>): {
42
- valid: boolean;
43
- missing: string[];
44
- errors: string[];
45
- };
46
- export { extractPackageNamespace };
47
- /**
48
- * Get the web server URL if it's running
49
- */
50
- export declare function getWebServerUrl(): string | null;
51
- /**
52
- * Generate a configuration link for missing environment variables
53
- */
54
- export declare function generateConfigLink(missingVars: string[], toolName: string): string | null;