@starlink-awaken/agentmesh 1.0.0 → 1.0.2

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/src/cli.ts DELETED
@@ -1,284 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import type { AgentMessage } from './types/index.js';
4
-
5
- const BASE_URL = process.env.AGENT_GATEWAY_URL || 'http://localhost:3000';
6
-
7
- async function request<T = any>(path: string, options?: RequestInit): Promise<T> {
8
- const response = await fetch(`${BASE_URL}${path}`, {
9
- ...options,
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- ...options?.headers
13
- }
14
- });
15
-
16
- if (!response.ok) {
17
- const error = await response.json().catch(() => ({ message: 'Unknown error' }));
18
- throw new Error(`HTTP ${response.status}: ${JSON.stringify(error)}`);
19
- }
20
-
21
- return response.json() as Promise<T>;
22
- }
23
-
24
- // 命令
25
- const commands = {
26
- // 列出所有 Agent
27
- async listAgents() {
28
- const agents = await request<any[]>('/agents');
29
- console.log('\n📋 可用 Agent:\n');
30
- agents.forEach(agent => {
31
- console.log(` ${agent.id.padEnd(15)} ${agent.name.padEnd(20)} [${agent.status}]`);
32
- console.log(` 能力: ${agent.capabilities.join(', ')}\n`);
33
- });
34
- },
35
-
36
- // 提交任务
37
- async submitTask(args: string[]) {
38
- const task = args.join(' ');
39
- if (!task) {
40
- console.error('❌ 请提供任务描述');
41
- process.exit(1);
42
- }
43
-
44
- console.log(`\n📤 提交任务: ${task}\n`);
45
-
46
- const message: Partial<AgentMessage> = {
47
- type: 'request',
48
- source: 'cli',
49
- target: 'gateway',
50
- payload: {
51
- task,
52
- options: {
53
- stream: false,
54
- timeout: 300
55
- }
56
- }
57
- };
58
-
59
- const result = await request<any>('/tasks', {
60
- method: 'POST',
61
- body: JSON.stringify(message)
62
- });
63
-
64
- console.log(`✅ 任务已提交: ${result.task_id}`);
65
- console.log(` 状态: ${result.status}\n`);
66
-
67
- // 轮询获取结果
68
- console.log('Waiting for result...\n');
69
-
70
- let completed = false;
71
- let attempts = 0;
72
- const maxAttempts = 60;
73
-
74
- while (!completed && attempts < maxAttempts) {
75
- await new Promise(resolve => setTimeout(resolve, 2000));
76
-
77
- const taskResult = await request<any>(`/tasks/${result.task_id}`);
78
-
79
- if (taskResult.status === 'completed') {
80
- completed = true;
81
- console.log('✅ 任务完成!\n');
82
- console.log('📊 结果:');
83
- if (typeof taskResult.result === 'object') {
84
- Object.entries(taskResult.result).forEach(([agent, res]) => {
85
- console.log(`\n--- ${agent} ---`);
86
- console.log(res);
87
- });
88
- } else {
89
- console.log(taskResult.result);
90
- }
91
- } else if (taskResult.status === 'failed') {
92
- completed = true;
93
- console.log('❌ 任务失败!');
94
- console.log('错误:', taskResult.error);
95
- } else {
96
- attempts++;
97
- process.stdout.write('.');
98
- }
99
- }
100
-
101
- if (!completed) {
102
- console.log('\n⚠️ 任务超时\n');
103
- }
104
- },
105
-
106
- // 提交到指定 Agent
107
- async submitToAgent(agentId: string, args: string[]) {
108
- const task = args.join(' ');
109
- if (!task) {
110
- console.error('❌ 请提供任务描述');
111
- process.exit(1);
112
- }
113
-
114
- console.log(`\n📤 提交任务到 ${agentId}: ${task}\n`);
115
-
116
- const message: Partial<AgentMessage> = {
117
- type: 'request',
118
- source: 'cli',
119
- target: agentId,
120
- payload: {
121
- task,
122
- options: {
123
- stream: false,
124
- timeout: 300
125
- }
126
- }
127
- };
128
-
129
- const result = await request<any>('/tasks', {
130
- method: 'POST',
131
- body: JSON.stringify(message)
132
- });
133
-
134
- console.log(`✅ 任务已提交: ${result.task_id}`);
135
- console.log(` 状态: ${result.status}\n`);
136
-
137
- // 轮询获取结果
138
- console.log('⏳ 等待执行结果...\n');
139
-
140
- let completed = false;
141
- let attempts = 0;
142
- const maxAttempts = 60;
143
-
144
- while (!completed && attempts < maxAttempts) {
145
- await new Promise(resolve => setTimeout(resolve, 2000));
146
-
147
- const taskResult = await request<any>(`/tasks/${result.task_id}`);
148
-
149
- if (taskResult.status === 'completed') {
150
- completed = true;
151
- console.log('\n✅ 任务完成!\n');
152
- console.log('📊 结果:');
153
- console.log(taskResult.result);
154
- } else if (taskResult.status === 'failed') {
155
- completed = true;
156
- console.log('\n❌ 任务失败!');
157
- console.log('错误:', taskResult.error);
158
- } else {
159
- attempts++;
160
- process.stdout.write('.');
161
- }
162
- }
163
-
164
- if (!completed) {
165
- console.log('\n⚠️ 任务超时\n');
166
- }
167
- },
168
-
169
- // 创建共享空间
170
- async createSpace() {
171
- const result = await request<{ space_id: string }>('/spaces', {
172
- method: 'POST',
173
- body: JSON.stringify({ metadata: { createdBy: 'cli' } })
174
- });
175
-
176
- console.log(`\n✅ 共享空间已创建: ${result.space_id}\n`);
177
- return result.space_id;
178
- },
179
-
180
- // 列出任务
181
- async listTasks() {
182
- const tasks = await request<any[]>('/tasks');
183
- console.log('\n📋 任务列表:\n');
184
- if (tasks.length === 0) {
185
- console.log(' (无任务)\n');
186
- return;
187
- }
188
- tasks.forEach(task => {
189
- console.log(` ${task.id?.slice(0, 8) || 'unknown'}... ${task.status?.padEnd(10) || 'unknown'} ${new Date(task.created_at).toLocaleString()}`);
190
- });
191
- console.log('');
192
- },
193
-
194
- // 健康检查
195
- async health() {
196
- const result = await request<any>('/health');
197
- console.log('\n🔍 Gateway 状态:\n');
198
- console.log(` 状态: ${result.status}`);
199
- console.log(` Agent 数量: ${result.agents?.length || 0}`);
200
- console.log(` 时间: ${new Date(result.timestamp).toLocaleString()}\n`);
201
- }
202
- };
203
-
204
- // 主入口
205
- async function main() {
206
- const args = process.argv.slice(2);
207
-
208
- if (args.length === 0) {
209
- console.log(`
210
- 🤖 Agent Gateway CLI
211
-
212
- 用法:
213
- agent-gateway <command> [options]
214
-
215
- 命令:
216
- agents, list 列出所有可用 Agent
217
- task <description> 提交通用任务(自动路由)
218
- to <agent> <task> 提交任务到指定 Agent
219
- space, create-space 创建共享空间
220
- tasks, list-tasks 列出所有任务
221
- health, status 检查 Gateway 状态
222
-
223
- 示例:
224
- agent-gateway agents
225
- agent-gateway task 帮我写一个排序算法
226
- agent-gateway to claude-code 帮我review这段代码
227
- agent-gateway health
228
- `);
229
- process.exit(0);
230
- }
231
-
232
- const command = args[0];
233
- const commandArgs = args.slice(1);
234
-
235
- try {
236
- switch (command) {
237
- case 'agents':
238
- case 'list':
239
- case 'ls':
240
- await commands.listAgents();
241
- break;
242
-
243
- case 'task':
244
- await commands.submitTask(commandArgs);
245
- break;
246
-
247
- case 'to':
248
- if (commandArgs.length < 2) {
249
- console.error('用法: agent-gateway to <agent> <task>');
250
- process.exit(1);
251
- }
252
- const agentId = commandArgs[0];
253
- if (agentId) {
254
- await commands.submitToAgent(agentId, commandArgs.slice(1));
255
- }
256
- break;
257
-
258
- case 'space':
259
- case 'create-space':
260
- await commands.createSpace();
261
- break;
262
-
263
- case 'tasks':
264
- case 'list-tasks':
265
- await commands.listTasks();
266
- break;
267
-
268
- case 'health':
269
- case 'status':
270
- await commands.health();
271
- break;
272
-
273
- default:
274
- console.error(`❌ 未知命令: ${command}`);
275
- console.log('运行 agent-gateway 查看帮助');
276
- process.exit(1);
277
- }
278
- } catch (error: any) {
279
- console.error(`\n❌ 错误: ${error.message}\n`);
280
- process.exit(1);
281
- }
282
- }
283
-
284
- main();
@@ -1,334 +0,0 @@
1
- import { ProcessAdapter } from '../adapters/process.js';
2
- import { ClaudeCodeAdapter } from '../adapters/claude-code.js';
3
- import { OpenClawAdapter } from '../adapters/openclaw.js';
4
- import type { AgentAdapter } from '../adapters/base.js';
5
- import type { Agent } from '../types/index.js';
6
- import { getAllAgentConfigs } from './config.js';
7
-
8
- // 默认 Agent 配置
9
- const DEFAULT_AGENT_CONFIGS: Record<string, {
10
- name: string;
11
- capabilities: string[];
12
- command: string;
13
- args?: string[];
14
- env?: Record<string, string>;
15
- }> = {
16
- 'claude-code': {
17
- name: 'Claude Code',
18
- capabilities: ['code-generation', 'code-review', 'debugging', 'refactoring', 'documentation', 'file-operations'],
19
- command: 'claude',
20
- args: ['-p']
21
- },
22
- 'openclaw': {
23
- name: 'OpenClaw',
24
- capabilities: ['browser-automation', 'web-scraping', 'form-filling', 'ui-testing'],
25
- command: 'openclaw',
26
- args: ['--task']
27
- },
28
- 'opencode': {
29
- name: 'OpenCode',
30
- capabilities: ['code-completion', 'code-generation', 'refactoring', 'debugging'],
31
- command: 'opencode',
32
- args: ['--task']
33
- },
34
- 'gemini': {
35
- name: 'Google Gemini CLI',
36
- capabilities: ['code-generation', 'multimodal', 'reasoning', 'analysis'],
37
- command: 'gemini',
38
- args: ['--prompt']
39
- },
40
- 'codex': {
41
- name: 'OpenAI Codex',
42
- capabilities: ['code-generation', 'code-explanation', 'refactoring'],
43
- command: 'codex',
44
- args: ['complete']
45
- },
46
- 'github-copilot': {
47
- name: 'GitHub Copilot',
48
- capabilities: ['code-completion', 'code-suggestions', 'refactoring'],
49
- command: 'copilot',
50
- args: ['--ask']
51
- },
52
- 'qwen-code': {
53
- name: 'Qwen Code',
54
- capabilities: ['code-generation', 'code-review', 'multilingual'],
55
- command: 'qwen-code',
56
- args: ['--task']
57
- },
58
- 'crush': {
59
- name: 'CRUSH AI',
60
- capabilities: ['code-generation', 'debugging', 'security-analysis'],
61
- command: 'crush',
62
- args: ['run']
63
- },
64
- 'droid': {
65
- name: 'Droid Agent',
66
- capabilities: ['android-development', 'mobile-debugging', 'device-control'],
67
- command: 'droid',
68
- args: ['--task']
69
- },
70
- 'factory': {
71
- name: 'Factory AI',
72
- capabilities: ['code-generation', 'testing', 'documentation', 'refactoring'],
73
- command: 'factory',
74
- args: ['--task']
75
- },
76
- 'cursor': {
77
- name: 'Cursor',
78
- capabilities: ['code-completion', 'code-generation', 'refactoring', 'chat'],
79
- command: 'cursor',
80
- args: ['--task']
81
- },
82
- 'windsurf': {
83
- name: 'Windsurf',
84
- capabilities: ['code-generation', 'agentic-coding', 'flow-state'],
85
- command: 'windsurf',
86
- args: ['--task']
87
- },
88
- 'zed': {
89
- name: 'Zed AI',
90
- capabilities: ['code-generation', 'collaboration', 'high-performance'],
91
- command: 'zed',
92
- args: ['--ai-task']
93
- },
94
- 'aider': {
95
- name: 'Aider',
96
- capabilities: ['git-based-editing', 'code-refactoring', 'multi-file-changes'],
97
- command: 'aider',
98
- args: ['--message']
99
- },
100
- 'cline': {
101
- name: 'Cline',
102
- capabilities: ['autonomous-coding', 'file-operations', 'command-execution'],
103
- command: 'cline',
104
- args: ['--task']
105
- },
106
- 'roo-code': {
107
- name: 'Roo Code',
108
- capabilities: ['code-generation', 'agentic-mode', 'workspace-awareness'],
109
- command: 'roo-code',
110
- args: ['--task']
111
- },
112
- // 2026 新增 Agent
113
- 'perplexity': {
114
- name: 'Perplexity',
115
- capabilities: ['research', 'web-search', 'fact-checking', 'analysis'],
116
- command: 'perplexity',
117
- args: ['--query']
118
- },
119
- 'grok': {
120
- name: 'xAI Grok',
121
- capabilities: ['reasoning', 'humor', 'code-generation', 'analysis'],
122
- command: 'grok',
123
- args: ['--prompt']
124
- },
125
- 'phind': {
126
- name: 'Phind',
127
- capabilities: ['developer-search', 'code-search', 'documentation-search'],
128
- command: 'phind',
129
- args: ['--search']
130
- },
131
- 'you': {
132
- name: 'You.com AI',
133
- capabilities: ['web-search', 'code-search', 'general-assistant'],
134
- command: 'you',
135
- args: ['--query']
136
- },
137
- 'lepton': {
138
- name: 'Lepton AI',
139
- capabilities: ['code-generation', 'conversation', 'analysis'],
140
- command: 'lepton',
141
- args: ['--prompt']
142
- },
143
- 'ollama': {
144
- name: 'Ollama',
145
- capabilities: ['local-llm', 'code-generation', 'privacy-focused'],
146
- command: 'ollama',
147
- args: ['run']
148
- },
149
- 'llama': {
150
- name: 'Meta Llama',
151
- capabilities: ['code-generation', 'reasoning', 'open-source'],
152
- command: 'llama',
153
- args: ['--prompt']
154
- },
155
- 'mistral': {
156
- name: 'Mistral AI',
157
- capabilities: ['code-generation', 'reasoning', 'multilingual'],
158
- command: 'mistral',
159
- args: ['--task']
160
- },
161
- 'anthropic': {
162
- name: 'Anthropic CLI',
163
- capabilities: ['conversation', 'reasoning', 'code-generation'],
164
- command: 'anthropic',
165
- args: ['--prompt']
166
- }
167
- };
168
-
169
- export class AgentRegistry {
170
- private adapters: Map<string, AgentAdapter> = new Map();
171
- private initialized = false;
172
-
173
- constructor() {
174
- // 延迟初始化
175
- }
176
-
177
- /**
178
- * 初始化注册表
179
- */
180
- initialize(): void {
181
- if (this.initialized) return;
182
-
183
- // 注册内置适配器
184
- this.register(new ClaudeCodeAdapter());
185
- this.register(new OpenClawAdapter());
186
-
187
- // 从配置加载所有 Agent
188
- this.registerAllFromConfig();
189
-
190
- this.initialized = true;
191
- }
192
-
193
- /**
194
- * 从配置注册所有 Agent
195
- */
196
- private registerAllFromConfig(): void {
197
- const configAgents = getAllAgentConfigs();
198
-
199
- // 1. 先注册配置文件中的 Agent
200
- for (const config of configAgents) {
201
- if (this.adapters.has(config.id)) continue;
202
-
203
- if (config.type === 'claude-code' || config.type === 'openclaw') {
204
- // 跳过,内置适配器已注册
205
- continue;
206
- }
207
-
208
- if (config.type === 'process' && config.command) {
209
- const adapter = new ProcessAdapter(
210
- config.id,
211
- config.name,
212
- config.capabilities,
213
- {
214
- command: config.command,
215
- args: config.args,
216
- env: config.env
217
- }
218
- );
219
- this.adapters.set(config.id, adapter);
220
- console.log(`[AgentRegistry] Registered from config: ${config.id}`);
221
- }
222
- }
223
-
224
- // 2. 再注册默认 Agent(未被配置覆盖的)
225
- for (const [id, defaultConfig] of Object.entries(DEFAULT_AGENT_CONFIGS)) {
226
- if (this.adapters.has(id)) continue;
227
-
228
- const adapter = new ProcessAdapter(
229
- id,
230
- defaultConfig.name,
231
- defaultConfig.capabilities,
232
- {
233
- command: defaultConfig.command,
234
- args: defaultConfig.args,
235
- env: defaultConfig.env
236
- }
237
- );
238
-
239
- this.adapters.set(id, adapter);
240
- console.log(`[AgentRegistry] Registered default: ${id}`);
241
- }
242
- }
243
-
244
- /**
245
- * 注册自定义适配器
246
- */
247
- register(adapter: AgentAdapter): void {
248
- this.adapters.set(adapter.id, adapter);
249
- console.log(`[AgentRegistry] Registered adapter: ${adapter.id}`);
250
- }
251
-
252
- /**
253
- * 获取适配器
254
- */
255
- get(agentId: string): AgentAdapter | undefined {
256
- return this.adapters.get(agentId);
257
- }
258
-
259
- /**
260
- * 获取所有适配器
261
- */
262
- getAll(): AgentAdapter[] {
263
- return Array.from(this.adapters.values());
264
- }
265
-
266
- /**
267
- * 获取所有 Agent 信息
268
- */
269
- getAgents(): Agent[] {
270
- return this.getAll().map(adapter => ({
271
- id: adapter.id,
272
- name: adapter.name,
273
- type: adapter.type as Agent['type'],
274
- capabilities: adapter.capabilities,
275
- status: 'online' as const,
276
- lastSeen: Date.now()
277
- }));
278
- }
279
-
280
- /**
281
- * 根据能力查找 Agent
282
- */
283
- findByCapability(capability: string): Agent[] {
284
- return this.getAll()
285
- .filter(adapter => adapter.capabilities.includes(capability))
286
- .map(adapter => ({
287
- id: adapter.id,
288
- name: adapter.name,
289
- type: adapter.type as Agent['type'],
290
- capabilities: adapter.capabilities,
291
- status: 'online' as const,
292
- lastSeen: Date.now()
293
- }));
294
- }
295
-
296
- /**
297
- * 检查适配器是否存在
298
- */
299
- has(agentId: string): boolean {
300
- return this.adapters.has(agentId);
301
- }
302
-
303
- /**
304
- * 检查适配器是否健康
305
- */
306
- async checkHealth(agentId: string): Promise<boolean> {
307
- const adapter = this.adapters.get(agentId);
308
- if (!adapter) return false;
309
- return adapter.health();
310
- }
311
-
312
- /**
313
- * 获取可用 Agent 列表(健康检查)
314
- */
315
- async getAvailableAgents(): Promise<Agent[]> {
316
- const results: Agent[] = [];
317
-
318
- for (const adapter of this.adapters.values()) {
319
- const isHealthy = await adapter.health().catch(() => false);
320
- results.push({
321
- id: adapter.id,
322
- name: adapter.name,
323
- type: adapter.type as Agent['type'],
324
- capabilities: adapter.capabilities,
325
- status: isHealthy ? 'online' as const : 'offline' as const,
326
- lastSeen: Date.now()
327
- });
328
- }
329
-
330
- return results;
331
- }
332
- }
333
-
334
- export const agentRegistry = new AgentRegistry();