@elliotding/ai-agent-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +213 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +326 -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 +256 -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 +217 -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 +54 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +168 -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 +62 -0
- package/dist/git/multi-source-manager.d.ts.map +1 -0
- package/dist/git/multi-source-manager.js +293 -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 +109 -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/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 +87 -0
- package/dist/resources/loader.d.ts.map +1 -0
- package/dist/resources/loader.js +452 -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 +336 -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 +157 -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/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +27 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/manage-subscription.d.ts +43 -0
- package/dist/tools/manage-subscription.d.ts.map +1 -0
- package/dist/tools/manage-subscription.js +268 -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/search-resources.d.ts +31 -0
- package/dist/tools/search-resources.d.ts.map +1 -0
- package/dist/tools/search-resources.js +154 -0
- package/dist/tools/search-resources.js.map +1 -0
- package/dist/tools/sync-resources.d.ts +41 -0
- package/dist/tools/sync-resources.d.ts.map +1 -0
- package/dist/tools/sync-resources.js +606 -0
- package/dist/tools/sync-resources.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 +259 -0
- package/dist/tools/uninstall-resource.js.map +1 -0
- package/dist/tools/upload-resource.d.ts +77 -0
- package/dist/tools/upload-resource.d.ts.map +1 -0
- package/dist/tools/upload-resource.js +252 -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 +147 -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 +49 -0
- package/dist/utils/cursor-paths.d.ts.map +1 -0
- package/dist/utils/cursor-paths.js +116 -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 +58 -0
- package/src/api/cached-client.ts +144 -0
- package/src/api/client.ts +578 -0
- package/src/auth/index.ts +11 -0
- package/src/auth/middleware.ts +244 -0
- package/src/auth/permissions.ts +317 -0
- package/src/auth/token-validator.ts +294 -0
- package/src/cache/cache-manager.ts +243 -0
- package/src/cache/index.ts +6 -0
- package/src/cache/redis-client.ts +249 -0
- package/src/config/constants.ts +33 -0
- package/src/config/index.ts +228 -0
- package/src/filesystem/manager.ts +235 -0
- package/src/git/multi-source-manager.ts +333 -0
- package/src/git/operations.ts +93 -0
- package/src/index.ts +139 -0
- package/src/monitoring/health.ts +132 -0
- package/src/resources/index.ts +13 -0
- package/src/resources/loader.ts +530 -0
- package/src/server/http.ts +427 -0
- package/src/server.ts +191 -0
- package/src/session/manager.ts +296 -0
- package/src/tools/index.ts +11 -0
- package/src/tools/manage-subscription.ts +332 -0
- package/src/tools/registry.ts +97 -0
- package/src/tools/search-resources.ts +177 -0
- package/src/tools/sync-resources.ts +662 -0
- package/src/tools/uninstall-resource.ts +248 -0
- package/src/tools/upload-resource.ts +258 -0
- package/src/transport/sse.ts +308 -0
- package/src/types/errors.ts +146 -0
- package/src/types/index.ts +7 -0
- package/src/types/mcp.ts +61 -0
- package/src/types/resources.ts +141 -0
- package/src/types/tools.ts +175 -0
- package/src/utils/cursor-paths.ts +83 -0
- package/src/utils/log-cleaner.ts +92 -0
- package/src/utils/logger.ts +333 -0
- package/src/utils/validation.ts +262 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* upload_resource Tool
|
|
4
|
+
*
|
|
5
|
+
* Uploads resource files to a CSP source repository via the two-step API:
|
|
6
|
+
* Step 1: POST /csp/api/resources/upload → returns upload_id (server-side staging)
|
|
7
|
+
* Step 2: POST /csp/api/resources/finalize → triggers Git commit, returns permanent resource_id
|
|
8
|
+
*
|
|
9
|
+
* The user selects files from anywhere on their local machine. The AI reads the file
|
|
10
|
+
* content and passes it directly in files[]. The MCP server forwards everything to the
|
|
11
|
+
* CSP API — no local path resolution or server-side filesystem access is needed.
|
|
12
|
+
*
|
|
13
|
+
* target_source is passed through to the CSP API as-is; the CSP server decides
|
|
14
|
+
* which Git repo to commit to based on that value.
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.uploadResourceTool = void 0;
|
|
51
|
+
exports.uploadResource = uploadResource;
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const logger_1 = require("../utils/logger");
|
|
54
|
+
const client_1 = require("../api/client");
|
|
55
|
+
const resources_1 = require("../resources");
|
|
56
|
+
const errors_1 = require("../types/errors");
|
|
57
|
+
/**
|
|
58
|
+
* Validate and return the files[] array.
|
|
59
|
+
* Each entry path must be a relative path with no traversal.
|
|
60
|
+
* For MCP resources, mcp-config.json must be present.
|
|
61
|
+
*/
|
|
62
|
+
function collectFiles(typedParams) {
|
|
63
|
+
if (!typedParams.files || typedParams.files.length === 0) {
|
|
64
|
+
throw (0, errors_1.createValidationError)('files', 'required', '"files" must be a non-empty array of {path, content} entries.');
|
|
65
|
+
}
|
|
66
|
+
for (const entry of typedParams.files) {
|
|
67
|
+
const norm = path.normalize(entry.path);
|
|
68
|
+
if (norm.startsWith('..') || path.isAbsolute(norm)) {
|
|
69
|
+
throw (0, errors_1.createValidationError)('files[].path', 'relative_path', `Path traversal or absolute path not allowed: "${entry.path}"`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// MCP resources must include mcp-config.json so the client can auto-register
|
|
73
|
+
// the server in ~/.cursor/mcp.json after sync_resources installs it.
|
|
74
|
+
if (typedParams.type === 'mcp') {
|
|
75
|
+
const hasMcpConfig = typedParams.files.some((f) => path.basename(f.path) === 'mcp-config.json');
|
|
76
|
+
if (!hasMcpConfig) {
|
|
77
|
+
throw (0, errors_1.createValidationError)('files', 'required', 'MCP resources must include a "mcp-config.json" file. ' +
|
|
78
|
+
'This file tells the client how to start the MCP server after installation. ' +
|
|
79
|
+
'Required format:\n' +
|
|
80
|
+
'{\n' +
|
|
81
|
+
' "name": "<server-name>",\n' +
|
|
82
|
+
' "command": "python3", // or "node", "uvx", etc.\n' +
|
|
83
|
+
' "args": ["<entry-file.py>"], // relative path resolved against install dir\n' +
|
|
84
|
+
' "env": { "ENV_VAR": "" } // optional; empty string = user must fill in\n' +
|
|
85
|
+
'}');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return typedParams.files;
|
|
89
|
+
}
|
|
90
|
+
async function uploadResource(params) {
|
|
91
|
+
const startTime = Date.now();
|
|
92
|
+
const typedParams = params;
|
|
93
|
+
logger_1.logger.info({ tool: 'upload_resource', params }, 'upload_resource called');
|
|
94
|
+
try {
|
|
95
|
+
const resourceType = typedParams.type;
|
|
96
|
+
const resourceId = typedParams.resource_id;
|
|
97
|
+
const resourceName = typedParams.name ?? resourceId; // API uses "name" field
|
|
98
|
+
const targetSource = typedParams.target_source ?? 'csp'; // default to "csp" repo
|
|
99
|
+
const force = typedParams.force || false;
|
|
100
|
+
logger_1.logger.info({ resourceId, resourceType, targetSource }, 'Upload target resolved');
|
|
101
|
+
// ========== Step 1: Duplicate-name check ==========
|
|
102
|
+
try {
|
|
103
|
+
if (!resources_1.resourceLoader.getStats()) {
|
|
104
|
+
await resources_1.resourceLoader.loadConfig();
|
|
105
|
+
await resources_1.resourceLoader.scanResources();
|
|
106
|
+
}
|
|
107
|
+
const existing = resources_1.resourceLoader.searchResourcesByName(resourceName, resourceType);
|
|
108
|
+
if (existing.length > 0 && !force) {
|
|
109
|
+
const conflictInfo = existing.map((r) => ({ name: r.name, type: r.type, source: r.source }));
|
|
110
|
+
logger_1.logger.warn({ resourceName, resourceType, conflictInfo }, 'Resource name conflict detected');
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
error: {
|
|
114
|
+
code: 'RESOURCE_NAME_CONFLICT',
|
|
115
|
+
message: `Resource "${resourceName}" already exists. Add "force": true to overwrite.\n` +
|
|
116
|
+
conflictInfo.map((c) => ` - ${c.name} (${c.type}, source: ${c.source})`).join('\n'),
|
|
117
|
+
details: conflictInfo,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
logger_1.logger.warn({ error: err.message }, 'Duplicate check failed, continuing upload');
|
|
124
|
+
}
|
|
125
|
+
// ========== Step 3: Validate commit message ==========
|
|
126
|
+
if (!typedParams.message || typeof typedParams.message !== 'string') {
|
|
127
|
+
throw (0, errors_1.createValidationError)('message', 'string', 'Commit message is required');
|
|
128
|
+
}
|
|
129
|
+
if (typedParams.message.length < 5 || typedParams.message.length > 200) {
|
|
130
|
+
throw (0, errors_1.createValidationError)('message', 'string', `Commit message must be 5-200 characters, got ${typedParams.message.length}`);
|
|
131
|
+
}
|
|
132
|
+
// ========== Step 4: Collect files ==========
|
|
133
|
+
const fileEntries = collectFiles(typedParams);
|
|
134
|
+
logger_1.logger.info({ resourceId, fileCount: fileEntries.length }, 'Files collected for upload');
|
|
135
|
+
// ========== Step 5: Call CSP API — upload (staging) ==========
|
|
136
|
+
logger_1.logger.info({ resourceName, resourceType, targetSource }, 'Calling CSP upload API...');
|
|
137
|
+
const uploadResp = await client_1.apiClient.uploadResourceFiles({
|
|
138
|
+
type: resourceType,
|
|
139
|
+
name: resourceName,
|
|
140
|
+
files: fileEntries,
|
|
141
|
+
target_source: targetSource,
|
|
142
|
+
force,
|
|
143
|
+
});
|
|
144
|
+
const uploadId = uploadResp.upload_id;
|
|
145
|
+
logger_1.logger.info({ uploadId, expiresAt: uploadResp.expires_at }, 'Upload staged successfully');
|
|
146
|
+
// ========== Step 6: Call CSP API — finalize (Git commit) ==========
|
|
147
|
+
logger_1.logger.info({ uploadId }, 'Calling CSP finalize API...');
|
|
148
|
+
const finalizeResp = await client_1.apiClient.finalizeResourceUpload(uploadId, typedParams.message);
|
|
149
|
+
const finalResourceId = finalizeResp.resource_id;
|
|
150
|
+
const version = finalizeResp.version ?? '1.0.0';
|
|
151
|
+
const resourceUrl = finalizeResp.url ?? '';
|
|
152
|
+
const commitHash = finalizeResp.commit_hash ?? '';
|
|
153
|
+
logger_1.logger.info({ finalResourceId, version, commitHash }, 'Upload finalized successfully');
|
|
154
|
+
const result = {
|
|
155
|
+
resource_id: finalResourceId,
|
|
156
|
+
version,
|
|
157
|
+
url: resourceUrl,
|
|
158
|
+
commit_hash: commitHash,
|
|
159
|
+
message: `Resource '${resourceName}' (${resourceType}) uploaded to source '${targetSource}' (v${version}). ${resourceUrl ? `URL: ${resourceUrl}` : ''}`.trim(),
|
|
160
|
+
};
|
|
161
|
+
const duration = Date.now() - startTime;
|
|
162
|
+
(0, logger_1.logToolCall)('upload_resource', 'user-id', params, duration);
|
|
163
|
+
logger_1.logger.info({ finalResourceId, version, source: targetSource, duration }, 'upload_resource completed');
|
|
164
|
+
return { success: true, data: result };
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
logger_1.logger.error({ error, resourceId: typedParams.resource_id }, 'upload_resource failed');
|
|
168
|
+
return {
|
|
169
|
+
success: false,
|
|
170
|
+
error: {
|
|
171
|
+
code: error instanceof errors_1.MCPServerError ? error.code : 'UNKNOWN_ERROR',
|
|
172
|
+
message: error instanceof Error ? error.message : String(error),
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Tool definition for registry
|
|
178
|
+
exports.uploadResourceTool = {
|
|
179
|
+
name: 'upload_resource',
|
|
180
|
+
description: 'Upload a new AI resource (command, skill, rule, or mcp) to a CSP source repository. ' +
|
|
181
|
+
'The user selects files from anywhere on their local machine — read each file and pass its content in files[]. ' +
|
|
182
|
+
'ALWAYS confirm two things with the user before uploading: ' +
|
|
183
|
+
'(1) the resource type (command/skill/rule/mcp), and ' +
|
|
184
|
+
'(2) the target source repo (e.g. "csp" (default) or "client-sdk-ai-hub"). ' +
|
|
185
|
+
'The tool uses a two-step CSP API: first stages files and gets an upload_id, then finalizes the Git commit. ' +
|
|
186
|
+
'Pass files[] — an array of {path, content} entries. ' +
|
|
187
|
+
'path is the filename the resource should be stored as (e.g. "csp-ai-agent.mdc", "SKILL.md"). ' +
|
|
188
|
+
'Single-file upload: one entry in files[]. Multi-file upload: multiple entries. ' +
|
|
189
|
+
'No restriction on file extensions — mcp packages may include .py, .js, package.json, etc.',
|
|
190
|
+
inputSchema: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
resource_id: {
|
|
194
|
+
type: 'string',
|
|
195
|
+
description: 'Unique resource identifier used as commit label and for duplicate detection',
|
|
196
|
+
},
|
|
197
|
+
name: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
description: 'Human-readable resource name sent to the CSP API (defaults to resource_id if omitted)',
|
|
200
|
+
},
|
|
201
|
+
type: {
|
|
202
|
+
type: 'string',
|
|
203
|
+
enum: ['command', 'skill', 'rule', 'mcp'],
|
|
204
|
+
description: 'Resource category — MUST be confirmed with the user. ' +
|
|
205
|
+
'command: single .md slash-command file; ' +
|
|
206
|
+
'skill: directory with SKILL.md + supporting files; ' +
|
|
207
|
+
'rule: single .mdc Cursor rule file; ' +
|
|
208
|
+
'mcp: MCP server package — MUST include mcp-config.json (defines command/args/env for auto-registration into ~/.cursor/mcp.json).',
|
|
209
|
+
},
|
|
210
|
+
message: {
|
|
211
|
+
type: 'string',
|
|
212
|
+
description: 'Git commit message (5-200 characters)',
|
|
213
|
+
},
|
|
214
|
+
target_source: {
|
|
215
|
+
type: 'string',
|
|
216
|
+
description: 'Target source repo name on the CSP server. ' +
|
|
217
|
+
'Ask the user which repo to target. Typical values: "csp" (default), "client-sdk-ai-hub". ' +
|
|
218
|
+
'The CSP server will commit the resource to the corresponding Git repo.',
|
|
219
|
+
},
|
|
220
|
+
files: {
|
|
221
|
+
type: 'array',
|
|
222
|
+
description: 'List of files to upload. Read each file from the user\'s local machine and pass content here. ' +
|
|
223
|
+
'path is the filename the resource should be stored as on the server. ' +
|
|
224
|
+
'Examples (type="rule"): [{path: "csp-ai-agent.mdc", content: "..."}]. ' +
|
|
225
|
+
'Examples (type="skill"): [{path: "SKILL.md", content: "..."}, {path: "examples.md", content: "..."}]. ' +
|
|
226
|
+
'Examples (type="mcp"): [{path: "server.py", content: "..."}, {path: "mcp-config.json", content: "..."}]. ' +
|
|
227
|
+
'No restriction on file extension.',
|
|
228
|
+
items: {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
path: { type: 'string', description: 'Relative path under the type subdirectory' },
|
|
232
|
+
content: { type: 'string', description: 'Full text content of the file' },
|
|
233
|
+
},
|
|
234
|
+
required: ['path', 'content'],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
team: {
|
|
238
|
+
type: 'string',
|
|
239
|
+
description: 'Team / group name (defaults to Client-Public)',
|
|
240
|
+
default: 'Client-Public',
|
|
241
|
+
},
|
|
242
|
+
force: {
|
|
243
|
+
type: 'boolean',
|
|
244
|
+
description: 'Overwrite if a resource with the same name already exists',
|
|
245
|
+
default: false,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
required: ['resource_id', 'type', 'message', 'files'],
|
|
249
|
+
},
|
|
250
|
+
handler: uploadResource,
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=upload-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-resource.js","sourceRoot":"","sources":["../../src/tools/upload-resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;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 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE Transport Implementation
|
|
3
|
+
* MCP protocol over Server-Sent Events
|
|
4
|
+
*/
|
|
5
|
+
export interface SSEMessage {
|
|
6
|
+
jsonrpc: '2.0';
|
|
7
|
+
id?: string | number;
|
|
8
|
+
method?: string;
|
|
9
|
+
params?: unknown;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export declare class SSETransport {
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Handle incoming message from client
|
|
21
|
+
*/
|
|
22
|
+
handleMessage(sessionId: string, message: SSEMessage): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Send message to client via SSE
|
|
25
|
+
*/
|
|
26
|
+
private sendMessage;
|
|
27
|
+
}
|
|
28
|
+
export declare const sseTransport: SSETransport;
|
|
29
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/transport/sse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,OAAO,CAAC;KAChB,CAAC;CACH;AAED,qBAAa,YAAY;;IAKvB;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAwQ1E;;OAEG;IACH,OAAO,CAAC,WAAW;CAMpB;AAGD,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SSE Transport Implementation
|
|
4
|
+
* MCP protocol over Server-Sent Events
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.sseTransport = exports.SSETransport = void 0;
|
|
8
|
+
const logger_1 = require("../utils/logger");
|
|
9
|
+
const manager_1 = require("../session/manager");
|
|
10
|
+
const registry_1 = require("../tools/registry");
|
|
11
|
+
const middleware_1 = require("../auth/middleware");
|
|
12
|
+
class SSETransport {
|
|
13
|
+
constructor() {
|
|
14
|
+
logger_1.logger.info('SSE transport initialized');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Handle incoming message from client
|
|
18
|
+
*/
|
|
19
|
+
async handleMessage(sessionId, message) {
|
|
20
|
+
const messageStartTime = Date.now();
|
|
21
|
+
logger_1.logger.info({
|
|
22
|
+
type: 'sse_message_received',
|
|
23
|
+
sessionId,
|
|
24
|
+
method: message.method,
|
|
25
|
+
messageId: message.id,
|
|
26
|
+
hasParams: !!message.params,
|
|
27
|
+
timestamp: new Date().toISOString()
|
|
28
|
+
}, `SSE message received: ${message.method}`);
|
|
29
|
+
try {
|
|
30
|
+
// Validate session
|
|
31
|
+
(0, logger_1.logToolStep)('sse', 'Validating session', { sessionId });
|
|
32
|
+
const session = manager_1.sessionManager.getSession(sessionId);
|
|
33
|
+
if (!session) {
|
|
34
|
+
logger_1.logger.error({
|
|
35
|
+
type: 'sse_error',
|
|
36
|
+
sessionId,
|
|
37
|
+
method: message.method,
|
|
38
|
+
error: 'session_not_found',
|
|
39
|
+
timestamp: new Date().toISOString()
|
|
40
|
+
}, 'Session not found or expired');
|
|
41
|
+
throw new Error('Session not found or expired');
|
|
42
|
+
}
|
|
43
|
+
logger_1.logger.debug({
|
|
44
|
+
type: 'sse_session_validated',
|
|
45
|
+
sessionId,
|
|
46
|
+
userId: session.userId,
|
|
47
|
+
email: session.email,
|
|
48
|
+
groups: session.groups,
|
|
49
|
+
timestamp: new Date().toISOString()
|
|
50
|
+
}, 'Session validated');
|
|
51
|
+
// Update session activity
|
|
52
|
+
manager_1.sessionManager.updateActivity(sessionId);
|
|
53
|
+
(0, logger_1.logToolStep)('sse', 'Session activity updated', { sessionId });
|
|
54
|
+
// Handle MCP message
|
|
55
|
+
if (message.method === 'tools/list') {
|
|
56
|
+
(0, logger_1.logToolStep)('sse', 'Handling tools/list request', { sessionId });
|
|
57
|
+
const tools = registry_1.toolRegistry.getMCPToolDefinitions();
|
|
58
|
+
logger_1.logger.info({
|
|
59
|
+
type: 'sse_tools_list',
|
|
60
|
+
sessionId,
|
|
61
|
+
toolCount: tools.length,
|
|
62
|
+
toolNames: tools.map(t => t.name),
|
|
63
|
+
timestamp: new Date().toISOString()
|
|
64
|
+
}, `Returning ${tools.length} tool definitions`);
|
|
65
|
+
const response = {
|
|
66
|
+
jsonrpc: '2.0',
|
|
67
|
+
id: message.id,
|
|
68
|
+
result: { tools },
|
|
69
|
+
};
|
|
70
|
+
this.sendMessage(sessionId, response);
|
|
71
|
+
}
|
|
72
|
+
else if (message.method === 'tools/call') {
|
|
73
|
+
const params = message.params;
|
|
74
|
+
const toolName = params.name;
|
|
75
|
+
const args = params.arguments || {};
|
|
76
|
+
logger_1.logger.info({
|
|
77
|
+
type: 'sse_tool_call',
|
|
78
|
+
sessionId,
|
|
79
|
+
toolName,
|
|
80
|
+
userId: session.userId,
|
|
81
|
+
email: session.email,
|
|
82
|
+
argsPreview: JSON.stringify(args).substring(0, 200),
|
|
83
|
+
timestamp: new Date().toISOString()
|
|
84
|
+
}, `Executing tool: ${toolName}`);
|
|
85
|
+
(0, logger_1.logToolStep)(toolName, 'Tool call initiated via SSE', {
|
|
86
|
+
sessionId,
|
|
87
|
+
userId: session.userId,
|
|
88
|
+
email: session.email
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
// Check permissions if user is authenticated
|
|
92
|
+
if (session.userId && session.groups && session.groups.length > 0) {
|
|
93
|
+
(0, logger_1.logToolStep)(toolName, 'Checking tool permissions', {
|
|
94
|
+
userId: session.userId,
|
|
95
|
+
email: session.email,
|
|
96
|
+
groups: session.groups
|
|
97
|
+
});
|
|
98
|
+
const permissionStartTime = Date.now();
|
|
99
|
+
const permissionCheck = (0, middleware_1.checkToolCallPermission)(toolName, {
|
|
100
|
+
userId: session.userId,
|
|
101
|
+
email: session.email,
|
|
102
|
+
groups: session.groups,
|
|
103
|
+
});
|
|
104
|
+
const permissionDuration = Date.now() - permissionStartTime;
|
|
105
|
+
if (!permissionCheck.allowed) {
|
|
106
|
+
logger_1.logger.warn({
|
|
107
|
+
type: 'sse_permission_denied',
|
|
108
|
+
sessionId,
|
|
109
|
+
userId: session.userId,
|
|
110
|
+
email: session.email,
|
|
111
|
+
groups: session.groups,
|
|
112
|
+
toolName,
|
|
113
|
+
reason: permissionCheck.reason,
|
|
114
|
+
duration: permissionDuration,
|
|
115
|
+
timestamp: new Date().toISOString()
|
|
116
|
+
}, `Tool call permission denied for ${toolName}`);
|
|
117
|
+
const errorResponse = {
|
|
118
|
+
jsonrpc: '2.0',
|
|
119
|
+
id: message.id,
|
|
120
|
+
error: {
|
|
121
|
+
code: -32600, // Invalid Request
|
|
122
|
+
message: permissionCheck.reason || 'Permission denied',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
this.sendMessage(sessionId, errorResponse);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
logger_1.logger.debug({
|
|
129
|
+
type: 'sse_permission_granted',
|
|
130
|
+
sessionId,
|
|
131
|
+
userId: session.userId,
|
|
132
|
+
toolName,
|
|
133
|
+
duration: permissionDuration,
|
|
134
|
+
timestamp: new Date().toISOString()
|
|
135
|
+
}, `Permission granted for ${toolName}`);
|
|
136
|
+
}
|
|
137
|
+
(0, logger_1.logToolStep)(toolName, 'Executing tool handler', { args });
|
|
138
|
+
const toolStartTime = Date.now();
|
|
139
|
+
const result = await registry_1.toolRegistry.callTool(toolName, args);
|
|
140
|
+
const toolDuration = Date.now() - toolStartTime;
|
|
141
|
+
// Log complete result
|
|
142
|
+
logger_1.logger.info({
|
|
143
|
+
type: 'sse_tool_success',
|
|
144
|
+
sessionId,
|
|
145
|
+
toolName,
|
|
146
|
+
userId: session.userId,
|
|
147
|
+
resultType: typeof result,
|
|
148
|
+
resultPreview: JSON.stringify(result).substring(0, 500),
|
|
149
|
+
duration: toolDuration,
|
|
150
|
+
timestamp: new Date().toISOString()
|
|
151
|
+
}, `Tool ${toolName} executed successfully`);
|
|
152
|
+
(0, logger_1.logToolStep)(toolName, 'Tool execution completed', {
|
|
153
|
+
duration: toolDuration,
|
|
154
|
+
resultSize: JSON.stringify(result).length
|
|
155
|
+
});
|
|
156
|
+
const response = {
|
|
157
|
+
jsonrpc: '2.0',
|
|
158
|
+
id: message.id,
|
|
159
|
+
result,
|
|
160
|
+
};
|
|
161
|
+
this.sendMessage(sessionId, response);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const toolDuration = Date.now() - messageStartTime;
|
|
165
|
+
logger_1.logger.error({
|
|
166
|
+
type: 'sse_tool_error',
|
|
167
|
+
sessionId,
|
|
168
|
+
toolName,
|
|
169
|
+
userId: session.userId,
|
|
170
|
+
error: error instanceof Error ? {
|
|
171
|
+
message: error.message,
|
|
172
|
+
stack: error.stack,
|
|
173
|
+
name: error.name
|
|
174
|
+
} : String(error),
|
|
175
|
+
duration: toolDuration,
|
|
176
|
+
timestamp: new Date().toISOString()
|
|
177
|
+
}, `Tool ${toolName} execution failed`);
|
|
178
|
+
const errorResponse = {
|
|
179
|
+
jsonrpc: '2.0',
|
|
180
|
+
id: message.id,
|
|
181
|
+
error: {
|
|
182
|
+
code: -32603,
|
|
183
|
+
message: error instanceof Error ? error.message : 'Tool execution failed',
|
|
184
|
+
data: error,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
this.sendMessage(sessionId, errorResponse);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (message.method === 'initialize') {
|
|
191
|
+
logger_1.logger.info({
|
|
192
|
+
type: 'sse_initialize',
|
|
193
|
+
sessionId,
|
|
194
|
+
timestamp: new Date().toISOString()
|
|
195
|
+
}, 'Client initialization request');
|
|
196
|
+
const response = {
|
|
197
|
+
jsonrpc: '2.0',
|
|
198
|
+
id: message.id,
|
|
199
|
+
result: {
|
|
200
|
+
protocolVersion: '2024-11-05',
|
|
201
|
+
capabilities: {
|
|
202
|
+
tools: {},
|
|
203
|
+
},
|
|
204
|
+
serverInfo: {
|
|
205
|
+
name: 'csp-ai-agent-mcp',
|
|
206
|
+
version: '0.2.0',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
this.sendMessage(sessionId, response);
|
|
211
|
+
}
|
|
212
|
+
else if (message.method === 'ping') {
|
|
213
|
+
// Keepalive ping
|
|
214
|
+
logger_1.logger.debug({
|
|
215
|
+
type: 'sse_ping',
|
|
216
|
+
sessionId,
|
|
217
|
+
timestamp: new Date().toISOString()
|
|
218
|
+
}, 'Keepalive ping received');
|
|
219
|
+
const response = {
|
|
220
|
+
jsonrpc: '2.0',
|
|
221
|
+
id: message.id,
|
|
222
|
+
result: { type: 'pong' },
|
|
223
|
+
};
|
|
224
|
+
this.sendMessage(sessionId, response);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// Unknown method
|
|
228
|
+
logger_1.logger.warn({
|
|
229
|
+
type: 'sse_unknown_method',
|
|
230
|
+
sessionId,
|
|
231
|
+
method: message.method,
|
|
232
|
+
timestamp: new Date().toISOString()
|
|
233
|
+
}, `Unknown method: ${message.method}`);
|
|
234
|
+
const errorResponse = {
|
|
235
|
+
jsonrpc: '2.0',
|
|
236
|
+
id: message.id,
|
|
237
|
+
error: {
|
|
238
|
+
code: -32601,
|
|
239
|
+
message: `Method not found: ${message.method}`,
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
this.sendMessage(sessionId, errorResponse);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
logger_1.logger.error({ error, sessionId }, 'Error handling message');
|
|
247
|
+
const errorResponse = {
|
|
248
|
+
jsonrpc: '2.0',
|
|
249
|
+
id: message.id,
|
|
250
|
+
error: {
|
|
251
|
+
code: -32603,
|
|
252
|
+
message: error instanceof Error ? error.message : 'Internal error',
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
this.sendMessage(sessionId, errorResponse);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Send message to client via SSE
|
|
260
|
+
*/
|
|
261
|
+
sendMessage(sessionId, message) {
|
|
262
|
+
const sent = manager_1.sessionManager.sendMessage(sessionId, message);
|
|
263
|
+
if (!sent) {
|
|
264
|
+
logger_1.logger.warn({ sessionId, messageId: message.id }, 'Failed to send message to client');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.SSETransport = SSETransport;
|
|
269
|
+
// Singleton instance
|
|
270
|
+
exports.sseTransport = new SSETransport();
|
|
271
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/transport/sse.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAsD;AACtD,gDAAoD;AACpD,gDAAiD;AACjD,mDAA6D;AAe7D,MAAa,YAAY;IACvB;QACE,eAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,OAAmB;QACxD,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEpC,eAAM,CAAC,IAAI,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AyRC;AAED,qBAAqB;AACR,QAAA,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error Types
|
|
3
|
+
* Typed errors for different failure scenarios
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base Error for MCP Server operations
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCPServerError extends Error {
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly details?: unknown | undefined;
|
|
11
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Git Operation Error
|
|
15
|
+
*/
|
|
16
|
+
export declare class GitError extends MCPServerError {
|
|
17
|
+
readonly operation: string;
|
|
18
|
+
readonly repositoryUrl?: string | undefined;
|
|
19
|
+
constructor(message: string, operation: string, repositoryUrl?: string | undefined, details?: unknown);
|
|
20
|
+
private redactCredentials;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* API Request Error
|
|
24
|
+
*/
|
|
25
|
+
export declare class APIError extends MCPServerError {
|
|
26
|
+
readonly statusCode?: number | undefined;
|
|
27
|
+
readonly method?: string | undefined;
|
|
28
|
+
readonly url?: string | undefined;
|
|
29
|
+
readonly retryCount?: number | undefined;
|
|
30
|
+
constructor(message: string, statusCode?: number | undefined, method?: string | undefined, url?: string | undefined, retryCount?: number | undefined, details?: unknown);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resource Validation Error
|
|
34
|
+
*/
|
|
35
|
+
export declare class ValidationError extends MCPServerError {
|
|
36
|
+
readonly filePath?: string | undefined;
|
|
37
|
+
readonly expectedFormat?: string | undefined;
|
|
38
|
+
readonly validationReason?: string | undefined;
|
|
39
|
+
constructor(message: string, filePath?: string | undefined, expectedFormat?: string | undefined, validationReason?: string | undefined, details?: unknown);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Filesystem Operation Error
|
|
43
|
+
*/
|
|
44
|
+
export declare class FileSystemError extends MCPServerError {
|
|
45
|
+
readonly operation: string;
|
|
46
|
+
readonly path?: string | undefined;
|
|
47
|
+
readonly systemErrorCode?: string | undefined;
|
|
48
|
+
readonly suggestedResolution?: string | undefined;
|
|
49
|
+
constructor(message: string, operation: string, path?: string | undefined, systemErrorCode?: string | undefined, suggestedResolution?: string | undefined, details?: unknown);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Error Factory Functions
|
|
53
|
+
*/
|
|
54
|
+
export declare function createGitError(operation: string, error: Error, repositoryUrl?: string): GitError;
|
|
55
|
+
export declare function createAPIError(method: string, url: string, error: Error, statusCode?: number, retryCount?: number): APIError;
|
|
56
|
+
export declare function createValidationError(filePath: string, expectedFormat: string, reason: string): ValidationError;
|
|
57
|
+
export declare function createFileSystemError(operation: string, path: string, error: Error & {
|
|
58
|
+
code?: string;
|
|
59
|
+
}, suggestedResolution?: string): FileSystemError;
|
|
60
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAGrB,IAAI,EAAE,MAAM;aACZ,OAAO,CAAC,EAAE,OAAO;gBAFjC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,YAAA;CAMpC;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAAc;aAGxB,SAAS,EAAE,MAAM;aACjB,aAAa,CAAC,EAAE,MAAM;gBAFtC,OAAO,EAAE,MAAM,EACC,SAAS,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,YAAA,EACtC,OAAO,CAAC,EAAE,OAAO;IAUnB,OAAO,CAAC,iBAAiB;CAG1B;AAED;;GAEG;AACH,qBAAa,QAAS,SAA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