aegiscode 3.1.10 → 3.2.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.
Files changed (209) hide show
  1. package/bin/aegis-cli-linux-x64 +0 -0
  2. package/bin/cli.js +68 -0
  3. package/package.json +11 -48
  4. package/scripts/download-binary.mjs +155 -0
  5. package/dist/main.js +0 -2171
  6. package/gui/run-gui.cjs +0 -13
  7. package/src/agent/Agent.ts +0 -903
  8. package/src/agent/SimpleAgent.ts +0 -48
  9. package/src/agent/index.ts +0 -54
  10. package/src/agent/orchestrator/AppBuilder.ts +0 -443
  11. package/src/agent/orchestrator/CouncilAgent.ts +0 -310
  12. package/src/agent/orchestrator/DiscussionRoom.ts +0 -462
  13. package/src/agent/orchestrator/OrchestratorAgent.ts +0 -637
  14. package/src/agent/orchestrator/index.ts +0 -38
  15. package/src/agent/orchestrator/utils.ts +0 -397
  16. package/src/agent/pricing.ts +0 -115
  17. package/src/agent/router.ts +0 -74
  18. package/src/agent/routerStats.ts +0 -121
  19. package/src/agent/types.ts +0 -318
  20. package/src/auth/login.ts +0 -383
  21. package/src/cli/config.ts +0 -189
  22. package/src/cli/index.ts +0 -17
  23. package/src/cli/middleware.ts +0 -119
  24. package/src/cli/types.ts +0 -75
  25. package/src/config/ConfigManager.ts +0 -587
  26. package/src/config/index.ts +0 -7
  27. package/src/config/types.ts +0 -584
  28. package/src/context/CompactionService.ts +0 -300
  29. package/src/context/ContextManager.ts +0 -450
  30. package/src/context/FileAnalyzer.ts +0 -267
  31. package/src/context/TokenCounter.ts +0 -265
  32. package/src/context/index.ts +0 -27
  33. package/src/context/storage/CacheStore.ts +0 -176
  34. package/src/context/storage/JSONLStore.ts +0 -201
  35. package/src/context/storage/MemoryStore.ts +0 -205
  36. package/src/context/storage/PersistentStore.ts +0 -327
  37. package/src/context/storage/index.ts +0 -9
  38. package/src/context/storage/pathUtils.ts +0 -114
  39. package/src/context/test.ts +0 -309
  40. package/src/context/types.ts +0 -268
  41. package/src/hooks/HookExecutor.ts +0 -434
  42. package/src/hooks/HookManager.ts +0 -596
  43. package/src/hooks/HookService.ts +0 -269
  44. package/src/hooks/Matcher.ts +0 -157
  45. package/src/hooks/index.ts +0 -63
  46. package/src/hooks/types.ts +0 -424
  47. package/src/main.tsx +0 -596
  48. package/src/mcp/HealthMonitor.ts +0 -150
  49. package/src/mcp/McpClient.ts +0 -491
  50. package/src/mcp/McpRegistry.ts +0 -321
  51. package/src/mcp/createMcpTool.ts +0 -251
  52. package/src/mcp/index.ts +0 -15
  53. package/src/mcp/server.ts +0 -334
  54. package/src/mcp/test-server.ts +0 -88
  55. package/src/mcp/test.ts +0 -372
  56. package/src/mcp/types.ts +0 -247
  57. package/src/memory/AgentMemoryBus.ts +0 -432
  58. package/src/memory/CloudSync.ts +0 -99
  59. package/src/memory/DriveSync.ts +0 -106
  60. package/src/memory/SharedMemory.ts +0 -951
  61. package/src/memory/index.ts +0 -14
  62. package/src/memory/machineFingerprint.ts +0 -40
  63. package/src/orchestrator/SubAgentMetadata.ts +0 -136
  64. package/src/prompts/builder.ts +0 -213
  65. package/src/prompts/default.ts +0 -144
  66. package/src/prompts/index.ts +0 -16
  67. package/src/prompts/plan.ts +0 -64
  68. package/src/prompts/test.ts +0 -78
  69. package/src/services/AnthropicChatService.ts +0 -341
  70. package/src/services/ChatService.ts +0 -347
  71. package/src/services/ClaudeCliChatService.ts +0 -256
  72. package/src/services/CloudSync.ts +0 -168
  73. package/src/services/CostLedger.ts +0 -211
  74. package/src/services/Heartbeat.ts +0 -135
  75. package/src/services/LearningCollector.ts +0 -291
  76. package/src/services/OllamaInstaller.ts +0 -342
  77. package/src/services/VersionChecker.ts +0 -445
  78. package/src/services/index.ts +0 -57
  79. package/src/services/streaming/OpenAIEventAdapter.ts +0 -126
  80. package/src/services/streaming/RenderingProfile.ts +0 -90
  81. package/src/services/streaming/StreamEventParser.ts +0 -181
  82. package/src/services/streaming/ThrottledRenderer.ts +0 -139
  83. package/src/services/streaming/TranscriptBuffer.ts +0 -574
  84. package/src/services/streaming/eventStatusMap.ts +0 -52
  85. package/src/services/streaming/index.ts +0 -46
  86. package/src/services/streaming/renderFormatting.ts +0 -79
  87. package/src/services/streaming/types.ts +0 -234
  88. package/src/skills/SkillLoader.ts +0 -126
  89. package/src/skills/SkillRegistry.ts +0 -366
  90. package/src/skills/index.ts +0 -48
  91. package/src/skills/types.ts +0 -146
  92. package/src/slash-commands/billing.ts +0 -70
  93. package/src/slash-commands/build.ts +0 -413
  94. package/src/slash-commands/builtinCommands.ts +0 -2733
  95. package/src/slash-commands/clone.ts +0 -242
  96. package/src/slash-commands/council.ts +0 -125
  97. package/src/slash-commands/custom/CustomCommandExecutor.ts +0 -143
  98. package/src/slash-commands/custom/CustomCommandLoader.ts +0 -251
  99. package/src/slash-commands/custom/CustomCommandRegistry.ts +0 -144
  100. package/src/slash-commands/custom/index.ts +0 -7
  101. package/src/slash-commands/debate.ts +0 -254
  102. package/src/slash-commands/gmail.ts +0 -105
  103. package/src/slash-commands/index.ts +0 -388
  104. package/src/slash-commands/mcpCommand.ts +0 -205
  105. package/src/slash-commands/types.ts +0 -201
  106. package/src/store/index.ts +0 -76
  107. package/src/store/selectors.ts +0 -246
  108. package/src/store/slices/appSlice.ts +0 -205
  109. package/src/store/slices/commandSlice.ts +0 -115
  110. package/src/store/slices/configSlice.ts +0 -46
  111. package/src/store/slices/focusSlice.ts +0 -64
  112. package/src/store/slices/index.ts +0 -9
  113. package/src/store/slices/sessionSlice.ts +0 -424
  114. package/src/store/streaming-buffer.ts +0 -425
  115. package/src/store/test.ts +0 -296
  116. package/src/store/types.ts +0 -274
  117. package/src/store/vanilla.ts +0 -186
  118. package/src/tools/builtin/bash.ts +0 -236
  119. package/src/tools/builtin/council.ts +0 -105
  120. package/src/tools/builtin/edit.ts +0 -213
  121. package/src/tools/builtin/glob.ts +0 -136
  122. package/src/tools/builtin/grep.ts +0 -263
  123. package/src/tools/builtin/index.ts +0 -61
  124. package/src/tools/builtin/memory.ts +0 -66
  125. package/src/tools/builtin/read.ts +0 -168
  126. package/src/tools/builtin/skill.ts +0 -97
  127. package/src/tools/builtin/snapshot.ts +0 -40
  128. package/src/tools/builtin/task.ts +0 -106
  129. package/src/tools/builtin/write.ts +0 -134
  130. package/src/tools/createTool.ts +0 -221
  131. package/src/tools/execution/ExecutionPipeline.ts +0 -263
  132. package/src/tools/execution/index.ts +0 -40
  133. package/src/tools/execution/stages/CacheStage.ts +0 -131
  134. package/src/tools/execution/stages/ConfirmationStage.ts +0 -203
  135. package/src/tools/execution/stages/DiscoveryStage.ts +0 -46
  136. package/src/tools/execution/stages/ExecutionStage.ts +0 -48
  137. package/src/tools/execution/stages/FormattingStage.ts +0 -44
  138. package/src/tools/execution/stages/HookStage.ts +0 -72
  139. package/src/tools/execution/stages/PermissionStage.ts +0 -287
  140. package/src/tools/execution/stages/PostHookStage.ts +0 -71
  141. package/src/tools/execution/stages/index.ts +0 -12
  142. package/src/tools/execution/test.ts +0 -266
  143. package/src/tools/execution/types.ts +0 -273
  144. package/src/tools/index.ts +0 -81
  145. package/src/tools/registry.ts +0 -304
  146. package/src/tools/schemas.ts +0 -109
  147. package/src/tools/test.ts +0 -220
  148. package/src/tools/types.ts +0 -175
  149. package/src/tools/validation/PermissionChecker.ts +0 -242
  150. package/src/tools/validation/SensitiveFileDetector.ts +0 -210
  151. package/src/tools/validation/index.ts +0 -11
  152. package/src/ui/App.tsx +0 -166
  153. package/src/ui/components/AegisInterface.tsx +0 -484
  154. package/src/ui/components/common/ChatSearch.tsx +0 -150
  155. package/src/ui/components/common/ErrorBoundary.tsx +0 -82
  156. package/src/ui/components/common/ExitMessage.tsx +0 -120
  157. package/src/ui/components/common/LoadingIndicator.tsx +0 -49
  158. package/src/ui/components/common/index.ts +0 -6
  159. package/src/ui/components/dialog/ConfirmationPrompt.tsx +0 -208
  160. package/src/ui/components/dialog/InteractiveSelector.tsx +0 -149
  161. package/src/ui/components/dialog/SetupWizard.tsx +0 -297
  162. package/src/ui/components/dialog/UpdatePrompt.tsx +0 -155
  163. package/src/ui/components/dialog/index.ts +0 -8
  164. package/src/ui/components/index.ts +0 -28
  165. package/src/ui/components/input/CommandSuggestions.tsx +0 -139
  166. package/src/ui/components/input/CustomTextInput.tsx +0 -220
  167. package/src/ui/components/input/InputArea.tsx +0 -361
  168. package/src/ui/components/input/PromptSuggestions.tsx +0 -66
  169. package/src/ui/components/input/index.ts +0 -6
  170. package/src/ui/components/layout/ChatStatusBar.tsx +0 -90
  171. package/src/ui/components/layout/ContextBar.tsx +0 -79
  172. package/src/ui/components/layout/MessageArea.tsx +0 -96
  173. package/src/ui/components/layout/MessageList.tsx +0 -647
  174. package/src/ui/components/layout/MessageSeparator.tsx +0 -26
  175. package/src/ui/components/layout/WelcomeMessage.tsx +0 -93
  176. package/src/ui/components/layout/index.ts +0 -7
  177. package/src/ui/components/markdown/CodeHighlighter.tsx +0 -292
  178. package/src/ui/components/markdown/MessageRenderer.tsx +0 -1211
  179. package/src/ui/components/markdown/index.ts +0 -8
  180. package/src/ui/components/markdown/parser.ts +0 -336
  181. package/src/ui/components/markdown/types.ts +0 -66
  182. package/src/ui/focus/FocusManager.ts +0 -137
  183. package/src/ui/focus/index.ts +0 -13
  184. package/src/ui/focus/types.ts +0 -54
  185. package/src/ui/focus/useFocus.ts +0 -75
  186. package/src/ui/hooks/index.ts +0 -11
  187. package/src/ui/hooks/useAgent.ts +0 -284
  188. package/src/ui/hooks/useCommandHistory.ts +0 -87
  189. package/src/ui/hooks/useCommandProcessor.ts +0 -443
  190. package/src/ui/hooks/useConfirmation.ts +0 -99
  191. package/src/ui/hooks/useCtrlCHandler.ts +0 -100
  192. package/src/ui/hooks/useInputBuffer.ts +0 -122
  193. package/src/ui/hooks/useTerminalSize.ts +0 -68
  194. package/src/ui/hooks/useTerminalWidth.ts +0 -5
  195. package/src/ui/hooks/useWindowedList.ts +0 -118
  196. package/src/ui/render-debugger.ts +0 -621
  197. package/src/ui/test.ts +0 -189
  198. package/src/ui/themes/ThemeManager.ts +0 -332
  199. package/src/ui/themes/aegisTheme.ts +0 -87
  200. package/src/ui/themes/darkTheme.ts +0 -87
  201. package/src/ui/themes/defaultTheme.ts +0 -85
  202. package/src/ui/themes/index.ts +0 -10
  203. package/src/ui/themes/lightTheme.ts +0 -89
  204. package/src/ui/themes/popularThemes.ts +0 -187
  205. package/src/ui/themes/types.ts +0 -130
  206. package/src/utils/clipboard.ts +0 -48
  207. package/src/utils/debug.ts +0 -43
  208. package/src/utils/environment.ts +0 -68
  209. package/src/utils/index.ts +0 -10
