sub-agents-mcp 0.13.1 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -534
- package/dist/agents/AgentManager.d.ts +0 -45
- package/dist/agents/AgentManager.d.ts.map +1 -1
- package/dist/agents/AgentManager.js +0 -52
- package/dist/agents/AgentManager.js.map +1 -1
- package/dist/config/ServerConfig.d.ts +0 -41
- package/dist/config/ServerConfig.d.ts.map +1 -1
- package/dist/config/ServerConfig.js +0 -52
- package/dist/config/ServerConfig.js.map +1 -1
- package/dist/execution/AgentExecutor.d.ts +3 -151
- package/dist/execution/AgentExecutor.d.ts.map +1 -1
- package/dist/execution/AgentExecutor.js +27 -103
- package/dist/execution/AgentExecutor.js.map +1 -1
- package/dist/execution/StreamProcessor.d.ts +1 -10
- package/dist/execution/StreamProcessor.d.ts.map +1 -1
- package/dist/execution/StreamProcessor.js +33 -10
- package/dist/execution/StreamProcessor.js.map +1 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +1 -1
- package/dist/resources/AgentResources.d.ts +0 -71
- package/dist/resources/AgentResources.d.ts.map +1 -1
- package/dist/resources/AgentResources.js +0 -68
- package/dist/resources/AgentResources.js.map +1 -1
- package/dist/server/McpServer.d.ts +0 -88
- package/dist/server/McpServer.d.ts.map +1 -1
- package/dist/server/McpServer.js +0 -98
- package/dist/server/McpServer.js.map +1 -1
- package/dist/session/SessionHistoryFormatter.d.ts +0 -29
- package/dist/session/SessionHistoryFormatter.d.ts.map +1 -1
- package/dist/session/SessionHistoryFormatter.js +1 -34
- package/dist/session/SessionHistoryFormatter.js.map +1 -1
- package/dist/session/SessionManager.d.ts +0 -142
- package/dist/session/SessionManager.d.ts.map +1 -1
- package/dist/session/SessionManager.js +0 -180
- package/dist/session/SessionManager.js.map +1 -1
- package/dist/tools/RunAgentTool.d.ts +0 -121
- package/dist/tools/RunAgentTool.d.ts.map +1 -1
- package/dist/tools/RunAgentTool.js +16 -168
- package/dist/tools/RunAgentTool.js.map +1 -1
- package/dist/types/AgentDefinition.d.ts +0 -25
- package/dist/types/AgentDefinition.d.ts.map +1 -1
- package/dist/types/ExecutionParams.d.ts +0 -24
- package/dist/types/ExecutionParams.d.ts.map +1 -1
- package/dist/types/SessionData.d.ts +0 -23
- package/dist/types/SessionData.d.ts.map +1 -1
- package/dist/utils/ErrorHandler.d.ts +0 -67
- package/dist/utils/ErrorHandler.d.ts.map +1 -1
- package/dist/utils/ErrorHandler.js +0 -59
- package/dist/utils/ErrorHandler.js.map +1 -1
- package/dist/utils/Logger.d.ts +0 -78
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +0 -75
- package/dist/utils/Logger.js.map +1 -1
- package/package.json +6 -9
|
@@ -1,60 +1,15 @@
|
|
|
1
1
|
import type { ServerConfig } from '../config/ServerConfig.js';
|
|
2
2
|
import type { AgentDefinition } from '../types/AgentDefinition.js';
|
|
3
|
-
/**
|
|
4
|
-
* AgentManager class for discovering, loading, parsing, and caching agent definitions.
|
|
5
|
-
*
|
|
6
|
-
* Provides automatic detection of .md/.txt files in configured directory,
|
|
7
|
-
* parsing of Claude Code sub-agent format, and efficient caching with
|
|
8
|
-
* file change detection.
|
|
9
|
-
*/
|
|
10
3
|
export declare class AgentManager {
|
|
11
4
|
private config;
|
|
12
5
|
private logger;
|
|
13
6
|
constructor(config: ServerConfig);
|
|
14
|
-
/**
|
|
15
|
-
* Retrieves a specific agent definition by name.
|
|
16
|
-
*
|
|
17
|
-
* @param name - The name of the agent to retrieve
|
|
18
|
-
* @returns Promise resolving to the agent definition or undefined if not found
|
|
19
|
-
* @throws {Error} When agent name is invalid
|
|
20
|
-
*/
|
|
21
7
|
getAgent(name: string): Promise<AgentDefinition | undefined>;
|
|
22
|
-
/**
|
|
23
|
-
* Lists all available agent definitions.
|
|
24
|
-
*
|
|
25
|
-
* @returns Promise resolving to an array of all agent definitions
|
|
26
|
-
*/
|
|
27
8
|
listAgents(): Promise<AgentDefinition[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Refreshes the agents by re-scanning the agents directory.
|
|
30
|
-
* Forces reload of all agent definitions from disk.
|
|
31
|
-
*
|
|
32
|
-
* @returns Promise resolving when refresh is complete
|
|
33
|
-
*/
|
|
34
9
|
refreshAgents(): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Loads all agent definitions from the configured directory.
|
|
37
|
-
* Scans for .md and .txt files and parses them as agent definitions.
|
|
38
|
-
*
|
|
39
|
-
* @returns Map of agent name to agent definition
|
|
40
|
-
*/
|
|
41
10
|
private loadAgentsFromDirectory;
|
|
42
|
-
/**
|
|
43
|
-
* Loads and parses a single agent definition from a file.
|
|
44
|
-
*
|
|
45
|
-
* @param resolvedFilePath - Validated real path used for reading the definition
|
|
46
|
-
* @param agentName - Agent name derived from the discovered directory entry
|
|
47
|
-
* @returns Promise resolving to the parsed agent definition or undefined
|
|
48
|
-
*/
|
|
49
11
|
private loadAgentFromFile;
|
|
50
12
|
private isWithinDirectory;
|
|
51
|
-
/**
|
|
52
|
-
* Extracts description from agent file content.
|
|
53
|
-
* Looks for first heading or first line as description.
|
|
54
|
-
*
|
|
55
|
-
* @param content - The file content to parse
|
|
56
|
-
* @returns Extracted description or default message
|
|
57
|
-
*/
|
|
58
13
|
private extractDescription;
|
|
59
14
|
}
|
|
60
15
|
//# sourceMappingURL=AgentManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE
|
|
1
|
+
{"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAGlE,qBAAa,YAAY;IAGX,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,MAAM,CAAQ;gBAEF,MAAM,EAAE,YAAY;IAIlC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAiC5D,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAKxC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;YAItB,uBAAuB;YAuFvB,iBAAiB;IAsC/B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,kBAAkB;CAe3B"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { Logger as LoggerClass } from '../utils/Logger.js';
|
|
4
|
-
/**
|
|
5
|
-
* AgentManager class for discovering, loading, parsing, and caching agent definitions.
|
|
6
|
-
*
|
|
7
|
-
* Provides automatic detection of .md/.txt files in configured directory,
|
|
8
|
-
* parsing of Claude Code sub-agent format, and efficient caching with
|
|
9
|
-
* file change detection.
|
|
10
|
-
*/
|
|
11
4
|
export class AgentManager {
|
|
12
5
|
config;
|
|
13
6
|
logger;
|
|
@@ -15,15 +8,7 @@ export class AgentManager {
|
|
|
15
8
|
this.config = config;
|
|
16
9
|
this.logger = new LoggerClass(config.logLevel);
|
|
17
10
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a specific agent definition by name.
|
|
20
|
-
*
|
|
21
|
-
* @param name - The name of the agent to retrieve
|
|
22
|
-
* @returns Promise resolving to the agent definition or undefined if not found
|
|
23
|
-
* @throws {Error} When agent name is invalid
|
|
24
|
-
*/
|
|
25
11
|
async getAgent(name) {
|
|
26
|
-
// Input validation for security
|
|
27
12
|
if (!name || typeof name !== 'string') {
|
|
28
13
|
throw new Error('Invalid agent name: agent name is required');
|
|
29
14
|
}
|
|
@@ -33,49 +18,29 @@ export class AgentManager {
|
|
|
33
18
|
if (name.length > 255) {
|
|
34
19
|
throw new Error('Invalid agent name: too long agent name');
|
|
35
20
|
}
|
|
36
|
-
// Check for invalid characters that could be used for path traversal or injection
|
|
37
21
|
const invalidChars = /[<>:"/\\|?*;`$()&|\s]/;
|
|
38
22
|
if (invalidChars.test(name)) {
|
|
39
23
|
throw new Error('Invalid agent name: forbidden characters detected');
|
|
40
24
|
}
|
|
41
|
-
// Check for control characters using char code inspection
|
|
42
25
|
for (let i = 0; i < name.length; i++) {
|
|
43
26
|
const charCode = name.charCodeAt(i);
|
|
44
27
|
if ((charCode >= 0 && charCode <= 31) || charCode === 127) {
|
|
45
28
|
throw new Error('Invalid agent name: forbidden characters detected');
|
|
46
29
|
}
|
|
47
30
|
}
|
|
48
|
-
// Check for path traversal attempts
|
|
49
31
|
if (name.includes('..') || name.includes('./') || name.includes('.\\')) {
|
|
50
32
|
throw new Error('Invalid agent name: path traversal attempt detected');
|
|
51
33
|
}
|
|
52
34
|
const agents = await this.loadAgentsFromDirectory();
|
|
53
35
|
return agents.get(name);
|
|
54
36
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Lists all available agent definitions.
|
|
57
|
-
*
|
|
58
|
-
* @returns Promise resolving to an array of all agent definitions
|
|
59
|
-
*/
|
|
60
37
|
async listAgents() {
|
|
61
38
|
const agents = await this.loadAgentsFromDirectory();
|
|
62
39
|
return Array.from(agents.values());
|
|
63
40
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Refreshes the agents by re-scanning the agents directory.
|
|
66
|
-
* Forces reload of all agent definitions from disk.
|
|
67
|
-
*
|
|
68
|
-
* @returns Promise resolving when refresh is complete
|
|
69
|
-
*/
|
|
70
41
|
async refreshAgents() {
|
|
71
42
|
await this.loadAgentsFromDirectory();
|
|
72
43
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Loads all agent definitions from the configured directory.
|
|
75
|
-
* Scans for .md and .txt files and parses them as agent definitions.
|
|
76
|
-
*
|
|
77
|
-
* @returns Map of agent name to agent definition
|
|
78
|
-
*/
|
|
79
44
|
async loadAgentsFromDirectory() {
|
|
80
45
|
try {
|
|
81
46
|
const agentsDir = await fs.promises.realpath(path.resolve(this.config.agentsDir));
|
|
@@ -147,19 +112,11 @@ export class AgentManager {
|
|
|
147
112
|
throw new Error(`Failed to load agents from directory: ${this.config.agentsDir}`);
|
|
148
113
|
}
|
|
149
114
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Loads and parses a single agent definition from a file.
|
|
152
|
-
*
|
|
153
|
-
* @param resolvedFilePath - Validated real path used for reading the definition
|
|
154
|
-
* @param agentName - Agent name derived from the discovered directory entry
|
|
155
|
-
* @returns Promise resolving to the parsed agent definition or undefined
|
|
156
|
-
*/
|
|
157
115
|
async loadAgentFromFile(resolvedFilePath, agentName) {
|
|
158
116
|
try {
|
|
159
117
|
this.logger.debug('Loading agent definition from file', { filePath: resolvedFilePath });
|
|
160
118
|
const content = await fs.promises.readFile(resolvedFilePath, 'utf-8');
|
|
161
119
|
const stats = await fs.promises.stat(resolvedFilePath);
|
|
162
|
-
// Parse description from content (first line or first heading)
|
|
163
120
|
const description = this.extractDescription(content);
|
|
164
121
|
const agentDefinition = {
|
|
165
122
|
name: agentName,
|
|
@@ -186,22 +143,13 @@ export class AgentManager {
|
|
|
186
143
|
return (relative === '' ||
|
|
187
144
|
(relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)));
|
|
188
145
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Extracts description from agent file content.
|
|
191
|
-
* Looks for first heading or first line as description.
|
|
192
|
-
*
|
|
193
|
-
* @param content - The file content to parse
|
|
194
|
-
* @returns Extracted description or default message
|
|
195
|
-
*/
|
|
196
146
|
extractDescription(content) {
|
|
197
147
|
const lines = content.split('\n').filter((line) => line.trim());
|
|
198
|
-
// Look for first markdown heading
|
|
199
148
|
for (const line of lines) {
|
|
200
149
|
if (line.startsWith('#')) {
|
|
201
150
|
return line.replace(/^#+\s*/, '').trim();
|
|
202
151
|
}
|
|
203
152
|
}
|
|
204
|
-
// Fall back to first non-empty line
|
|
205
153
|
if (lines.length > 0 && lines[0]) {
|
|
206
154
|
return lines[0].trim();
|
|
207
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAe,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEvE
|
|
1
|
+
{"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../../src/agents/AgentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAe,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEvE,MAAM,OAAO,YAAY;IAGH;IAFZ,MAAM,CAAQ;IAEtB,YAAoB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACrE,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACtB,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C,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAE/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;YAC1C,CAAC;QACH,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACxB,CAAC;QAED,OAAO,kBAAkB,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -1,63 +1,22 @@
|
|
|
1
1
|
import { type AgentPermission, type AgentType } from '../execution/AgentExecutor.js';
|
|
2
2
|
import { type LogLevel } from '../utils/Logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Server configuration management class.
|
|
5
|
-
*
|
|
6
|
-
* Handles loading configuration from environment variables with fallback defaults,
|
|
7
|
-
* validates configuration values, and provides type-safe access to server settings.
|
|
8
|
-
*
|
|
9
|
-
* Environment variables:
|
|
10
|
-
* - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
|
|
11
|
-
* - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
|
|
12
|
-
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
13
|
-
* - AGENT_TYPE: Type of agent to use (REQUIRED)
|
|
14
|
-
* - AGENT_PERMISSION: Approval/sandbox level for sub-agents ('read-only' | 'safe-edit' | 'yolo') (default: 'safe-edit')
|
|
15
|
-
* - AGENT_MODEL: Optional model override for every agent execution
|
|
16
|
-
* - AGENT_EFFORT: Optional backend-specific reasoning effort/model variant
|
|
17
|
-
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
18
|
-
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
19
|
-
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
20
|
-
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
21
|
-
* - AGENTS_SETTINGS_PATH: Path to CLI settings file/directory (optional)
|
|
22
|
-
*/
|
|
23
3
|
export declare class ServerConfig {
|
|
24
|
-
/** Server name identifier used for MCP registration */
|
|
25
4
|
readonly serverName: string;
|
|
26
|
-
/** Server version used for identification */
|
|
27
5
|
readonly serverVersion: string;
|
|
28
|
-
/** Directory path containing agent definition markdown files */
|
|
29
6
|
readonly agentsDir: string;
|
|
30
|
-
/** Type of agent to use for execution */
|
|
31
7
|
readonly agentType: AgentType;
|
|
32
|
-
/** Approval/sandbox level for sub-agent execution */
|
|
33
8
|
readonly agentPermission: AgentPermission;
|
|
34
|
-
/** Optional model override applied to every execution */
|
|
35
9
|
readonly agentModel: string | undefined;
|
|
36
|
-
/** Optional backend-specific reasoning effort or model variant */
|
|
37
10
|
readonly agentEffort: string | undefined;
|
|
38
|
-
/** Log level for server operations */
|
|
39
11
|
readonly logLevel: LogLevel;
|
|
40
|
-
/** Maximum execution timeout in milliseconds for agent execution */
|
|
41
12
|
readonly executionTimeoutMs: number;
|
|
42
|
-
/** Enable session management functionality */
|
|
43
13
|
readonly sessionEnabled: boolean;
|
|
44
|
-
/** Directory for storing session files */
|
|
45
14
|
readonly sessionDir: string;
|
|
46
|
-
/** Number of days to retain session files before cleanup */
|
|
47
15
|
readonly sessionRetentionDays: number;
|
|
48
|
-
/** Path to CLI settings file/directory for agent execution */
|
|
49
16
|
readonly agentsSettingsPath: string | undefined;
|
|
50
|
-
/** API key for cursor-agent authentication (from CURSOR_API_KEY or CLI_API_KEY env var) */
|
|
51
17
|
readonly cursorApiKey: string | undefined;
|
|
52
|
-
/** API key for GLM/Z.ai authentication (from CLI_API_KEY env var) */
|
|
53
18
|
readonly glmApiKey: string | undefined;
|
|
54
|
-
/** API key for Kimi authentication (from CLI_API_KEY env var) */
|
|
55
19
|
readonly kimiApiKey: string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new ServerConfig instance by loading values from environment variables
|
|
58
|
-
* or using default values.
|
|
59
|
-
* @throws {Error} When AGENTS_DIR environment variable is not set
|
|
60
|
-
*/
|
|
61
20
|
constructor();
|
|
62
21
|
}
|
|
63
22
|
//# sourceMappingURL=ServerConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EAKf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"ServerConfig.d.ts","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EAKf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE1E,qBAAa,YAAY;IACvB,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,SAAgB,aAAa,EAAE,MAAM,CAAA;IAErC,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,SAAgB,SAAS,EAAE,SAAS,CAAA;IAEpC,SAAgB,eAAe,EAAE,eAAe,CAAA;IAEhD,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAE9C,SAAgB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAE/C,SAAgB,QAAQ,EAAE,QAAQ,CAAA;IAElC,SAAgB,kBAAkB,EAAE,MAAM,CAAA;IAE1C,SAAgB,cAAc,EAAE,OAAO,CAAA;IAEvC,SAAgB,UAAU,EAAE,MAAM,CAAA;IAElC,SAAgB,oBAAoB,EAAE,MAAM,CAAA;IAE5C,SAAgB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAA;IAEtD,SAAgB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAEhD,SAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAE7C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;;CAsG/C"}
|
|
@@ -1,67 +1,25 @@
|
|
|
1
1
|
import { AGENT_EFFORT_SUPPORTED_TYPES, AGENT_PERMISSIONS, AGENT_TYPES, DEFAULT_AGENT_PERMISSION, isAgentPermission, isAgentType, supportsAgentEffort, } from '../execution/AgentExecutor.js';
|
|
2
2
|
import { isLogLevel, LOG_LEVELS } from '../utils/Logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Server configuration management class.
|
|
5
|
-
*
|
|
6
|
-
* Handles loading configuration from environment variables with fallback defaults,
|
|
7
|
-
* validates configuration values, and provides type-safe access to server settings.
|
|
8
|
-
*
|
|
9
|
-
* Environment variables:
|
|
10
|
-
* - SERVER_NAME: Name identifier for the MCP server (default: 'sub-agents-mcp-server')
|
|
11
|
-
* - SERVER_VERSION: Version of the MCP server (default: '1.0.0')
|
|
12
|
-
* - AGENTS_DIR: Directory containing agent definition files (REQUIRED - must be absolute path)
|
|
13
|
-
* - AGENT_TYPE: Type of agent to use (REQUIRED)
|
|
14
|
-
* - AGENT_PERMISSION: Approval/sandbox level for sub-agents ('read-only' | 'safe-edit' | 'yolo') (default: 'safe-edit')
|
|
15
|
-
* - AGENT_MODEL: Optional model override for every agent execution
|
|
16
|
-
* - AGENT_EFFORT: Optional backend-specific reasoning effort/model variant
|
|
17
|
-
* - LOG_LEVEL: Log level for server operations (default: 'info')
|
|
18
|
-
* - SESSION_ENABLED: Enable session management functionality (default: false)
|
|
19
|
-
* - SESSION_DIR: Directory for storing session files (default: '.mcp-sessions')
|
|
20
|
-
* - SESSION_RETENTION_DAYS: Number of days to retain session files (default: 1)
|
|
21
|
-
* - AGENTS_SETTINGS_PATH: Path to CLI settings file/directory (optional)
|
|
22
|
-
*/
|
|
23
3
|
export class ServerConfig {
|
|
24
|
-
/** Server name identifier used for MCP registration */
|
|
25
4
|
serverName;
|
|
26
|
-
/** Server version used for identification */
|
|
27
5
|
serverVersion;
|
|
28
|
-
/** Directory path containing agent definition markdown files */
|
|
29
6
|
agentsDir;
|
|
30
|
-
/** Type of agent to use for execution */
|
|
31
7
|
agentType;
|
|
32
|
-
/** Approval/sandbox level for sub-agent execution */
|
|
33
8
|
agentPermission;
|
|
34
|
-
/** Optional model override applied to every execution */
|
|
35
9
|
agentModel;
|
|
36
|
-
/** Optional backend-specific reasoning effort or model variant */
|
|
37
10
|
agentEffort;
|
|
38
|
-
/** Log level for server operations */
|
|
39
11
|
logLevel;
|
|
40
|
-
/** Maximum execution timeout in milliseconds for agent execution */
|
|
41
12
|
executionTimeoutMs;
|
|
42
|
-
/** Enable session management functionality */
|
|
43
13
|
sessionEnabled;
|
|
44
|
-
/** Directory for storing session files */
|
|
45
14
|
sessionDir;
|
|
46
|
-
/** Number of days to retain session files before cleanup */
|
|
47
15
|
sessionRetentionDays;
|
|
48
|
-
/** Path to CLI settings file/directory for agent execution */
|
|
49
16
|
agentsSettingsPath;
|
|
50
|
-
/** API key for cursor-agent authentication (from CURSOR_API_KEY or CLI_API_KEY env var) */
|
|
51
17
|
cursorApiKey;
|
|
52
|
-
/** API key for GLM/Z.ai authentication (from CLI_API_KEY env var) */
|
|
53
18
|
glmApiKey;
|
|
54
|
-
/** API key for Kimi authentication (from CLI_API_KEY env var) */
|
|
55
19
|
kimiApiKey;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a new ServerConfig instance by loading values from environment variables
|
|
58
|
-
* or using default values.
|
|
59
|
-
* @throws {Error} When AGENTS_DIR environment variable is not set
|
|
60
|
-
*/
|
|
61
20
|
constructor() {
|
|
62
21
|
this.serverName = process.env['SERVER_NAME'] || 'sub-agents-mcp';
|
|
63
22
|
this.serverVersion = process.env['SERVER_VERSION'] || '0.1.0';
|
|
64
|
-
// AGENTS_DIR is required for MCP to work correctly
|
|
65
23
|
const agentsDir = process.env['AGENTS_DIR'];
|
|
66
24
|
if (!agentsDir) {
|
|
67
25
|
throw new Error('AGENTS_DIR environment variable is required.\n' +
|
|
@@ -124,26 +82,16 @@ export class ServerConfig {
|
|
|
124
82
|
else {
|
|
125
83
|
this.executionTimeoutMs = 300000;
|
|
126
84
|
}
|
|
127
|
-
// Session management configuration
|
|
128
|
-
// Only 'true' string enables session management, all other values are treated as false
|
|
129
85
|
this.sessionEnabled = process.env['SESSION_ENABLED'] === 'true';
|
|
130
86
|
this.sessionDir = process.env['SESSION_DIR'] || '.mcp-sessions';
|
|
131
|
-
// Parse SESSION_RETENTION_DAYS with validation (must be positive integer)
|
|
132
87
|
const retentionDaysEnv = process.env['SESSION_RETENTION_DAYS'];
|
|
133
88
|
if (retentionDaysEnv?.trim()) {
|
|
134
89
|
const parsedDays = Number.parseInt(retentionDaysEnv, 10);
|
|
135
|
-
// Use default (1 day) for invalid values (NaN, zero, or negative)
|
|
136
90
|
this.sessionRetentionDays = Number.isNaN(parsedDays) || parsedDays <= 0 ? 1 : parsedDays;
|
|
137
91
|
}
|
|
138
92
|
else {
|
|
139
93
|
this.sessionRetentionDays = 1;
|
|
140
94
|
}
|
|
141
|
-
// CLI settings path (optional)
|
|
142
|
-
// Used to specify custom settings file/directory for each CLI:
|
|
143
|
-
// - Claude: passed as --settings argument
|
|
144
|
-
// - Cursor: set as CURSOR_CONFIG_DIR environment variable
|
|
145
|
-
// - Codex: set as CODEX_HOME environment variable
|
|
146
|
-
// - Gemini/Grok/Antigravity/OpenCode: not supported (upstream limitation or normal config discovery)
|
|
147
95
|
this.agentsSettingsPath = process.env['AGENTS_SETTINGS_PATH'] || undefined;
|
|
148
96
|
// Cursor API key: prefer CURSOR_API_KEY, fall back to CLI_API_KEY for backward compatibility
|
|
149
97
|
const cursorApiKeyEnv = process.env['CURSOR_API_KEY'] || process.env['CLI_API_KEY'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,WAAW,EAGX,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE1E
|
|
1
|
+
{"version":3,"file":"ServerConfig.js","sourceRoot":"","sources":["../../src/config/ServerConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,EACjB,WAAW,EAGX,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE1E,MAAM,OAAO,YAAY;IACP,UAAU,CAAQ;IAElB,aAAa,CAAQ;IAErB,SAAS,CAAQ;IAEjB,SAAS,CAAW;IAEpB,eAAe,CAAiB;IAEhC,UAAU,CAAoB;IAE9B,WAAW,CAAoB;IAE/B,QAAQ,CAAU;IAElB,kBAAkB,CAAQ;IAE1B,cAAc,CAAS;IAEvB,UAAU,CAAQ;IAElB,oBAAoB,CAAQ;IAE5B,kBAAkB,CAAoB;IAEtC,YAAY,CAAoB;IAEhC,SAAS,CAAoB;IAE7B,UAAU,CAAoB;IAE9C;QACE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,gBAAgB,CAAA;QAChE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAA;QAE7D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAC3C,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;CACF"}
|
|
@@ -1,183 +1,48 @@
|
|
|
1
1
|
import type { ExecutionParams } from '../types/ExecutionParams.js';
|
|
2
2
|
import { Logger } from '../utils/Logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Detailed execution result that includes performance metrics and method information.
|
|
5
|
-
* Captures the agent execution outcome with additional monitoring capabilities.
|
|
6
|
-
*/
|
|
7
3
|
export interface AgentExecutionResult {
|
|
8
|
-
/**
|
|
9
|
-
* Standard output from the agent execution.
|
|
10
|
-
* Contains the agent's response or execution result.
|
|
11
|
-
*/
|
|
12
4
|
stdout: string;
|
|
13
|
-
/**
|
|
14
|
-
* Standard error output from the agent execution.
|
|
15
|
-
* Contains error messages and diagnostic information.
|
|
16
|
-
*/
|
|
17
5
|
stderr: string;
|
|
18
|
-
/**
|
|
19
|
-
* Exit code returned by the agent process.
|
|
20
|
-
* 0 indicates success, non-zero indicates failure.
|
|
21
|
-
*/
|
|
22
6
|
exitCode: number;
|
|
23
|
-
/**
|
|
24
|
-
* Total execution time in milliseconds.
|
|
25
|
-
* Used for performance monitoring and optimization.
|
|
26
|
-
*/
|
|
27
7
|
executionTime: number;
|
|
28
|
-
/**
|
|
29
|
-
* Whether a result JSON was successfully obtained from the agent.
|
|
30
|
-
* True when StreamProcessor detects a valid JSON response.
|
|
31
|
-
*/
|
|
32
8
|
hasResult?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* The parsed JSON result from the agent if available.
|
|
35
|
-
* Contains the structured response data when hasResult is true.
|
|
36
|
-
*/
|
|
37
9
|
resultJson?: unknown;
|
|
38
10
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Simplified execution configuration.
|
|
41
|
-
*/
|
|
42
11
|
export interface ExecutionConfig {
|
|
43
|
-
/**
|
|
44
|
-
* Maximum execution timeout in milliseconds.
|
|
45
|
-
* Default: 5 minutes (300000ms)
|
|
46
|
-
*/
|
|
47
12
|
executionTimeout: number;
|
|
48
|
-
/** Maximum combined stdout/stderr bytes retained in memory. */
|
|
49
13
|
maxOutputBytes: number;
|
|
50
|
-
/**
|
|
51
|
-
* Type of agent to use for execution.
|
|
52
|
-
* 'cursor', 'claude', 'gemini', 'codex', 'glm', 'kimi', 'grok', 'antigravity', or 'opencode'
|
|
53
|
-
*/
|
|
54
14
|
agentType: AgentType;
|
|
55
|
-
/**
|
|
56
|
-
* Approval/sandbox level the sub-agent runs with.
|
|
57
|
-
*
|
|
58
|
-
* Sub-agents have no stdin, so any approval prompt would deadlock the run.
|
|
59
|
-
* The default 'safe-edit' keeps writes confined to the workspace while
|
|
60
|
-
* suppressing prompts. The default value is owned by ServerConfig and
|
|
61
|
-
* threaded through here; this field is required.
|
|
62
|
-
*/
|
|
63
15
|
permission: AgentPermission;
|
|
64
|
-
/**
|
|
65
|
-
* Path to CLI settings file/directory.
|
|
66
|
-
* Applied differently based on agentType:
|
|
67
|
-
* - claude: passed as --settings argument
|
|
68
|
-
* - cursor: set as CURSOR_CONFIG_DIR environment variable
|
|
69
|
-
* - codex: set as CODEX_HOME environment variable
|
|
70
|
-
* - gemini: not supported (ignored)
|
|
71
|
-
*/
|
|
72
16
|
agentsSettingsPath?: string;
|
|
73
|
-
/**
|
|
74
|
-
* API key for cursor-agent authentication.
|
|
75
|
-
* Passed to cursor-agent via CURSOR_API_KEY environment variable.
|
|
76
|
-
*/
|
|
77
17
|
cursorApiKey?: string;
|
|
78
|
-
/**
|
|
79
|
-
* API key for GLM (Z.ai) authentication.
|
|
80
|
-
* Passed to the claude binary via ANTHROPIC_AUTH_TOKEN environment variable.
|
|
81
|
-
*/
|
|
82
18
|
glmApiKey?: string;
|
|
83
|
-
/**
|
|
84
|
-
* API key for Kimi authentication.
|
|
85
|
-
* Passed to the claude binary via ANTHROPIC_API_KEY environment variable.
|
|
86
|
-
*/
|
|
87
19
|
kimiApiKey?: string;
|
|
88
|
-
/** Optional model override applied to every execution by this MCP server. */
|
|
89
20
|
model?: string;
|
|
90
|
-
/** Optional backend-specific reasoning effort or model variant. */
|
|
91
21
|
effort?: string;
|
|
92
22
|
}
|
|
93
23
|
export declare const DEFAULT_EXECUTION_TIMEOUT = 300000;
|
|
94
|
-
|
|
95
|
-
* Supported agent runtimes. Single source of truth for both runtime validation
|
|
96
|
-
* (ServerConfig) and static typing.
|
|
97
|
-
*/
|
|
98
|
-
export declare const AGENT_TYPES: readonly ["cursor", "claude", "gemini", "codex", "glm", "kimi", "grok", "antigravity", "opencode"];
|
|
24
|
+
export declare const AGENT_TYPES: readonly ["cursor", "claude", "gemini", "codex", "glm", "kimi", "grok", "antigravity", "opencode", "command-code"];
|
|
99
25
|
export type AgentType = (typeof AGENT_TYPES)[number];
|
|
100
26
|
export declare function isAgentType(value: unknown): value is AgentType;
|
|
101
|
-
export declare const AGENT_EFFORT_SUPPORTED_TYPES: readonly ["codex", "claude", "glm", "kimi", "grok", "antigravity", "opencode"];
|
|
27
|
+
export declare const AGENT_EFFORT_SUPPORTED_TYPES: readonly ["codex", "claude", "glm", "kimi", "grok", "antigravity", "opencode", "command-code"];
|
|
102
28
|
export declare function supportsAgentEffort(agentType: AgentType): agentType is (typeof AGENT_EFFORT_SUPPORTED_TYPES)[number];
|
|
103
|
-
/**
|
|
104
|
-
* Supported permission levels. Single source of truth for both runtime
|
|
105
|
-
* validation (ServerConfig) and static typing.
|
|
106
|
-
*/
|
|
107
29
|
export declare const AGENT_PERMISSIONS: readonly ["read-only", "safe-edit", "yolo"];
|
|
108
30
|
export type AgentPermission = (typeof AGENT_PERMISSIONS)[number];
|
|
109
31
|
export declare function isAgentPermission(value: unknown): value is AgentPermission;
|
|
110
|
-
/**
|
|
111
|
-
* Default permission level used when AGENT_PERMISSION is not set.
|
|
112
|
-
* Owned here so ServerConfig and createExecutionConfig share a single constant.
|
|
113
|
-
*/
|
|
114
32
|
export declare const DEFAULT_AGENT_PERMISSION: AgentPermission;
|
|
115
|
-
/**
|
|
116
|
-
* Creates a complete ExecutionConfig with the provided agent type.
|
|
117
|
-
* @param agentType - The type of agent to use
|
|
118
|
-
* @param overrides - Optional overrides for configuration values
|
|
119
|
-
*/
|
|
120
33
|
export declare function createExecutionConfig(agentType: AgentType, overrides?: Partial<Omit<ExecutionConfig, 'agentType'>>): ExecutionConfig;
|
|
121
|
-
/**
|
|
122
|
-
* AgentExecutor class implements execution strategy for running Claude Code agents.
|
|
123
|
-
* Uses child_process.spawn for proper TTY handling and stdin/stdout streaming.
|
|
124
|
-
* Includes performance monitoring and timeout management.
|
|
125
|
-
*/
|
|
126
34
|
export declare class AgentExecutor {
|
|
127
35
|
private readonly config;
|
|
128
36
|
private readonly logger;
|
|
129
|
-
/**
|
|
130
|
-
* Creates a new AgentExecutor instance.
|
|
131
|
-
*
|
|
132
|
-
* @param config - Execution configuration including CLI command and thresholds
|
|
133
|
-
* @param logger - Optional Logger instance for structured logging
|
|
134
|
-
*/
|
|
135
37
|
constructor(config: ExecutionConfig, logger?: Logger);
|
|
136
|
-
/**
|
|
137
|
-
* Executes an agent with the specified parameters using spawn strategy.
|
|
138
|
-
*
|
|
139
|
-
* This method implements the core execution logic using spawn for proper TTY
|
|
140
|
-
* handling and streaming. It includes comprehensive performance monitoring.
|
|
141
|
-
*
|
|
142
|
-
* @param params - Execution parameters including agent name, prompt, and options
|
|
143
|
-
* @returns Promise resolving to detailed execution result with performance metrics
|
|
144
|
-
* @throws {Error} When agent execution fails or parameters are invalid
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const executor = new AgentExecutor()
|
|
149
|
-
* const result = await executor.executeAgent({
|
|
150
|
-
* agent: "code-helper",
|
|
151
|
-
* prompt: "Review this code",
|
|
152
|
-
* cwd: "/project"
|
|
153
|
-
* })
|
|
154
|
-
* console.log(`Execution took ${result.executionTime}ms using ${result.executionMethod}`)
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
38
|
executeAgent(params: ExecutionParams): Promise<AgentExecutionResult>;
|
|
158
|
-
/**
|
|
159
|
-
* Builds CLI-specific command, args, and environment overrides.
|
|
160
|
-
*
|
|
161
|
-
* Each CLI's argv layout follows the pattern: permission flags first
|
|
162
|
-
* (so the per-CLI base flags and the prompt remain at the tail). Per-CLI
|
|
163
|
-
* specifics (system-prompt injection, settings path, API key) are handled
|
|
164
|
-
* by the dedicated builder.
|
|
165
|
-
*
|
|
166
|
-
* @private
|
|
167
|
-
*/
|
|
168
39
|
private buildCommandArgs;
|
|
169
|
-
/**
|
|
170
|
-
* Maps AGENTS_SETTINGS_PATH onto the per-CLI env var (claude is handled
|
|
171
|
-
* via argv, gemini does not support it). Gemini ignoring this is a known
|
|
172
|
-
* upstream limitation, not a bug here.
|
|
173
|
-
*
|
|
174
|
-
* @private
|
|
175
|
-
*/
|
|
176
40
|
private buildSettingsPathEnv;
|
|
177
41
|
private permissionFlags;
|
|
178
42
|
private invocationFlags;
|
|
179
43
|
private formatSystemUserPrompt;
|
|
180
44
|
private buildCodexArgs;
|
|
45
|
+
private buildCommandCodeArgs;
|
|
181
46
|
private buildClaudeArgs;
|
|
182
47
|
private buildGlmArgs;
|
|
183
48
|
private buildKimiArgs;
|
|
@@ -190,21 +55,8 @@ export declare class AgentExecutor {
|
|
|
190
55
|
private buildSpawnEnv;
|
|
191
56
|
private prepareSpawnEnvironment;
|
|
192
57
|
private errorCode;
|
|
193
|
-
/**
|
|
194
|
-
* Executes an agent using child_process.spawn for proper TTY handling.
|
|
195
|
-
*
|
|
196
|
-
* @private
|
|
197
|
-
* @param params - Execution parameters
|
|
198
|
-
* @returns Promise resolving to execution result
|
|
199
|
-
*/
|
|
200
58
|
private executeWithSpawn;
|
|
201
59
|
private signalNumber;
|
|
202
|
-
/**
|
|
203
|
-
* Generates a unique request ID for tracking execution requests.
|
|
204
|
-
*
|
|
205
|
-
* @private
|
|
206
|
-
* @returns Unique request identifier
|
|
207
|
-
*/
|
|
208
60
|
private generateRequestId;
|
|
209
61
|
}
|
|
210
62
|
//# sourceMappingURL=AgentExecutor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentExecutor.d.ts","sourceRoot":"","sources":["../../src/execution/AgentExecutor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,MAAM,EAAiB,MAAM,oBAAoB,CAAA;AAG1D
|
|
1
|
+
{"version":3,"file":"AgentExecutor.d.ts","sourceRoot":"","sources":["../../src/execution/AgentExecutor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,MAAM,EAAiB,MAAM,oBAAoB,CAAA;AAG1D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IAEd,MAAM,EAAE,MAAM,CAAA;IAEd,QAAQ,EAAE,MAAM,CAAA;IAEhB,aAAa,EAAE,MAAM,CAAA;IAErB,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,MAAM,CAAA;IAExB,cAAc,EAAE,MAAM,CAAA;IAEtB,SAAS,EAAE,SAAS,CAAA;IAEpB,UAAU,EAAE,eAAe,CAAA;IAE3B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,yBAAyB,SAAS,CAAA;AAsB/C,eAAO,MAAM,WAAW,oHAWd,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;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