@elliotding/ai-agent-mcp 0.1.26 → 0.1.28
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 +330 -30
- package/dist/api/cached-client.d.ts +48 -0
- package/dist/api/cached-client.d.ts.map +1 -0
- package/dist/api/cached-client.js +126 -0
- package/dist/api/cached-client.js.map +1 -0
- package/dist/api/client.d.ts +295 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +385 -0
- package/dist/api/client.js.map +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +26 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware.d.ts +36 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +194 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/permissions.d.ts +60 -0
- package/dist/auth/permissions.d.ts.map +1 -0
- package/dist/auth/permissions.js +262 -0
- package/dist/auth/permissions.js.map +1 -0
- package/dist/auth/token-validator.d.ts +52 -0
- package/dist/auth/token-validator.d.ts.map +1 -0
- package/dist/auth/token-validator.js +215 -0
- package/dist/auth/token-validator.js.map +1 -0
- package/dist/cache/cache-manager.d.ts +49 -0
- package/dist/cache/cache-manager.d.ts.map +1 -0
- package/dist/cache/cache-manager.js +191 -0
- package/dist/cache/cache-manager.js.map +1 -0
- package/dist/cache/index.d.ts +6 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +12 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/redis-client.d.ts +45 -0
- package/dist/cache/redis-client.d.ts.map +1 -0
- package/dist/cache/redis-client.js +210 -0
- package/dist/cache/redis-client.js.map +1 -0
- package/dist/config/constants.d.ts +28 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +31 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/index.d.ts +71 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +190 -0
- package/dist/config/index.js.map +1 -0
- package/dist/filesystem/manager.d.ts +45 -0
- package/dist/filesystem/manager.d.ts.map +1 -0
- package/dist/filesystem/manager.js +246 -0
- package/dist/filesystem/manager.js.map +1 -0
- package/dist/git/multi-source-manager.d.ts +105 -0
- package/dist/git/multi-source-manager.d.ts.map +1 -0
- package/dist/git/multi-source-manager.js +677 -0
- package/dist/git/multi-source-manager.js.map +1 -0
- package/dist/git/operations.d.ts +27 -0
- package/dist/git/operations.d.ts.map +1 -0
- package/dist/git/operations.js +83 -0
- package/dist/git/operations.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/monitoring/health.d.ts +35 -0
- package/dist/monitoring/health.d.ts.map +1 -0
- package/dist/monitoring/health.js +105 -0
- package/dist/monitoring/health.js.map +1 -0
- package/dist/prompts/cache.d.ts +69 -0
- package/dist/prompts/cache.d.ts.map +1 -0
- package/dist/prompts/cache.js +163 -0
- package/dist/prompts/cache.js.map +1 -0
- package/dist/prompts/generator.d.ts +49 -0
- package/dist/prompts/generator.d.ts.map +1 -0
- package/dist/prompts/generator.js +160 -0
- package/dist/prompts/generator.js.map +1 -0
- package/dist/prompts/index.d.ts +13 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +24 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/manager.d.ts +213 -0
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts/manager.js +587 -0
- package/dist/prompts/manager.js.map +1 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +10 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/loader.d.ts +88 -0
- package/dist/resources/loader.d.ts.map +1 -0
- package/dist/resources/loader.js +492 -0
- package/dist/resources/loader.js.map +1 -0
- package/dist/server/http.d.ts +57 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +435 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +201 -0
- package/dist/server.js.map +1 -0
- package/dist/session/manager.d.ts +91 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +251 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +7 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/manager.d.ts +151 -0
- package/dist/telemetry/manager.d.ts.map +1 -0
- package/dist/telemetry/manager.js +367 -0
- package/dist/telemetry/manager.js.map +1 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +29 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/manage-subscription.d.ts +47 -0
- package/dist/tools/manage-subscription.d.ts.map +1 -0
- package/dist/tools/manage-subscription.js +317 -0
- package/dist/tools/manage-subscription.js.map +1 -0
- package/dist/tools/registry.d.ts +40 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +85 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/resolve-prompt-content.d.ts +35 -0
- package/dist/tools/resolve-prompt-content.d.ts.map +1 -0
- package/dist/tools/resolve-prompt-content.js +99 -0
- package/dist/tools/resolve-prompt-content.js.map +1 -0
- package/dist/tools/search-resources.d.ts +35 -0
- package/dist/tools/search-resources.d.ts.map +1 -0
- package/dist/tools/search-resources.js +159 -0
- package/dist/tools/search-resources.js.map +1 -0
- package/dist/tools/sync-resources.d.ts +54 -0
- package/dist/tools/sync-resources.d.ts.map +1 -0
- package/dist/tools/sync-resources.js +793 -0
- package/dist/tools/sync-resources.js.map +1 -0
- package/dist/tools/track-usage.d.ts +63 -0
- package/dist/tools/track-usage.d.ts.map +1 -0
- package/dist/tools/track-usage.js +90 -0
- package/dist/tools/track-usage.js.map +1 -0
- package/dist/tools/uninstall-resource.d.ts +30 -0
- package/dist/tools/uninstall-resource.d.ts.map +1 -0
- package/dist/tools/uninstall-resource.js +186 -0
- package/dist/tools/uninstall-resource.js.map +1 -0
- package/dist/tools/upload-resource.d.ts +81 -0
- package/dist/tools/upload-resource.d.ts.map +1 -0
- package/dist/tools/upload-resource.js +393 -0
- package/dist/tools/upload-resource.js.map +1 -0
- package/dist/transport/sse.d.ts +29 -0
- package/dist/transport/sse.d.ts.map +1 -0
- package/dist/transport/sse.js +271 -0
- package/dist/transport/sse.js.map +1 -0
- package/dist/types/errors.d.ts +60 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +112 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mcp.d.ts +50 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +6 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/resources.d.ts +109 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +7 -0
- package/dist/types/resources.js.map +1 -0
- package/dist/types/tools.d.ts +274 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +6 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/cursor-paths.d.ts +84 -0
- package/dist/utils/cursor-paths.d.ts.map +1 -0
- package/dist/utils/cursor-paths.js +166 -0
- package/dist/utils/cursor-paths.js.map +1 -0
- package/dist/utils/log-cleaner.d.ts +18 -0
- package/dist/utils/log-cleaner.d.ts.map +1 -0
- package/dist/utils/log-cleaner.js +112 -0
- package/dist/utils/log-cleaner.js.map +1 -0
- package/dist/utils/logger.d.ts +59 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +292 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +58 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +214 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST API Client
|
|
3
|
+
* HTTP client for CSP Resource Server
|
|
4
|
+
*/
|
|
5
|
+
import { AxiosRequestConfig } from 'axios';
|
|
6
|
+
declare class APIClient {
|
|
7
|
+
private client;
|
|
8
|
+
private readonly maxRetries;
|
|
9
|
+
private readonly retryDelay;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Build an AxiosRequestConfig that carries a per-request user token.
|
|
13
|
+
* Pass the result as the `config` argument to get/post/put/delete or merge it
|
|
14
|
+
* into any existing request config so that the caller's token overrides the
|
|
15
|
+
* server-level fallback set in the interceptor.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* await apiClient.get('/some/path', apiClient.authConfig(userToken));
|
|
19
|
+
* await apiClient.post('/some/path', body, apiClient.authConfig(userToken));
|
|
20
|
+
*/
|
|
21
|
+
authConfig(token: string | undefined, extra?: AxiosRequestConfig): AxiosRequestConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Sanitize headers to hide sensitive information
|
|
24
|
+
*/
|
|
25
|
+
private sanitizeHeaders;
|
|
26
|
+
/**
|
|
27
|
+
* Execute request with retry logic
|
|
28
|
+
*/
|
|
29
|
+
private executeWithRetry;
|
|
30
|
+
/**
|
|
31
|
+
* GET request
|
|
32
|
+
*/
|
|
33
|
+
get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* POST request
|
|
36
|
+
*/
|
|
37
|
+
post<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* PUT request
|
|
40
|
+
*/
|
|
41
|
+
put<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T>;
|
|
42
|
+
/**
|
|
43
|
+
* DELETE request
|
|
44
|
+
*/
|
|
45
|
+
delete<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Get subscription list
|
|
48
|
+
*
|
|
49
|
+
* @param params Query parameters for filtering subscriptions.
|
|
50
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
51
|
+
* When provided it overrides the server-level fallback token.
|
|
52
|
+
*/
|
|
53
|
+
getSubscriptions(params?: {
|
|
54
|
+
scope?: 'general' | 'team' | 'user' | 'all';
|
|
55
|
+
types?: string[];
|
|
56
|
+
detail?: boolean;
|
|
57
|
+
}, userToken?: string): Promise<{
|
|
58
|
+
total: number;
|
|
59
|
+
subscriptions: Array<{
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
type: string;
|
|
63
|
+
team: string;
|
|
64
|
+
subscribed_at: string;
|
|
65
|
+
auto_sync: boolean;
|
|
66
|
+
resource: {
|
|
67
|
+
version: string;
|
|
68
|
+
hash: string;
|
|
69
|
+
download_url: string;
|
|
70
|
+
};
|
|
71
|
+
}>;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to resource
|
|
75
|
+
*
|
|
76
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
77
|
+
*/
|
|
78
|
+
subscribe(resourceIds: string[], autoSync?: boolean, scope?: 'general' | 'team' | 'user', userToken?: string): Promise<{
|
|
79
|
+
success: boolean;
|
|
80
|
+
subscriptions: Array<{
|
|
81
|
+
id: string;
|
|
82
|
+
name: string;
|
|
83
|
+
type: string;
|
|
84
|
+
subscribed_at: string;
|
|
85
|
+
}>;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Unsubscribe from resource
|
|
89
|
+
*
|
|
90
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
91
|
+
*/
|
|
92
|
+
unsubscribe(resourceIds: string | string[], userToken?: string): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Search resources
|
|
95
|
+
*
|
|
96
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
97
|
+
*/
|
|
98
|
+
searchResources(params: {
|
|
99
|
+
keyword: string;
|
|
100
|
+
team?: string;
|
|
101
|
+
type?: string;
|
|
102
|
+
detail?: boolean;
|
|
103
|
+
page?: number;
|
|
104
|
+
page_size?: number;
|
|
105
|
+
}, userToken?: string): Promise<{
|
|
106
|
+
total: number;
|
|
107
|
+
page?: number;
|
|
108
|
+
page_size?: number;
|
|
109
|
+
results: Array<{
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
type: string;
|
|
113
|
+
team: string;
|
|
114
|
+
version: string;
|
|
115
|
+
description: string;
|
|
116
|
+
score: number;
|
|
117
|
+
is_subscribed: boolean;
|
|
118
|
+
metadata?: {
|
|
119
|
+
module: string;
|
|
120
|
+
tags: string[];
|
|
121
|
+
author: string;
|
|
122
|
+
created_at: string;
|
|
123
|
+
updated_at: string;
|
|
124
|
+
downloads: number;
|
|
125
|
+
};
|
|
126
|
+
}>;
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Download resource — returns all files for the resource.
|
|
130
|
+
*
|
|
131
|
+
* GET /csp/api/resources/download/{id}
|
|
132
|
+
* Response: { data: { resource_id, name, type, version, hash, files: [{path, content}] } }
|
|
133
|
+
*
|
|
134
|
+
* files[].path is the relative path within the resource directory.
|
|
135
|
+
* Single-file resources (command, rule) have exactly one element.
|
|
136
|
+
* Multi-file resources (skill, mcp) have all their files included.
|
|
137
|
+
*
|
|
138
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
139
|
+
*/
|
|
140
|
+
downloadResource(resourceId: string, userToken?: string): Promise<{
|
|
141
|
+
resource_id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
type: string;
|
|
144
|
+
version: string;
|
|
145
|
+
hash: string;
|
|
146
|
+
files: Array<{
|
|
147
|
+
path: string;
|
|
148
|
+
content: string;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Get full resource metadata including script files and content hash.
|
|
153
|
+
*
|
|
154
|
+
* This is the primary endpoint for hybrid sync — returns enhanced metadata
|
|
155
|
+
* with has_scripts, script_files array, and file permissions.
|
|
156
|
+
*
|
|
157
|
+
* Fallback: If the server hasn't implemented this endpoint yet, falls back
|
|
158
|
+
* to downloadResource() and infers has_scripts from file structure.
|
|
159
|
+
*
|
|
160
|
+
* GET /api/v1/resources/{id}/metadata
|
|
161
|
+
* Response: { data: { id, name, type, version, content, has_scripts, script_files, content_hash } }
|
|
162
|
+
*
|
|
163
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
164
|
+
*/
|
|
165
|
+
/**
|
|
166
|
+
* Get resource detail
|
|
167
|
+
*
|
|
168
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
169
|
+
*/
|
|
170
|
+
getResourceDetail(resourceId: string, userToken?: string): Promise<{
|
|
171
|
+
id: string;
|
|
172
|
+
name: string;
|
|
173
|
+
type: string;
|
|
174
|
+
team: string;
|
|
175
|
+
version: string;
|
|
176
|
+
description: string;
|
|
177
|
+
metadata: {
|
|
178
|
+
module: string;
|
|
179
|
+
tags: string[];
|
|
180
|
+
author: string;
|
|
181
|
+
created_at: string;
|
|
182
|
+
updated_at: string;
|
|
183
|
+
downloads: number;
|
|
184
|
+
file_size: number;
|
|
185
|
+
hash: string;
|
|
186
|
+
};
|
|
187
|
+
download_url: string;
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* Stage resource files for upload (Step 1 of two-step upload flow).
|
|
191
|
+
*
|
|
192
|
+
* POST /csp/api/resources/upload
|
|
193
|
+
* Body: { type, name, files: [{ path, content }] }
|
|
194
|
+
* Response: { upload_id, status, expires_at, preview_url }
|
|
195
|
+
*
|
|
196
|
+
* The server validates path traversal, total size (< 10 MB), and name conflicts.
|
|
197
|
+
* All file types are supported — mcp packages may include .py, .js, package.json, etc.
|
|
198
|
+
*
|
|
199
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
200
|
+
*/
|
|
201
|
+
uploadResourceFiles(params: {
|
|
202
|
+
type: string;
|
|
203
|
+
name: string;
|
|
204
|
+
files: Array<{
|
|
205
|
+
path: string;
|
|
206
|
+
content: string;
|
|
207
|
+
}>;
|
|
208
|
+
target_source?: string;
|
|
209
|
+
force?: boolean;
|
|
210
|
+
}, userToken?: string): Promise<{
|
|
211
|
+
upload_id: string;
|
|
212
|
+
status: string;
|
|
213
|
+
expires_at: string;
|
|
214
|
+
preview_url?: string;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Finalize staged upload — triggers Git commit (Step 2 of two-step upload flow).
|
|
218
|
+
*
|
|
219
|
+
* POST /csp/api/resources/finalize
|
|
220
|
+
* Body: { upload_id, commit_message }
|
|
221
|
+
* Response: { resource_id, version, url, commit_hash, download_url }
|
|
222
|
+
*
|
|
223
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
224
|
+
*/
|
|
225
|
+
finalizeResourceUpload(uploadId: string, commitMessage: string, userToken?: string): Promise<{
|
|
226
|
+
resource_id: string;
|
|
227
|
+
version?: string;
|
|
228
|
+
url?: string;
|
|
229
|
+
commit_hash?: string;
|
|
230
|
+
download_url?: string;
|
|
231
|
+
}>;
|
|
232
|
+
/**
|
|
233
|
+
* Report AI resource usage telemetry to the server.
|
|
234
|
+
*
|
|
235
|
+
* POST /csp/api/resources/telemetry
|
|
236
|
+
* Body: { client_version, reported_at, events[], subscribed_rules[], configured_mcps[] }
|
|
237
|
+
*
|
|
238
|
+
* Called by TelemetryManager.flush() every ~10 seconds and on reconnect.
|
|
239
|
+
* Throws on non-2xx so the caller can apply retry logic.
|
|
240
|
+
*
|
|
241
|
+
* jira_id in each event entry is optional — it is only present when the user
|
|
242
|
+
* explicitly passed a Jira ID during the Prompt invocation.
|
|
243
|
+
*
|
|
244
|
+
* @param payload Telemetry report payload built by TelemetryManager
|
|
245
|
+
* @param userToken Per-request Bearer token from the caller's mcp.json configuration
|
|
246
|
+
*/
|
|
247
|
+
reportTelemetry(payload: {
|
|
248
|
+
client_version: string;
|
|
249
|
+
reported_at: string;
|
|
250
|
+
events: Array<{
|
|
251
|
+
resource_id: string;
|
|
252
|
+
resource_type: string;
|
|
253
|
+
resource_name: string;
|
|
254
|
+
invocation_count: number;
|
|
255
|
+
first_invoked_at: string;
|
|
256
|
+
last_invoked_at: string;
|
|
257
|
+
/** Optional Jira Issue ID (e.g. "PROJ-12345"). Absent when not provided. */
|
|
258
|
+
jira_id?: string;
|
|
259
|
+
}>;
|
|
260
|
+
subscribed_rules: Array<{
|
|
261
|
+
resource_id: string;
|
|
262
|
+
resource_name: string;
|
|
263
|
+
subscribed_at: string;
|
|
264
|
+
}>;
|
|
265
|
+
configured_mcps: Array<{
|
|
266
|
+
resource_id: string;
|
|
267
|
+
resource_name: string;
|
|
268
|
+
configured_at: string;
|
|
269
|
+
}>;
|
|
270
|
+
}, userToken: string): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* @deprecated Use uploadResourceFiles() + finalizeResourceUpload() instead.
|
|
273
|
+
*/
|
|
274
|
+
uploadResource(params: {
|
|
275
|
+
name: string;
|
|
276
|
+
type: string;
|
|
277
|
+
team: string;
|
|
278
|
+
description?: string;
|
|
279
|
+
tags?: string[];
|
|
280
|
+
}): Promise<{
|
|
281
|
+
upload_id: string;
|
|
282
|
+
upload_url: string;
|
|
283
|
+
expires_at: string;
|
|
284
|
+
}>;
|
|
285
|
+
/**
|
|
286
|
+
* @deprecated Use finalizeResourceUpload() instead.
|
|
287
|
+
*/
|
|
288
|
+
finalizeUpload(uploadId: string, hash: string): Promise<{
|
|
289
|
+
resource_id: string;
|
|
290
|
+
status: string;
|
|
291
|
+
}>;
|
|
292
|
+
}
|
|
293
|
+
export declare const apiClient: APIClient;
|
|
294
|
+
export {};
|
|
295
|
+
//# sourceMappingURL=client.d.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D,eAAO,MAAM,SAAS,WAAkB,CAAC"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* REST API Client
|
|
4
|
+
* HTTP client for CSP Resource Server
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.apiClient = void 0;
|
|
41
|
+
const axios_1 = __importStar(require("axios"));
|
|
42
|
+
const config_1 = require("../config");
|
|
43
|
+
const logger_1 = require("../utils/logger");
|
|
44
|
+
const errors_1 = require("../types/errors");
|
|
45
|
+
class APIClient {
|
|
46
|
+
client;
|
|
47
|
+
maxRetries = 3;
|
|
48
|
+
retryDelay = 1000; // 1 second
|
|
49
|
+
constructor() {
|
|
50
|
+
this.client = axios_1.default.create({
|
|
51
|
+
baseURL: config_1.config.csp.apiBaseUrl,
|
|
52
|
+
timeout: config_1.config.csp.timeout,
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
'User-Agent': `csp-ai-agent-mcp/0.2.0`,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
// Request interceptor for authentication and logging.
|
|
59
|
+
// Every request MUST carry a per-request Authorization header supplied by
|
|
60
|
+
// the caller via authConfig(userToken). If none is present the request is
|
|
61
|
+
// rejected immediately — the token must come from the authenticated SSE
|
|
62
|
+
// connection, not from environment variables.
|
|
63
|
+
this.client.interceptors.request.use((requestConfig) => {
|
|
64
|
+
if (!requestConfig.headers.Authorization) {
|
|
65
|
+
return Promise.reject(new Error('Authorization token is missing. ' +
|
|
66
|
+
'Ensure the MCP server is connected via SSE with a valid Bearer token in the Authorization header.'));
|
|
67
|
+
}
|
|
68
|
+
// Enhanced request logging
|
|
69
|
+
logger_1.logger.debug({
|
|
70
|
+
type: 'api_request_start',
|
|
71
|
+
method: requestConfig.method?.toUpperCase(),
|
|
72
|
+
url: requestConfig.url,
|
|
73
|
+
params: requestConfig.params,
|
|
74
|
+
data: requestConfig.data ? JSON.stringify(requestConfig.data).substring(0, 500) : undefined,
|
|
75
|
+
headers: this.sanitizeHeaders(requestConfig.headers),
|
|
76
|
+
}, `API Request: ${requestConfig.method?.toUpperCase()} ${requestConfig.url}`);
|
|
77
|
+
// Record start time for duration calculation
|
|
78
|
+
requestConfig.startTime = Date.now();
|
|
79
|
+
return requestConfig;
|
|
80
|
+
}, (error) => {
|
|
81
|
+
logger_1.logger.error({
|
|
82
|
+
type: 'api_request_interceptor_error',
|
|
83
|
+
error: error.message
|
|
84
|
+
}, 'API request interceptor error');
|
|
85
|
+
return Promise.reject(error);
|
|
86
|
+
});
|
|
87
|
+
// Response interceptor for detailed logging
|
|
88
|
+
this.client.interceptors.response.use((response) => {
|
|
89
|
+
const startTime = response.config.startTime || Date.now();
|
|
90
|
+
const duration = Date.now() - startTime;
|
|
91
|
+
const method = response.config.method?.toUpperCase() || 'UNKNOWN';
|
|
92
|
+
const url = response.config.url || 'unknown';
|
|
93
|
+
// Enhanced response logging
|
|
94
|
+
(0, logger_1.logApiRequest)(method, url, response.status, duration, response.config.data, response.data, response.headers);
|
|
95
|
+
return response;
|
|
96
|
+
}, (error) => {
|
|
97
|
+
const startTime = error.config?.startTime || Date.now();
|
|
98
|
+
const duration = Date.now() - startTime;
|
|
99
|
+
const statusCode = error.response?.status;
|
|
100
|
+
const method = error.config?.method?.toUpperCase() || 'UNKNOWN';
|
|
101
|
+
const url = error.config?.url || 'unknown';
|
|
102
|
+
// Enhanced error logging
|
|
103
|
+
(0, logger_1.logApiError)(method, url, error, error.config?.data, statusCode);
|
|
104
|
+
// Log response details if available
|
|
105
|
+
if (error.response) {
|
|
106
|
+
logger_1.logger.error({
|
|
107
|
+
type: 'api_response_error',
|
|
108
|
+
method,
|
|
109
|
+
url,
|
|
110
|
+
status: statusCode,
|
|
111
|
+
statusText: error.response.statusText,
|
|
112
|
+
responseData: error.response.data ? JSON.stringify(error.response.data).substring(0, 1000) : undefined,
|
|
113
|
+
duration,
|
|
114
|
+
}, `API Error Response: ${method} ${url} - ${statusCode}`);
|
|
115
|
+
}
|
|
116
|
+
return Promise.reject(error);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Build an AxiosRequestConfig that carries a per-request user token.
|
|
121
|
+
* Pass the result as the `config` argument to get/post/put/delete or merge it
|
|
122
|
+
* into any existing request config so that the caller's token overrides the
|
|
123
|
+
* server-level fallback set in the interceptor.
|
|
124
|
+
*
|
|
125
|
+
* Usage:
|
|
126
|
+
* await apiClient.get('/some/path', apiClient.authConfig(userToken));
|
|
127
|
+
* await apiClient.post('/some/path', body, apiClient.authConfig(userToken));
|
|
128
|
+
*/
|
|
129
|
+
authConfig(token, extra) {
|
|
130
|
+
if (!token)
|
|
131
|
+
return extra ?? {};
|
|
132
|
+
return {
|
|
133
|
+
...extra,
|
|
134
|
+
headers: {
|
|
135
|
+
...(extra?.headers ?? {}),
|
|
136
|
+
Authorization: `Bearer ${token}`,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Sanitize headers to hide sensitive information
|
|
142
|
+
*/
|
|
143
|
+
sanitizeHeaders(headers) {
|
|
144
|
+
const sanitized = { ...headers };
|
|
145
|
+
if (sanitized['Authorization'] || sanitized['authorization']) {
|
|
146
|
+
const key = sanitized['Authorization'] ? 'Authorization' : 'authorization';
|
|
147
|
+
const value = sanitized[key];
|
|
148
|
+
if (value && value.startsWith('Bearer ')) {
|
|
149
|
+
const token = value.substring(7);
|
|
150
|
+
sanitized[key] = `Bearer ${token.substring(0, 10)}...${token.substring(token.length - 10)}`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return sanitized;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Execute request with retry logic
|
|
157
|
+
*/
|
|
158
|
+
async executeWithRetry(requestFn, method, url, retryCount = 0) {
|
|
159
|
+
try {
|
|
160
|
+
return await requestFn();
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const isNetworkError = error instanceof axios_1.AxiosError &&
|
|
164
|
+
(!error.response || error.code === 'ECONNREFUSED' || error.code === 'ETIMEDOUT');
|
|
165
|
+
if (isNetworkError && retryCount < this.maxRetries) {
|
|
166
|
+
const delay = this.retryDelay * Math.pow(2, retryCount);
|
|
167
|
+
logger_1.logger.warn({
|
|
168
|
+
method,
|
|
169
|
+
url,
|
|
170
|
+
retryCount: retryCount + 1,
|
|
171
|
+
maxRetries: this.maxRetries,
|
|
172
|
+
delay,
|
|
173
|
+
}, `API request failed, retrying in ${delay}ms...`);
|
|
174
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
175
|
+
return this.executeWithRetry(requestFn, method, url, retryCount + 1);
|
|
176
|
+
}
|
|
177
|
+
// Transform axios error to APIError
|
|
178
|
+
if (error instanceof axios_1.AxiosError) {
|
|
179
|
+
throw (0, errors_1.createAPIError)(method, url, error, error.response?.status, retryCount);
|
|
180
|
+
}
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* GET request
|
|
186
|
+
*/
|
|
187
|
+
async get(url, config) {
|
|
188
|
+
return this.executeWithRetry(async () => {
|
|
189
|
+
const response = await this.client.get(url, config);
|
|
190
|
+
return response.data;
|
|
191
|
+
}, 'GET', url);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* POST request
|
|
195
|
+
*/
|
|
196
|
+
async post(url, data, config) {
|
|
197
|
+
return this.executeWithRetry(async () => {
|
|
198
|
+
const response = await this.client.post(url, data, config);
|
|
199
|
+
return response.data;
|
|
200
|
+
}, 'POST', url);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* PUT request
|
|
204
|
+
*/
|
|
205
|
+
async put(url, data, config) {
|
|
206
|
+
return this.executeWithRetry(async () => {
|
|
207
|
+
const response = await this.client.put(url, data, config);
|
|
208
|
+
return response.data;
|
|
209
|
+
}, 'PUT', url);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* DELETE request
|
|
213
|
+
*/
|
|
214
|
+
async delete(url, config) {
|
|
215
|
+
return this.executeWithRetry(async () => {
|
|
216
|
+
const response = await this.client.delete(url, config);
|
|
217
|
+
return response.data;
|
|
218
|
+
}, 'DELETE', url);
|
|
219
|
+
}
|
|
220
|
+
//===========================================
|
|
221
|
+
// CSP Resource Server API Endpoints
|
|
222
|
+
//===========================================
|
|
223
|
+
/**
|
|
224
|
+
* Get subscription list
|
|
225
|
+
*
|
|
226
|
+
* @param params Query parameters for filtering subscriptions.
|
|
227
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
228
|
+
* When provided it overrides the server-level fallback token.
|
|
229
|
+
*/
|
|
230
|
+
async getSubscriptions(params, userToken) {
|
|
231
|
+
const response = await this.get('/csp/api/resources/subscriptions', this.authConfig(userToken, { params }));
|
|
232
|
+
if (!response.data) {
|
|
233
|
+
throw new Error('Invalid API response: missing data field');
|
|
234
|
+
}
|
|
235
|
+
return response.data;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Subscribe to resource
|
|
239
|
+
*
|
|
240
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
241
|
+
*/
|
|
242
|
+
async subscribe(resourceIds, autoSync = true, scope, userToken) {
|
|
243
|
+
const response = await this.post('/csp/api/resources/subscriptions/add', { resource_ids: resourceIds, auto_sync: autoSync, scope }, this.authConfig(userToken));
|
|
244
|
+
if (!response.data) {
|
|
245
|
+
throw new Error('Invalid API response: missing data field');
|
|
246
|
+
}
|
|
247
|
+
return { success: true, subscriptions: response.data.subscriptions };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Unsubscribe from resource
|
|
251
|
+
*
|
|
252
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
253
|
+
*/
|
|
254
|
+
async unsubscribe(resourceIds, userToken) {
|
|
255
|
+
const ids = Array.isArray(resourceIds) ? resourceIds : [resourceIds];
|
|
256
|
+
const response = await this.delete('/csp/api/resources/subscriptions/remove', this.authConfig(userToken, { data: { resource_ids: ids } }));
|
|
257
|
+
if (!response.data) {
|
|
258
|
+
throw new Error('Invalid API response: missing data field');
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Search resources
|
|
263
|
+
*
|
|
264
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
265
|
+
*/
|
|
266
|
+
async searchResources(params, userToken) {
|
|
267
|
+
const response = await this.get('/csp/api/resources/search', this.authConfig(userToken, { params }));
|
|
268
|
+
if (!response.data) {
|
|
269
|
+
throw new Error('Invalid API response: missing data field');
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
total: response.data.total,
|
|
273
|
+
page: response.data.page,
|
|
274
|
+
page_size: response.data.page_size,
|
|
275
|
+
results: response.data.results.map((r) => ({
|
|
276
|
+
...r,
|
|
277
|
+
score: r.score || 0,
|
|
278
|
+
is_subscribed: r.is_subscribed || false,
|
|
279
|
+
})),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Download resource — returns all files for the resource.
|
|
284
|
+
*
|
|
285
|
+
* GET /csp/api/resources/download/{id}
|
|
286
|
+
* Response: { data: { resource_id, name, type, version, hash, files: [{path, content}] } }
|
|
287
|
+
*
|
|
288
|
+
* files[].path is the relative path within the resource directory.
|
|
289
|
+
* Single-file resources (command, rule) have exactly one element.
|
|
290
|
+
* Multi-file resources (skill, mcp) have all their files included.
|
|
291
|
+
*
|
|
292
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
293
|
+
*/
|
|
294
|
+
async downloadResource(resourceId, userToken) {
|
|
295
|
+
const response = await this.get(`/csp/api/resources/download/${resourceId}`, this.authConfig(userToken));
|
|
296
|
+
return response.data;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Get full resource metadata including script files and content hash.
|
|
300
|
+
*
|
|
301
|
+
* This is the primary endpoint for hybrid sync — returns enhanced metadata
|
|
302
|
+
* with has_scripts, script_files array, and file permissions.
|
|
303
|
+
*
|
|
304
|
+
* Fallback: If the server hasn't implemented this endpoint yet, falls back
|
|
305
|
+
* to downloadResource() and infers has_scripts from file structure.
|
|
306
|
+
*
|
|
307
|
+
* GET /api/v1/resources/{id}/metadata
|
|
308
|
+
* Response: { data: { id, name, type, version, content, has_scripts, script_files, content_hash } }
|
|
309
|
+
*
|
|
310
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
311
|
+
*/
|
|
312
|
+
/**
|
|
313
|
+
* Get resource detail
|
|
314
|
+
*
|
|
315
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
316
|
+
*/
|
|
317
|
+
async getResourceDetail(resourceId, userToken) {
|
|
318
|
+
return this.get(`/csp/api/resources/${resourceId}`, this.authConfig(userToken));
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Stage resource files for upload (Step 1 of two-step upload flow).
|
|
322
|
+
*
|
|
323
|
+
* POST /csp/api/resources/upload
|
|
324
|
+
* Body: { type, name, files: [{ path, content }] }
|
|
325
|
+
* Response: { upload_id, status, expires_at, preview_url }
|
|
326
|
+
*
|
|
327
|
+
* The server validates path traversal, total size (< 10 MB), and name conflicts.
|
|
328
|
+
* All file types are supported — mcp packages may include .py, .js, package.json, etc.
|
|
329
|
+
*
|
|
330
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
331
|
+
*/
|
|
332
|
+
async uploadResourceFiles(params, userToken) {
|
|
333
|
+
const resp = await this.post('/csp/api/resources/upload', params, this.authConfig(userToken));
|
|
334
|
+
return resp.data;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Finalize staged upload — triggers Git commit (Step 2 of two-step upload flow).
|
|
338
|
+
*
|
|
339
|
+
* POST /csp/api/resources/finalize
|
|
340
|
+
* Body: { upload_id, commit_message }
|
|
341
|
+
* Response: { resource_id, version, url, commit_hash, download_url }
|
|
342
|
+
*
|
|
343
|
+
* @param userToken Per-request token from the caller's mcp.json configuration.
|
|
344
|
+
*/
|
|
345
|
+
async finalizeResourceUpload(uploadId, commitMessage, userToken) {
|
|
346
|
+
const resp = await this.post('/csp/api/resources/finalize', { upload_id: uploadId, commit_message: commitMessage }, this.authConfig(userToken));
|
|
347
|
+
return resp.data;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Report AI resource usage telemetry to the server.
|
|
351
|
+
*
|
|
352
|
+
* POST /csp/api/resources/telemetry
|
|
353
|
+
* Body: { client_version, reported_at, events[], subscribed_rules[], configured_mcps[] }
|
|
354
|
+
*
|
|
355
|
+
* Called by TelemetryManager.flush() every ~10 seconds and on reconnect.
|
|
356
|
+
* Throws on non-2xx so the caller can apply retry logic.
|
|
357
|
+
*
|
|
358
|
+
* jira_id in each event entry is optional — it is only present when the user
|
|
359
|
+
* explicitly passed a Jira ID during the Prompt invocation.
|
|
360
|
+
*
|
|
361
|
+
* @param payload Telemetry report payload built by TelemetryManager
|
|
362
|
+
* @param userToken Per-request Bearer token from the caller's mcp.json configuration
|
|
363
|
+
*/
|
|
364
|
+
async reportTelemetry(payload, userToken) {
|
|
365
|
+
await this.post('/csp/api/resources/telemetry', payload, this.authConfig(userToken));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* @deprecated Use uploadResourceFiles() + finalizeResourceUpload() instead.
|
|
369
|
+
*/
|
|
370
|
+
async uploadResource(params) {
|
|
371
|
+
return this.post('/csp/api/resources/upload', params);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @deprecated Use finalizeResourceUpload() instead.
|
|
375
|
+
*/
|
|
376
|
+
async finalizeUpload(uploadId, hash) {
|
|
377
|
+
return this.post('/csp/api/resources/finalize', {
|
|
378
|
+
upload_id: uploadId,
|
|
379
|
+
hash,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// Export singleton instance
|
|
384
|
+
exports.apiClient = new APIClient();
|
|
385
|
+
//# sourceMappingURL=client.js.map
|