package/src/mcp/test.ts DELETED
@@ -1,372 +0,0 @@
1
- /**
2
- * MCP 模块测试
3
- *
4
- *
5
- *
6
- *
7
- * 1. 类型定义验证
8
- * 2. McpRegistry 单例模式
9
- * 3. JSON Schema → Zod 转换
10
- * 4. 服务器配置验证
11
- * 5. 真实 MCP Server 连接(使用本地测试服务器)
12
- */
13
-
14
- import { z } from 'zod';
15
- import { fileURLToPath } from 'url';
16
- import { dirname, join } from 'path';
17
- import {
18
- McpRegistry,
19
- McpConnectionStatus,
20
- McpServerConfig,
21
- McpToolDefinition,
22
- ErrorType,
23
- DEFAULT_HEALTH_CHECK_CONFIG,
24
- DEFAULT_CONNECTION_CONFIG,
25
- } from './index.js';
26
- import { createMcpTool } from './createMcpTool.js';
27
-
28
- const __filename = fileURLToPath(import.meta.url);
29
- const __dirname = dirname(__filename);
30
-
31
- // 模拟 MCP 工具定义(用于测试 Schema 转
32
- const MOCK_TOOL_DEFINITION: McpToolDefinition = {
33
- name: 'test_tool',
34
- description: 'A test tool for validation',
35
- inputSchema: {
36
- type: 'object',
37
- properties: {
38
- path: { type: 'string', description: 'File path' },
39
- content: { type: 'string', description: 'File content' },
40
- recursive: { type: 'boolean', description: 'Recursive flag' },
41
- depth: { type: 'number', minimum: 0, maximum: 10 },
42
- mode: { type: 'string', enum: ['read', 'write', 'append'] },
43
- },
44
- required: ['path'],
45
- },
46
- };
47
-
48
- let testsPassed = 0;
49
- let testsFailed = 0;
50
-
51
- function pass(msg: string) {
52
- testsPassed++;
53
- console.log(`✅ ${msg}`);
54
- }
55
-
56
- function fail(msg: string, error?: any) {
57
- testsFailed++;
58
- console.log(`❌ ${msg}`);
59
- if (error) console.log(` 错误: ${error}`);
60
- }
61
-
62
- async function runTests() {
63
- console.log('='.repeat(60));
64
- console.log('MCP 模块测试');
65
- console.log('='.repeat(60));
66
- console.log();
67
-
68
- // ========== 测试 1: 类型定
69
- console.log('📝 测试 1: 类型定义验证');
70
- console.log('-'.repeat(40));
71
-
72
- // 测试 McpConnectionStatus 枚
73
- if (
74
- McpConnectionStatus.DISCONNECTED === 'disconnected' &&
75
- McpConnectionStatus.CONNECTING === 'connecting' &&
76
- McpConnectionStatus.CONNECTED === 'connected' &&
77
- McpConnectionStatus.ERROR === 'error'
78
- ) {
79
- pass('McpConnectionStatus 枚举值正确');
80
- } else {
81
- fail('McpConnectionStatus 枚举值不正确');
82
- }
83
-
84
- // 测试 ErrorType 枚
85
- if (
86
- ErrorType.NETWORK_TEMPORARY === 'network_temporary' &&
87
- ErrorType.CONFIG_ERROR === 'config_error' &&
88
- ErrorType.AUTH_ERROR === 'auth_error'
89
- ) {
90
- pass('ErrorType 枚举值正确');
91
- } else {
92
- fail('ErrorType 枚举值不正确');
93
- }
94
-
95
- // 测试默认配
96
- if (
97
- DEFAULT_HEALTH_CHECK_CONFIG.intervalMs === 30000 &&
98
- DEFAULT_CONNECTION_CONFIG.maxRetries === 3
99
- ) {
100
- pass('默认配置值正确');
101
- } else {
102
- fail('默认配置值不正确');
103
- }
104
- console.log();
105
-
106
- // ========== 测试 2: McpRegistry 单
107
- console.log('📝 测试 2: McpRegistry 单例模式');
108
- console.log('-'.repeat(40));
109
-
110
- const registry1 = McpRegistry.getInstance();
111
- const registry2 = McpRegistry.getInstance();
112
-
113
- if (registry1 === registry2) {
114
- pass('McpRegistry 单例模式正常');
115
- } else {
116
- fail('McpRegistry 单例模式失败');
117
- }
118
-
119
- // 测试统计信
120
- const stats = registry1.getStatistics();
121
- if (
122
- typeof stats.totalServers === 'number' &&
123
- typeof stats.connectedServers === 'number' &&
124
- typeof stats.totalTools === 'number'
125
- ) {
126
- pass('getStatistics() 返回正确结构');
127
- } else {
128
- fail('getStatistics() 返回结构不正确');
129
- }
130
-
131
- // 测
132
- const servers = registry1.getAllServers();
133
- if (servers instanceof Map) {
134
- pass('getAllServers() 返回 Map');
135
- } else {
136
- fail('getAllServers() 未返回 Map');
137
- }
138
- console.log();
139
-
140
- // ========== 测试 3: JSON Schema → Zod 转
141
- console.log('📝 测试 3: JSON Schema → Zod 转换');
142
- console.log('-'.repeat(40));
143
-
144
- // 创建模拟 McpClient(不实际连
145
- const mockClient = {
146
- serverName: 'mock-server',
147
- connectionStatus: McpConnectionStatus.CONNECTED,
148
- availableTools: [MOCK_TOOL_DEFINITION],
149
- connectWithRetry: async () => {},
150
- disconnect: async () => {},
151
- callTool: async (name: string, args: any) => ({
152
- content: [{ type: 'text' as const, text: 'mock result' }],
153
- isError: false,
154
- }),
155
- reloadTools: async () => {},
156
- on: () => {},
157
- emit: () => {},
158
- };
159
-
160
- try {
161
- const tool = createMcpTool(
162
- mockClient as any,
163
- 'mock-server',
164
- MOCK_TOOL_DEFINITION,
165
- 'test_tool'
166
- );
167
-
168
- if (tool.name === 'test_tool') {
169
- pass('工具名称正确');
170
- } else {
171
- fail(`工具名称不正确: ${tool.name}`);
172
- }
173
-
174
- if (tool.category === 'mcp') {
175
- pass('工具分类正确');
176
- } else {
177
- fail(`工具分类不正确: ${tool.category}`);
178
- }
179
-
180
- if (tool.tags?.includes('mcp') && tool.tags?.includes('mock-server')) {
181
- pass('工具标签正确');
182
- } else {
183
- fail(`工具标签不正确: ${tool.tags}`);
184
- }
185
-
186
- // 测
187
- const funcDecl = tool.getFunctionDeclaration();
188
- if (funcDecl.name === 'test_tool') {
189
- pass('getFunctionDeclaration 名称正确');
190
- } else {
191
- fail(`getFunctionDeclaration 名称不正确: ${funcDecl.name}`);
192
- }
193
-
194
- if (funcDecl.parameters && typeof funcDecl.parameters === 'object') {
195
- pass('getFunctionDeclaration 参数结构正确');
196
- } else {
197
- fail('getFunctionDeclaration 参数结构不正确');
198
- }
199
-
200
- // 验证参数 schema 包含 required 字
201
- const params = funcDecl.parameters as any;
202
- if (params.required && params.required.includes('path')) {
203
- pass('getFunctionDeclaration 必填字段正确');
204
- } else {
205
- pass('getFunctionDeclaration 参数已生成(required 可能在 properties 内)');
206
- }
207
- } catch (error) {
208
- fail('createMcpTool 创建失败', error);
209
- }
210
- console.log();
211
-
212
- // ========== 测试 4: 服务器配置验
213
- console.log('📝 测试 4: 服务器配置验证');
214
- console.log('-'.repeat(40));
215
-
216
- const validStdioConfig: McpServerConfig = {
217
- type: 'stdio',
218
- command: 'node',
219
- args: ['server.js'],
220
- env: { DEBUG: 'true' },
221
- };
222
-
223
- const validSseConfig: McpServerConfig = {
224
- type: 'sse',
225
- url: 'http://localhost:3000/sse',
226
- headers: { Authorization: 'Bearer token' },
227
- };
228
-
229
- const validHttpConfig: McpServerConfig = {
230
- type: 'http',
231
- url: 'http://localhost:3000/api',
232
- };
233
-
234
- if (validStdioConfig.type === 'stdio' && validStdioConfig.command) {
235
- pass('stdio 配置结构正确');
236
- } else {
237
- fail('stdio 配置结构不正确');
238
- }
239
-
240
- if (validSseConfig.type === 'sse' && validSseConfig.url) {
241
- pass('sse 配置结构正确');
242
- } else {
243
- fail('sse 配置结构不正确');
244
- }
245
-
246
- if (validHttpConfig.type === 'http' && validHttpConfig.url) {
247
- pass('http 配置结构正确');
248
- } else {
249
- fail('http 配置结构不正确');
250
- }
251
- console.log();
252
-
253
- // ========== 测试 5: 工具执行模
254
- console.log('📝 测试 5: 工具执行模拟');
255
- console.log('-'.repeat(40));
256
-
257
- try {
258
- const tool = createMcpTool(
259
- mockClient as any,
260
- 'mock-server',
261
- MOCK_TOOL_DEFINITION,
262
- 'test_tool'
263
- );
264
-
265
- const result = await tool.execute({ path: '/test/path' }, {} as any);
266
-
267
- if (result.success) {
268
- pass('工具执行成功');
269
- } else {
270
- fail('工具执行失败');
271
- }
272
-
273
- if (result.llmContent?.includes('mock result')) {
274
- pass('工具返回内容正确');
275
- } else {
276
- fail(`工具返回内容不正确: ${result.llmContent}`);
277
- }
278
-
279
- if (result.displayContent?.includes('✅')) {
280
- pass('工具显示内容包含成功标记');
281
- } else {
282
- fail(`工具显示内容不正确: ${result.displayContent}`);
283
- }
284
- } catch (error) {
285
- fail('工具执行测试失败', error);
286
- }
287
- console.log();
288
-
289
- // ========== 测试 6: 真实 MCP Server 连
290
- console.log('📝 测试 6: 真实 MCP Server 连接');
291
- console.log('-'.repeat(40));
292
-
293
- // 使用全局安装
294
- // 安
295
- const testServerConfig: McpServerConfig = {
296
- type: 'stdio',
297
- command: 'npx',
298
- args: ['-y', '@modelcontextprotocol/server-filesystem', __dirname],
299
- };
300
-
301
- try {
302
- // 重
303
- McpRegistry.resetInstance();
304
- const registry = McpRegistry.getInstance();
305
-
306
- // 注册并连
307
- console.log(' 连接本地测试服务器...');
308
- await registry.registerServer('test-server', testServerConfig);
309
-
310
- const serverInfo = registry.getServer('test-server');
311
- if (serverInfo?.status === McpConnectionStatus.CONNECTED) {
312
- pass('服务器连接成功');
313
- } else {
314
- fail(`服务器连接失败: ${serverInfo?.status}`);
315
- }
316
-
317
- // 检查工
318
- const tools = await registry.getAvailableTools();
319
- if (tools.length >= 2) {
320
- pass(`发现 ${tools.length} 个工具`);
321
- for (const t of tools) {
322
- console.log(` - ${t.name}`);
323
- }
324
- } else {
325
- fail(`工具数量不足: ${tools.length}`);
326
- }
327
-
328
- // 测试工具调
329
- const listTool = tools.find(t => t.name === 'list_directory');
330
- if (listTool) {
331
- console.log(` 调用工具: ${listTool.name}`);
332
- try {
333
- const result = await listTool.execute({ path: __dirname }, {} as any);
334
- if (result.success) {
335
- pass(`${listTool.name} 工具调用成功`);
336
- } else {
337
- fail(`${listTool.name} 工具调用失败: ${result.llmContent}`);
338
- }
339
- } catch (err) {
340
- console.log(` ⚠️ 工具调用异常: ${(err as Error).message}`);
341
- }
342
- } else {
343
- console.log(' ⚠️ 未找到 list_directory 工具');
344
- }
345
-
346
- // 断开连
347
- await registry.disconnectAll();
348
- pass('服务器断开成功');
349
- } catch (error) {
350
- fail('真实连接测试失败', (error as Error).message);
351
- }
352
- console.log();
353
-
354
- // ========== 测试总
355
- console.log('='.repeat(60));
356
- console.log(`测试完成: ${testsPassed} 通过, ${testsFailed} 失败`);
357
- console.log('='.repeat(60));
358
-
359
- // 重置单
360
- McpRegistry.resetInstance();
361
-
362
- // 返回退出
363
- if (testsFailed > 0) {
364
- process.exit(1);
365
- }
366
- }
367
-
368
- // 运行测
369
- runTests().catch(error => {
370
- console.error('测试出错:', error);
371
- process.exit(1);
372
- });
package/src/mcp/types.ts DELETED
@@ -1,247 +0,0 @@
1
- /**
2
- * MCP 协议类型定义
3
- * Model Context Protocol - Anthropic 推出的 AI 工具扩展协议
4
- */
5
-
6
- import type { EventEmitter } from 'events';
7
-
8
- /**
9
- * MCP 连接状态枚举
10
- */
11
- export enum McpConnectionStatus {
12
- DISCONNECTED = 'disconnected', // 未连
13
- CONNECTING = 'connecting', // 连接
14
- CONNECTED = 'connected', // 已连
15
- ERROR = 'error', // 错
16
- }
17
-
18
- /**
19
- *
20
- */
21
- export enum ErrorType {
22
- NETWORK_TEMPORARY = 'network_temporary', // 临时网络错误(可重
23
- NETWORK_PERMANENT = 'network_permanent', // 永久网络错
24
- CONFIG_ERROR = 'config_error', // 配置错
25
- AUTH_ERROR = 'auth_error', // 认证错
26
- PROTOCOL_ERROR = 'protocol_error', // 协议错
27
- UNKNOWN = 'unknown', // 未知错
28
- }
29
-
30
- /**
31
- *
32
- */
33
- export interface ClassifiedError {
34
- type: ErrorType;
35
- isRetryable: boolean;
36
- originalError: Error;
37
- }
38
-
39
- /**
40
- * MCP 工具定义(来自 MCP Server)
41
- */
42
- export interface McpToolDefinition {
43
- name: string;
44
- description?: string;
45
- inputSchema: {
46
- type: 'object';
47
- properties?: Record<string, JSONSchemaProperty>;
48
- required?: string[];
49
- additionalProperties?: boolean;
50
- };
51
- }
52
-
53
- /**
54
- * JSON Schema 属性类型
55
- */
56
- export interface JSONSchemaProperty {
57
- type?: string | string[];
58
- description?: string;
59
- enum?: any[];
60
- items?: JSONSchemaProperty;
61
- properties?: Record<string, JSONSchemaProperty>;
62
- required?: string[];
63
- minimum?: number;
64
- maximum?: number;
65
- minLength?: number;
66
- maxLength?: number;
67
- pattern?: string;
68
- default?: any;
69
- oneOf?: JSONSchemaProperty[];
70
- anyOf?: JSONSchemaProperty[];
71
- allOf?: JSONSchemaProperty[];
72
- $ref?: string;
73
- }
74
-
75
- /**
76
- * MCP 工具调用响应
77
- */
78
- export interface McpToolCallResponse {
79
- content: Array<{
80
- type: 'text' | 'image' | 'resource';
81
- text?: string;
82
- data?: string; // base64 编码的图片数
83
- mimeType?: string;
84
- uri?: string;
85
- }>;
86
- isError?: boolean;
87
- }
88
-
89
- /**
90
- * MCP 服务器配置
91
- */
92
- export interface McpServerConfig {
93
- /** 传输类型 */
94
- type: 'stdio' | 'sse' | 'http';
95
-
96
- // ===== stdio 配
97
- /** 可执行命令 */
98
- command?: string;
99
- /** 命令参数 */
100
- args?: string[];
101
- /** 环境变量 */
102
- env?: Record<string, string>;
103
- /** 工作目录 */
104
- cwd?: string;
105
-
106
- // ===== sse/http 配置 =====
107
- /** 服务器 URL */
108
- url?: string;
109
- /** HTTP 请求头 */
110
- headers?: Record<string, string>;
111
-
112
- // ===== OAuth 配
113
- oauth?: OAuthConfig;
114
-
115
- // ===== 健康检查配
116
- healthCheck?: HealthCheckConfig;
117
-
118
- // ===== 其他配
119
- /** 是否启用 */
120
- enabled?: boolean;
121
- /** 连接超时(毫秒) */
122
- timeout?: number;
123
- /** 描述 */
124
- description?: string;
125
- }
126
-
127
- /**
128
- * OAuth 配置
129
- */
130
- export interface OAuthConfig {
131
- enabled: boolean;
132
- authorizationUrl: string;
133
- tokenUrl: string;
134
- clientId: string;
135
- clientSecret?: string;
136
- scopes?: string[];
137
- redirectUri?: string;
138
- }
139
-
140
- /**
141
- *
142
- */
143
- export interface HealthCheckConfig {
144
- enabled: boolean;
145
- /** 检查间隔(毫秒) */
146
- intervalMs: number;
147
- /** 超时时间(毫秒) */
148
- timeoutMs: number;
149
- /** 最大失败次数(超过则标记为不健康) */
150
- maxFailures: number;
151
- }
152
-
153
- /**
154
- * MCP 服务器信息
155
- */
156
- export interface McpServerInfo {
157
- /** 服务器配置 */
158
- config: McpServerConfig;
159
- /** 客户端实例 */
160
- client: McpClientInterface;
161
- /** 连接状态 */
162
- status: McpConnectionStatus;
163
- /** 可用工具列表 */
164
- tools: McpToolDefinition[];
165
- /** 服务器名称 */
166
- serverName?: string;
167
- /** 服务器版本 */
168
- serverVersion?: string;
169
- /** 连接时间 */
170
- connectedAt?: Date;
171
- /** 最后错误 */
172
- lastError?: Error;
173
- }
174
-
175
- /**
176
- * MCP 客户端接口
177
- */
178
- export interface McpClientInterface extends EventEmitter {
179
- /** 连接状态 */
180
- readonly connectionStatus: McpConnectionStatus;
181
- /** 可用工具 */
182
- readonly availableTools: McpToolDefinition[];
183
- /** 服务器名称 */
184
- readonly serverName: string;
185
-
186
- /** 连接(带重试) */
187
- connectWithRetry(maxRetries?: number, initialDelay?: number): Promise<void>;
188
- /** 断开连接 */
189
- disconnect(): Promise<void>;
190
- /** 调用工具 */
191
- callTool(name: string, arguments_: Record<string, any>): Promise<McpToolCallResponse>;
192
- /** 重新加载工具列表 */
193
- reloadTools(): Promise<void>;
194
- }
195
-
196
- /**
197
- * MCP 注册中心统计信息
198
- */
199
- export interface McpRegistryStatistics {
200
- totalServers: number;
201
- connectedServers: number;
202
- disconnectedServers: number;
203
- errorServers: number;
204
- totalTools: number;
205
- }
206
-
207
- /**
208
- * MCP 事件类型
209
- */
210
- export interface McpClientEvents {
211
- connected: (serverInfo: { name: string; version: string }) => void;
212
- disconnected: () => void;
213
- error: (error: Error) => void;
214
- reconnecting: (attempt: number) => void;
215
- reconnected: () => void;
216
- reconnectFailed: () => void;
217
- toolsUpdated: (tools: McpToolDefinition[]) => void;
218
- unhealthy: (failures: number, error: Error) => void;
219
- }
220
-
221
- export interface McpRegistryEvents {
222
- serverRegistered: (name: string, info: McpServerInfo) => void;
223
- serverConnected: (name: string, server: { name: string; version: string }) => void;
224
- serverDisconnected: (name: string) => void;
225
- serverError: (name: string, error: Error) => void;
226
- toolsUpdated: (serverName: string, tools: McpToolDefinition[], oldCount: number) => void;
227
- }
228
-
229
- /**
230
- *
231
- */
232
- export const DEFAULT_HEALTH_CHECK_CONFIG: HealthCheckConfig = {
233
- enabled: true,
234
- intervalMs: 30000, // 30
235
- timeoutMs: 5000, // 5
236
- maxFailures: 3, // 3 次失败后标记为不健
237
- };
238
-
239
- /**
240
- *
241
- */
242
- export const DEFAULT_CONNECTION_CONFIG = {
243
- maxRetries: 3,
244
- initialDelay: 1000,
245
- maxReconnectAttempts: 5,
246
- maxReconnectDelay: 30000,
247
- };