@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
package/dist/utils/config.js
DELETED
|
@@ -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;
|
package/dist/utils/env-loader.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
// src/utils/env-loader.ts - Environment variable loader for Enact tools with package namespace support
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { existsSync } from "fs";
|
|
5
|
-
import { readFile } from "fs/promises";
|
|
6
|
-
import { config as loadDotenv } from "dotenv";
|
|
7
|
-
// Configuration paths
|
|
8
|
-
const CONFIG_DIR = join(homedir(), ".enact");
|
|
9
|
-
/**
|
|
10
|
-
* Extract package namespace from tool name (excluding tool name)
|
|
11
|
-
* e.g., "kgroves88/dagger/social/bluesky-poster" -> "kgroves88/dagger/social"
|
|
12
|
-
*/
|
|
13
|
-
function extractPackageNamespace(toolName) {
|
|
14
|
-
const parts = toolName.split("/");
|
|
15
|
-
if (parts.length < 2) {
|
|
16
|
-
throw new Error('Tool name must be in format "org/package" or "org/package/tool"');
|
|
17
|
-
}
|
|
18
|
-
// Use all path parts except the last one (tool name)
|
|
19
|
-
// For tools like "kgroves88/dagger/social/bluesky-poster",
|
|
20
|
-
// we want the package path "kgroves88/dagger/social"
|
|
21
|
-
if (parts.length >= 2) {
|
|
22
|
-
return parts.slice(0, -1).join("/");
|
|
23
|
-
}
|
|
24
|
-
return parts[0]; // fallback for edge cases
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the environment file path for a package namespace
|
|
28
|
-
*/
|
|
29
|
-
function getPackageEnvPath(packageNamespace) {
|
|
30
|
-
return join(CONFIG_DIR, "env", packageNamespace, ".env");
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Simple decryption for encrypted values
|
|
34
|
-
*/
|
|
35
|
-
function decryptValue(encryptedValue) {
|
|
36
|
-
try {
|
|
37
|
-
return Buffer.from(encryptedValue, "base64").toString("utf8");
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return encryptedValue; // Return as-is if decryption fails
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Read environment configuration for a package namespace
|
|
45
|
-
*/
|
|
46
|
-
async function readPackageEnvConfig(packageNamespace) {
|
|
47
|
-
const envFile = getPackageEnvPath(packageNamespace);
|
|
48
|
-
if (!existsSync(envFile)) {
|
|
49
|
-
return { variables: {} };
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const data = await readFile(envFile, "utf8");
|
|
53
|
-
// Check if it's a simple .env file (KEY=value format) or JSON
|
|
54
|
-
if (data.trim().startsWith("{")) {
|
|
55
|
-
// It's JSON format (legacy package-managed variables)
|
|
56
|
-
return JSON.parse(data);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// It's simple .env format (project mode), return empty since these are handled separately
|
|
60
|
-
return { variables: {} };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
// Only warn if it's not a simple .env file parsing issue
|
|
65
|
-
if (!error.message.includes("Unexpected token")) {
|
|
66
|
-
console.warn(`Failed to read env config from ${envFile}: ${error.message}`);
|
|
67
|
-
}
|
|
68
|
-
return { variables: {} };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Load environment variables from Enact configuration for a specific package namespace
|
|
73
|
-
*/
|
|
74
|
-
export async function loadPackageEnvironmentVariables(packageNamespace) {
|
|
75
|
-
const config = await readPackageEnvConfig(packageNamespace);
|
|
76
|
-
const envVars = {};
|
|
77
|
-
// Load variables from the package namespace
|
|
78
|
-
for (const [name, envVar] of Object.entries(config.variables)) {
|
|
79
|
-
const value = envVar.encrypted ? decryptValue(envVar.value) : envVar.value;
|
|
80
|
-
envVars[name] = value;
|
|
81
|
-
}
|
|
82
|
-
return envVars;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Load environment variables from a package-based .env file
|
|
86
|
-
*/
|
|
87
|
-
function loadPackageEnvFile(toolName) {
|
|
88
|
-
if (!toolName) {
|
|
89
|
-
return {};
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
const packageNamespace = extractPackageNamespace(toolName);
|
|
93
|
-
const packageEnvPath = getPackageEnvPath(packageNamespace);
|
|
94
|
-
if (!existsSync(packageEnvPath)) {
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
// Load .env file and return the parsed variables
|
|
98
|
-
const result = loadDotenv({ path: packageEnvPath });
|
|
99
|
-
return result.parsed || {};
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.warn(`Warning: Failed to load package .env file: ${error.message}`);
|
|
103
|
-
return {};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Resolve environment variables for a tool definition with package namespace support
|
|
108
|
-
* Combines system environment, Enact package configuration, and tool-specific requirements
|
|
109
|
-
* Following the Enact protocol format:
|
|
110
|
-
* env:
|
|
111
|
-
* VARIABLE_NAME:
|
|
112
|
-
* description: string
|
|
113
|
-
* source: string
|
|
114
|
-
* required: boolean
|
|
115
|
-
* default: string (optional)
|
|
116
|
-
*/
|
|
117
|
-
export async function resolveToolEnvironmentVariables(toolName, toolEnvConfig) {
|
|
118
|
-
// Start with system environment variables
|
|
119
|
-
const resolved = { ...process.env };
|
|
120
|
-
// Load package .env file (if it exists) - priority 2
|
|
121
|
-
const packageEnvVars = loadPackageEnvFile(toolName);
|
|
122
|
-
Object.assign(resolved, packageEnvVars);
|
|
123
|
-
// Load package-specific environment variables if we have a tool name - priority 3 (highest)
|
|
124
|
-
if (toolName) {
|
|
125
|
-
try {
|
|
126
|
-
const packageNamespace = extractPackageNamespace(toolName);
|
|
127
|
-
const packageJsonEnvVars = await loadPackageEnvironmentVariables(packageNamespace);
|
|
128
|
-
// Override with package-managed JSON variables (highest priority)
|
|
129
|
-
Object.assign(resolved, packageJsonEnvVars);
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
// If we can't extract package namespace, continue without package env vars
|
|
133
|
-
console.warn(`Warning: Could not load package environment variables: ${error.message}`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const missing = [];
|
|
137
|
-
// Check tool-specific environment requirements following Enact protocol
|
|
138
|
-
if (toolEnvConfig) {
|
|
139
|
-
for (const [varName, config] of Object.entries(toolEnvConfig)) {
|
|
140
|
-
if (typeof config === "object" && config !== null) {
|
|
141
|
-
// Enact protocol: each env var has description, source, required, and optional default
|
|
142
|
-
const isRequired = config.required === true;
|
|
143
|
-
const defaultValue = config.default;
|
|
144
|
-
const source = config.source;
|
|
145
|
-
// Check if variable is already resolved
|
|
146
|
-
if (!(varName in resolved) || resolved[varName] === "") {
|
|
147
|
-
if (defaultValue !== undefined) {
|
|
148
|
-
resolved[varName] = String(defaultValue);
|
|
149
|
-
}
|
|
150
|
-
else if (isRequired) {
|
|
151
|
-
missing.push(varName);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Handle different sources as specified in the Enact protocol
|
|
155
|
-
if (source && resolved[varName]) {
|
|
156
|
-
// The source field tells us where the value should come from
|
|
157
|
-
// For now, we'll just ensure the variable is available
|
|
158
|
-
// In the future, this could be extended to support different sources
|
|
159
|
-
// like "user", "system", "config", etc.
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// Generate and show configuration link if there are missing variables
|
|
165
|
-
let configLink;
|
|
166
|
-
if (missing.length > 0) {
|
|
167
|
-
configLink = generateConfigLink(missing, toolName) || undefined;
|
|
168
|
-
if (configLink) {
|
|
169
|
-
console.log(`\nš§ Missing environment variables: ${missing.join(", ")}`);
|
|
170
|
-
console.log(`š Configure them here: ${configLink}\n`);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
console.log(`\nā ļø Missing required environment variables: ${missing.join(", ")}`);
|
|
174
|
-
console.log(`š” Set them using the 'enact env set' command or your system environment\n`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { resolved, missing, configLink };
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Get available environment variables for a package namespace
|
|
181
|
-
*/
|
|
182
|
-
export async function getPackageEnvironmentVariables(packageNamespace) {
|
|
183
|
-
const packageConfig = await readPackageEnvConfig(packageNamespace);
|
|
184
|
-
const packageVars = {};
|
|
185
|
-
// Process package variables
|
|
186
|
-
for (const [name, envVar] of Object.entries(packageConfig.variables)) {
|
|
187
|
-
packageVars[name] = {
|
|
188
|
-
value: envVar.encrypted ? "[encrypted]" : envVar.value,
|
|
189
|
-
encrypted: envVar.encrypted || false,
|
|
190
|
-
description: envVar.description,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// System environment variables (filtered to avoid exposing sensitive data)
|
|
194
|
-
const system = Object.fromEntries(Object.entries(process.env)
|
|
195
|
-
.filter(([key]) =>
|
|
196
|
-
// Only include environment variables that look like they might be relevant for tools
|
|
197
|
-
key.includes("API") ||
|
|
198
|
-
key.includes("TOKEN") ||
|
|
199
|
-
key.includes("KEY") ||
|
|
200
|
-
key.includes("URL") ||
|
|
201
|
-
key.includes("HOST") ||
|
|
202
|
-
key.includes("PORT") ||
|
|
203
|
-
key.startsWith("ENACT_") ||
|
|
204
|
-
key.startsWith("NODE_") ||
|
|
205
|
-
key.startsWith("NPM_"))
|
|
206
|
-
.map(([key, value]) => [key, value || ""]));
|
|
207
|
-
return { package: packageVars, system };
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Validate that all required environment variables are available
|
|
211
|
-
* Following the Enact protocol format for environment variables
|
|
212
|
-
*/
|
|
213
|
-
export function validateRequiredEnvironmentVariables(toolEnvConfig, availableVars) {
|
|
214
|
-
const missing = [];
|
|
215
|
-
const errors = [];
|
|
216
|
-
if (!toolEnvConfig) {
|
|
217
|
-
return { valid: true, missing, errors };
|
|
218
|
-
}
|
|
219
|
-
for (const [varName, config] of Object.entries(toolEnvConfig)) {
|
|
220
|
-
if (typeof config === "object" && config !== null) {
|
|
221
|
-
// Enact protocol: description, source, required are all required fields
|
|
222
|
-
// default is optional
|
|
223
|
-
const isRequired = config.required === true;
|
|
224
|
-
const hasDefault = config.default !== undefined;
|
|
225
|
-
const description = config.description || "";
|
|
226
|
-
const source = config.source || "";
|
|
227
|
-
if (isRequired &&
|
|
228
|
-
!hasDefault &&
|
|
229
|
-
(!(varName in availableVars) || availableVars[varName] === "")) {
|
|
230
|
-
missing.push(varName);
|
|
231
|
-
const errorMsg = `Required environment variable '${varName}' is not set`;
|
|
232
|
-
const detailMsg = description ? ` - ${description}` : "";
|
|
233
|
-
const sourceMsg = source ? ` (source: ${source})` : "";
|
|
234
|
-
errors.push(`${errorMsg}${detailMsg}${sourceMsg}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
valid: missing.length === 0,
|
|
240
|
-
missing,
|
|
241
|
-
errors,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
// Export the package namespace extraction function for use in other modules
|
|
245
|
-
export { extractPackageNamespace };
|
|
246
|
-
// Load .env file if it exists
|
|
247
|
-
loadDotenv();
|
|
248
|
-
/**
|
|
249
|
-
* Get the web server URL if it's running
|
|
250
|
-
*/
|
|
251
|
-
export function getWebServerUrl() {
|
|
252
|
-
// For now, default to localhost:5555 as that's the standard port
|
|
253
|
-
// When running via MCP (npx -p @enactprotocol/cli enact-mcp), the web server is automatically started
|
|
254
|
-
// TODO: In the future, we could check if the server is actually responding or get the port dynamically
|
|
255
|
-
return "http://localhost:5555";
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Generate a configuration link for missing environment variables
|
|
259
|
-
*/
|
|
260
|
-
export function generateConfigLink(missingVars, toolName) {
|
|
261
|
-
const webUrl = getWebServerUrl();
|
|
262
|
-
if (!webUrl) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
// Extract package namespace from tool name (exclude tool name itself)
|
|
266
|
-
const packageNamespace = extractPackageNamespace(toolName);
|
|
267
|
-
const encodedVars = encodeURIComponent(JSON.stringify(missingVars));
|
|
268
|
-
const encodedPackage = encodeURIComponent(packageNamespace);
|
|
269
|
-
return `${webUrl}/?vars=${encodedVars}&package=${encodedPackage}`;
|
|
270
|
-
}
|
package/dist/utils/help.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Show the main help message
|
|
3
|
-
*/
|
|
4
|
-
export declare function showHelp(): void;
|
|
5
|
-
/**
|
|
6
|
-
* Show version information
|
|
7
|
-
*/
|
|
8
|
-
export declare function showVersion(): void;
|
|
9
|
-
/**
|
|
10
|
-
* Show help for the auth command
|
|
11
|
-
*/
|
|
12
|
-
export declare function showAuthHelp(): void;
|
|
13
|
-
/**
|
|
14
|
-
* Show help for the init command
|
|
15
|
-
*/
|
|
16
|
-
export declare function showInitHelp(): void;
|
|
17
|
-
/**
|
|
18
|
-
* Show help for the publish command
|
|
19
|
-
*/
|
|
20
|
-
export declare function showPublishHelp(): void;
|
|
21
|
-
/**
|
|
22
|
-
* Show help for the search command
|
|
23
|
-
*/
|
|
24
|
-
export declare function showSearchHelp(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Show help for the remote command
|
|
27
|
-
*/
|
|
28
|
-
export declare function showRemoteHelp(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Show help for the user command
|
|
31
|
-
*/
|
|
32
|
-
export declare function showUserHelp(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Show help for the env command
|
|
35
|
-
*/
|
|
36
|
-
export declare function showEnvHelp(): void;
|