@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,604 +0,0 @@
1
- import {
2
- EnactToolDefinition,
3
- ToolSignaturePayload,
4
- ToolUsage,
5
- ToolSearchQuery,
6
- CLITokenCreate,
7
- OAuthTokenExchange,
8
- } from "./types";
9
- import { getFrontendUrl, getApiUrl } from "../utils/config";
10
-
11
- export class EnactApiClient {
12
- baseUrl: string;
13
- supabaseUrl: string;
14
-
15
- constructor(
16
- baseUrl: string,
17
- supabaseUrl: string,
18
- ) {
19
- this.baseUrl = baseUrl.replace(/\/$/, ""); // Remove trailing slash
20
- this.supabaseUrl = supabaseUrl.replace(/\/$/, "");
21
- }
22
-
23
- /**
24
- * Create API client with config-based URLs
25
- */
26
- static async create(
27
- baseUrl?: string,
28
- supabaseUrl?: string,
29
- ): Promise<EnactApiClient> {
30
- const frontendUrl = baseUrl || await getFrontendUrl();
31
- const apiUrl = supabaseUrl || await getApiUrl();
32
- return new EnactApiClient(frontendUrl, apiUrl);
33
- }
34
-
35
- // Helper method to make authenticated requests
36
- private async makeRequest<T>(
37
- endpoint: string,
38
- options: RequestInit = {},
39
- token?: string,
40
- tokenType: "jwt" | "cli" = "jwt",
41
- ): Promise<T> {
42
- const url = endpoint.startsWith("http")
43
- ? endpoint
44
- : `${this.supabaseUrl}${endpoint}`;
45
-
46
- const headers: Record<string, string> = {
47
- "Content-Type": "application/json",
48
- ...(options.headers as Record<string, string>),
49
- };
50
-
51
- // Add authentication headers if token provided
52
- if (token) {
53
- if (tokenType === "jwt") {
54
- headers.Authorization = `Bearer ${token}`;
55
- } else {
56
- headers["X-API-Key"] = token;
57
- }
58
- }
59
-
60
- const response = await fetch(url, {
61
- ...options,
62
- headers,
63
- });
64
-
65
- if (!response.ok) {
66
- const errorData = await response
67
- .json()
68
- .catch(() => ({ error: "Unknown error" }));
69
- throw new EnactApiError(
70
- `${(errorData as { error?: string }).error || response.statusText}`,
71
- response.status,
72
- endpoint,
73
- );
74
- }
75
-
76
- const responseData = await response.json();
77
-
78
- // Debug logging to help identify response structure issues
79
- if ((process.env.NODE_ENV === "development" || process.env.DEBUG) && !process.env.ENACT_SILENT) {
80
- console.error(`API Response for ${endpoint}:`, responseData);
81
- }
82
-
83
- return responseData as T;
84
- }
85
-
86
- // =================
87
- // PUBLIC ENDPOINTS
88
- // =================
89
-
90
- /**
91
- * Get all tools (public, no auth required)
92
- */
93
- async getTools(params?: {
94
- limit?: number;
95
- offset?: number;
96
- tags?: string[];
97
- author?: string;
98
- }): Promise<EnactToolDefinition[]> {
99
- const searchParams = new URLSearchParams();
100
- if (params?.limit) searchParams.set("limit", params.limit.toString());
101
- if (params?.offset) searchParams.set("offset", params.offset.toString());
102
- if (params?.tags) searchParams.set("tags", params.tags.join(","));
103
- if (params?.author) searchParams.set("author", params.author);
104
-
105
- const query = searchParams.toString();
106
- const endpoint = `/functions/v1/tools${query ? `?${query}` : ""}`;
107
-
108
- const response = await this.makeRequest<any>(endpoint);
109
-
110
- // Handle different response structures
111
- if (Array.isArray(response)) {
112
- return response;
113
- } else if (response.data && Array.isArray(response.data)) {
114
- return response.data;
115
- } else if (response.tools && Array.isArray(response.tools)) {
116
- return response.tools;
117
- } else {
118
- console.warn("Unexpected response structure for getTools:", response);
119
- return [];
120
- }
121
- }
122
-
123
- /**
124
- * Get specific tool details (public, no auth required)
125
- */
126
- async getTool(name: string): Promise<EnactToolDefinition> {
127
- const endpoint = `/functions/v1/tools/${encodeURIComponent(name)}`;
128
- return this.makeRequest<EnactToolDefinition>(endpoint);
129
- }
130
-
131
- /**
132
- * Get tool usage statistics (public, no auth required)
133
- */
134
- async getToolUsage(name: string): Promise<any> {
135
- const endpoint = `/functions/v1/tools/${encodeURIComponent(name)}/usage`;
136
- return this.makeRequest(endpoint);
137
- }
138
-
139
- /**
140
- * Log tool usage (public, no auth required)
141
- */
142
- async logToolUsage(name: string, usage: ToolUsage): Promise<any> {
143
- const endpoint = `/functions/v1/tools/${encodeURIComponent(name)}/usage`;
144
- return this.makeRequest(endpoint, {
145
- method: "POST",
146
- body: JSON.stringify(usage),
147
- });
148
- }
149
-
150
- /**
151
- * Search tools with semantic/text search (public, no auth required)
152
- */
153
- async searchTools(query: ToolSearchQuery): Promise<EnactToolDefinition[]> {
154
- const endpoint = "/functions/v1/tools-search";
155
-
156
- try {
157
- // Log the request for debugging
158
- if ((process.env.NODE_ENV === "development" || process.env.DEBUG) && !process.env.ENACT_SILENT) {
159
- console.error(
160
- `Search request to ${endpoint}:`,
161
- JSON.stringify(query, null, 2),
162
- );
163
- }
164
-
165
- const response = await this.makeRequest<any>(endpoint, {
166
- method: "POST",
167
- body: JSON.stringify(query),
168
- });
169
-
170
- // Handle different response structures
171
- if (Array.isArray(response)) {
172
- return response;
173
- } else if (response.data && Array.isArray(response.data)) {
174
- return response.data;
175
- } else if (response.results && Array.isArray(response.results)) {
176
- return response.results;
177
- } else if (response.tools && Array.isArray(response.tools)) {
178
- return response.tools;
179
- } else {
180
- console.warn(
181
- "Unexpected response structure for searchTools:",
182
- response,
183
- );
184
- return [];
185
- }
186
- } catch (error) {
187
- // Enhanced error logging
188
- if (error instanceof EnactApiError) {
189
- console.error(
190
- `Search API error (${error.statusCode}): ${error.message}`,
191
- );
192
- console.error(`Endpoint: ${error.endpoint}`);
193
-
194
- // If it's a 502 error, provide more specific guidance
195
- if (error.statusCode === 502) {
196
- console.error("502 Bad Gateway error - this usually indicates:");
197
- console.error("• The API server is temporarily unavailable");
198
- console.error("• The search service is overloaded");
199
- console.error("• Network connectivity issues");
200
- console.error("• Try again in a few moments");
201
- }
202
- } else {
203
- console.error("Unexpected search error:", error);
204
- }
205
-
206
- // Re-throw the error
207
- throw error;
208
- }
209
- }
210
-
211
- // ===================
212
- // AUTHENTICATED ENDPOINTS
213
- // ===================
214
-
215
- /**
216
- * Publish/create new tool (requires authentication)
217
- */
218
- async publishTool(
219
- tool: EnactToolDefinition,
220
- token: string,
221
- tokenType: "jwt" | "cli" = "cli",
222
- ): Promise<any> {
223
- const endpoint = "/functions/v1/tools";
224
- return this.makeRequest(
225
- endpoint,
226
- {
227
- method: "POST",
228
- body: JSON.stringify(tool),
229
- },
230
- token,
231
- tokenType,
232
- );
233
- }
234
-
235
- /**
236
- * Update existing tool (requires authentication, must be owner)
237
- */
238
- async updateTool(
239
- name: string,
240
- tool: EnactToolDefinition,
241
- token: string,
242
- tokenType: "jwt" | "cli" = "cli",
243
- ): Promise<any> {
244
- const endpoint = `/functions/v1/tools/${encodeURIComponent(name)}`;
245
- return this.makeRequest(
246
- endpoint,
247
- {
248
- method: "PUT",
249
- body: JSON.stringify(tool),
250
- },
251
- token,
252
- tokenType,
253
- );
254
- }
255
-
256
- /**
257
- * Delete tool (requires authentication, must be owner)
258
- */
259
- async deleteTool(
260
- name: string,
261
- token: string,
262
- tokenType: "jwt" | "cli" = "cli",
263
- ): Promise<any> {
264
- const endpoint = `/functions/v1/tools/${encodeURIComponent(name)}`;
265
- return this.makeRequest(
266
- endpoint,
267
- {
268
- method: "DELETE",
269
- },
270
- token,
271
- tokenType,
272
- );
273
- }
274
-
275
- /**
276
- * Create new CLI token (requires JWT authentication)
277
- */
278
- async createCLIToken(
279
- tokenData: CLITokenCreate,
280
- jwtToken: string,
281
- ): Promise<{ token: string; id: string; name?: string }> {
282
- const endpoint = "/functions/v1/cli-token";
283
- return this.makeRequest(
284
- endpoint,
285
- {
286
- method: "POST",
287
- body: JSON.stringify(tokenData),
288
- },
289
- jwtToken,
290
- "jwt",
291
- );
292
- }
293
-
294
- /**
295
- * List user's CLI tokens (requires JWT authentication)
296
- */
297
- async getCLITokens(jwtToken: string): Promise<any[]> {
298
- const endpoint = "/functions/v1/cli-token";
299
- return this.makeRequest(
300
- endpoint,
301
- {
302
- method: "GET",
303
- },
304
- jwtToken,
305
- "jwt",
306
- );
307
- }
308
-
309
- /**
310
- * Delete CLI token (requires JWT authentication, must be owner)
311
- */
312
- async deleteCLIToken(tokenId: string, jwtToken: string): Promise<any> {
313
- const endpoint = `/functions/v1/cli-token/${tokenId}`;
314
- return this.makeRequest(
315
- endpoint,
316
- {
317
- method: "DELETE",
318
- },
319
- jwtToken,
320
- "jwt",
321
- );
322
- }
323
-
324
- /**
325
- * Exchange OAuth authorization code for access token
326
- */
327
- async exchangeOAuthCode(oauthData: OAuthTokenExchange): Promise<{
328
- access_token: string;
329
- token_type: string;
330
- expires_in: number;
331
- scope?: string;
332
- }> {
333
- const endpoint = "/functions/v1/cli-oauth";
334
- return this.makeRequest(endpoint, {
335
- method: "POST",
336
- body: JSON.stringify(oauthData),
337
- });
338
- }
339
-
340
- /**
341
- * Generate embeddings for tools (requires authentication)
342
- */
343
- async generateEmbeddings(
344
- data: { toolId: string; text: string },
345
- token: string,
346
- tokenType: "jwt" | "cli" = "cli",
347
- ): Promise<any> {
348
- const endpoint = "/functions/v1/generate-embeddings";
349
- return this.makeRequest(
350
- endpoint,
351
- {
352
- method: "POST",
353
- body: JSON.stringify(data),
354
- },
355
- token,
356
- tokenType,
357
- );
358
- }
359
-
360
- // ===================
361
- // CONVENIENCE METHODS
362
- // ===================
363
-
364
- /**
365
- * Check if a tool exists
366
- */
367
- async toolExists(name: string): Promise<boolean> {
368
- try {
369
- await this.getTool(name);
370
- return true;
371
- } catch (error) {
372
- if (error instanceof Error && error.message.includes("404")) {
373
- return false;
374
- }
375
- throw error;
376
- }
377
- }
378
-
379
- /**
380
- * Publish or update tool based on existence
381
- */
382
- async publishOrUpdateTool(
383
- tool: EnactToolDefinition,
384
- token: string,
385
- tokenType: "jwt" | "cli" = "cli",
386
- ): Promise<{ isUpdate: boolean; result: any }> {
387
- let exists: boolean;
388
- try {
389
- exists = await this.toolExists(tool.name);
390
- } catch (error) {
391
- exists = false;
392
- }
393
- if (exists) {
394
- const result = await this.updateTool(tool.name, tool, token, tokenType);
395
- return { isUpdate: true, result };
396
- } else {
397
- const result = await this.publishTool(tool, token, tokenType);
398
- return { isUpdate: false, result };
399
- }
400
- }
401
-
402
- /**
403
- * Search tools by tags
404
- */
405
- async getToolsByTags(
406
- tags: string[],
407
- limit: number = 20,
408
- ): Promise<EnactToolDefinition[]> {
409
- return this.searchTools({
410
- query: tags.join(" "),
411
- tags,
412
- limit,
413
- });
414
- }
415
-
416
- /**
417
- * Get tools by author
418
- */
419
- async getToolsByAuthor(
420
- author: string,
421
- limit: number = 20,
422
- ): Promise<EnactToolDefinition[]> {
423
- return this.getTools({
424
- author,
425
- limit,
426
- });
427
- }
428
-
429
- /**
430
- * Get a user's public key
431
- */
432
- async getUserPublicKey(userId: string): Promise<any> {
433
- const url = `${this.supabaseUrl}/functions/v1/tools/user/public-key/${userId}`;
434
-
435
- const headers = {
436
- Accept: "application/json",
437
- "Content-Type": "application/json",
438
- };
439
-
440
- try {
441
- const response = await fetch(url, {
442
- method: "GET",
443
- headers,
444
- });
445
- if (!response.ok) {
446
- const errorText = await response.text();
447
- let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
448
-
449
- try {
450
- const errorJson = JSON.parse(errorText);
451
- if (errorJson.message) {
452
- errorMessage = errorJson.message;
453
- } else if (errorJson.error) {
454
- errorMessage = errorJson.error;
455
- }
456
- } catch {
457
- // If we can't parse JSON, stick with the original error message
458
- }
459
-
460
- throw new EnactApiError(errorMessage, response.status);
461
- }
462
-
463
- const data = await response.json();
464
- return data as any;
465
- } catch (error) {
466
- if (error instanceof EnactApiError) {
467
- throw error;
468
- }
469
-
470
- // Handle network errors
471
- if (error instanceof Error) {
472
- if (error.message.includes("fetch")) {
473
- throw new EnactApiError(
474
- "Network error: Could not connect to Enact API",
475
- 0,
476
- );
477
- }
478
- throw new EnactApiError(error.message, 0);
479
- }
480
-
481
- throw new EnactApiError("Unknown error occurred", 0);
482
- }
483
- }
484
-
485
- async signTool(
486
- toolId: string,
487
- payload: ToolSignaturePayload,
488
- token: string,
489
- tokenType: "jwt" | "cli" = "cli"
490
- ): Promise<any> {
491
- const endpoint = `/functions/v1/tools/${encodeURIComponent(toolId)}/signatures`;
492
-
493
- return this.makeRequest(endpoint, {
494
- method: "POST",
495
- body: JSON.stringify(payload),
496
- }, token, tokenType);
497
- }
498
-
499
- // ===================
500
- // OAUTH FLOW HELPERS
501
- // ===================
502
-
503
- /**
504
- * Generate OAuth authorization URL
505
- */
506
- generateOAuthUrl(options: {
507
- clientId: string;
508
- redirectUri: string;
509
- scope: string;
510
- state: string;
511
- codeChallenge: string;
512
- codeChallengeMethod: string;
513
- }): string {
514
- const params = new URLSearchParams({
515
- response_type: "code",
516
- client_id: options.clientId,
517
- redirect_uri: options.redirectUri,
518
- scope: options.scope,
519
- state: options.state,
520
- code_challenge: options.codeChallenge,
521
- code_challenge_method: options.codeChallengeMethod,
522
- });
523
-
524
- return `${this.baseUrl}/auth/cli/oauth?${params.toString()}`;
525
- }
526
-
527
- /**
528
- * Validate tool definition before publishing
529
- */
530
- validateTool(tool: any): { valid: boolean; errors: string[] } {
531
- const errors: string[] = [];
532
-
533
- if (!tool.name || typeof tool.name !== "string") {
534
- errors.push("Tool name is required and must be a string");
535
- } else if (!/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_\/-]+$/.test(tool.name)) {
536
- errors.push(
537
- "Tool name must follow hierarchical format: org/package/tool-name",
538
- );
539
- }
540
-
541
- if (!tool.description || typeof tool.description !== "string") {
542
- errors.push("Tool description is required and must be a string");
543
- }
544
-
545
- if (!tool.command || typeof tool.command !== "string") {
546
- errors.push("Tool command is required and must be a string");
547
- }
548
-
549
- if (tool.timeout && typeof tool.timeout === "string") {
550
- if (!/^\d+[smh]$/.test(tool.timeout)) {
551
- errors.push(
552
- 'Timeout must be in Go duration format (e.g., "30s", "5m", "1h")',
553
- );
554
- }
555
- }
556
-
557
- if (tool.tags && !Array.isArray(tool.tags)) {
558
- errors.push("Tags must be an array of strings");
559
- }
560
-
561
- if (tool.inputSchema && typeof tool.inputSchema !== "object") {
562
- errors.push("inputSchema must be a valid JSON Schema object");
563
- }
564
-
565
- if (tool.outputSchema && typeof tool.outputSchema !== "object") {
566
- errors.push("outputSchema must be a valid JSON Schema object");
567
- }
568
-
569
- return {
570
- valid: errors.length === 0,
571
- errors,
572
- };
573
- }
574
- }
575
-
576
- // Export a default instance factory
577
- export async function createDefaultApiClient(): Promise<EnactApiClient> {
578
- return await EnactApiClient.create();
579
- }
580
-
581
- // Keep backward compatibility with sync usage
582
- export const enactApi = new EnactApiClient("https://enact.tools", "https://xjnhhxwxovjifdxdwzih.supabase.co");
583
-
584
- // Export error types for better error handling
585
- export class EnactApiError extends Error {
586
- constructor(
587
- message: string,
588
- public statusCode?: number,
589
- public endpoint?: string,
590
- ) {
591
- super(message);
592
- this.name = "EnactApiError";
593
- }
594
- }
595
-
596
- // Helper function to create API client with custom configuration
597
- export function createEnactApiClient(
598
- baseUrl?: string,
599
- supabaseUrl?: string,
600
- ): EnactApiClient {
601
- const defaultFrontend = "https://enact.tools";
602
- const defaultApi = "https://xjnhhxwxovjifdxdwzih.supabase.co";
603
- return new EnactApiClient(baseUrl || defaultFrontend, supabaseUrl || defaultApi);
604
- }
package/src/api/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './enact-api';
2
- export * from './types';
package/src/api/types.ts DELETED
@@ -1,114 +0,0 @@
1
- export interface EnactToolDefinition {
2
- name: string;
3
- description: string;
4
- verified?: boolean; // Indicates if the tool has been verified
5
- command: string;
6
- from?: string;
7
- version?: string;
8
- timeout?: string;
9
- tags?: string[];
10
- inputSchema?: any;
11
- outputSchema?: any;
12
- examples?: any[];
13
- annotations?: {
14
- title?: string;
15
- readOnlyHint?: boolean;
16
- destructiveHint?: boolean;
17
- idempotentHint?: boolean;
18
- openWorldHint?: boolean;
19
- };
20
- env?: Record<
21
- string,
22
- {
23
- description: string;
24
- source?: string;
25
- required: boolean;
26
- default?: string;
27
- }
28
- >;
29
- resources?: {
30
- memory?: string;
31
- gpu?: string;
32
- disk?: string;
33
- };
34
- signature?: {
35
- algorithm: string;
36
- type: string;
37
- signer: string;
38
- created: string;
39
- value: string;
40
- role?: string;
41
- };
42
- signatures?: {
43
- signer: string;
44
- algorithm: string;
45
- type: string;
46
- value: string;
47
- created: string;
48
- role?: string;
49
- }[];
50
- raw_content?: string;
51
- namespace?: string;
52
- enact?: string;
53
- [key: string]: any;
54
- }
55
-
56
- export interface ToolSearchQuery {
57
- query: string;
58
- limit?: number;
59
- tags?: string[];
60
- format?: string;
61
- }
62
-
63
- export interface ToolUsage {
64
- action: "view" | "download" | "execute";
65
- metadata?: any;
66
- }
67
-
68
- export interface CLITokenCreate {
69
- name?: string;
70
- }
71
-
72
- export interface OAuthTokenExchange {
73
- grant_type: "authorization_code";
74
- code: string;
75
- redirect_uri: string;
76
- client_id: string;
77
- code_verifier: string;
78
- }
79
-
80
- export interface ApiResponse<T = any> {
81
- success: boolean;
82
- data?: T;
83
- error?: string;
84
- }
85
-
86
- export interface VerificationPolicy {
87
- minimumSignatures?: number;
88
- trustedSigners?: string[];
89
- allowedAlgorithms?: string[];
90
- }
91
-
92
- export interface EnactExecOptions {
93
- help?: boolean;
94
- input?: string;
95
- params?: string;
96
- timeout?: string;
97
- dry?: boolean;
98
- verbose?: boolean;
99
- force?: boolean; // Force execution even if verification fails (legacy)
100
- dangerouslySkipVerification?: boolean; // Skip all signature verification (DANGEROUS)
101
- mount?: string; // Mount local directory to container (format: "local:container")
102
- }
103
-
104
- export interface ToolSignaturePayload {
105
- algorithm: "sha256";
106
- created: string; // Time of signing
107
- key_id: string; // ID of the private key
108
- public_key: string; // The corresponding public key
109
- role: "author";
110
- signer: string; // The userID of the signer
111
- timestamp: number;
112
- type: "ecdsa-p256";
113
- value: string; // Signature
114
- }