@starlink-awaken/agentmesh 1.0.2 → 1.0.3
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/adapters/base.d.ts +22 -0
- package/dist/adapters/base.js +10 -0
- package/dist/adapters/claude-code.d.ts +22 -0
- package/dist/adapters/claude-code.js +112 -0
- package/dist/adapters/openclaw.d.ts +22 -0
- package/dist/adapters/openclaw.js +110 -0
- package/dist/adapters/process.d.ts +28 -0
- package/dist/adapters/process.js +121 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +246 -0
- package/dist/core/agent-registry.d.ts +48 -0
- package/dist/core/agent-registry.js +295 -0
- package/dist/core/config.d.ts +59 -0
- package/dist/core/config.js +101 -0
- package/dist/core/context-manager.d.ts +52 -0
- package/dist/core/context-manager.js +165 -0
- package/dist/core/event-bus.d.ts +35 -0
- package/dist/core/event-bus.js +62 -0
- package/dist/core/metrics.d.ts +87 -0
- package/dist/core/metrics.js +167 -0
- package/dist/core/router.d.ts +46 -0
- package/dist/core/router.js +90 -0
- package/dist/core/task-manager.d.ts +41 -0
- package/dist/core/task-manager.js +197 -0
- package/dist/core/vector-store.d.ts +37 -0
- package/dist/core/vector-store.js +175 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +73 -0
- package/dist/routes/api.d.ts +2 -0
- package/dist/routes/api.js +128 -0
- package/dist/routes/websocket.d.ts +2 -0
- package/dist/routes/websocket.js +64 -0
- package/dist/types/index.d.ts +71 -0
- package/dist/types/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AgentMessage } from '../types/index.js';
|
|
2
|
+
export interface AgentAdapter {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
capabilities: string[];
|
|
7
|
+
invoke(request: AgentMessage): Promise<AgentMessage>;
|
|
8
|
+
invokeStream?(request: AgentMessage): AsyncGenerator<AgentMessage, void, unknown>;
|
|
9
|
+
health(): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Agent 适配器基类
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class BaseAgentAdapter implements AgentAdapter {
|
|
15
|
+
abstract id: string;
|
|
16
|
+
abstract name: string;
|
|
17
|
+
abstract type: string;
|
|
18
|
+
abstract capabilities: string[];
|
|
19
|
+
abstract invoke(request: AgentMessage): Promise<AgentMessage>;
|
|
20
|
+
invokeStream?(request: AgentMessage): AsyncGenerator<AgentMessage, void, unknown>;
|
|
21
|
+
abstract health(): Promise<boolean>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseAgentAdapter } from './base.js';
|
|
2
|
+
import type { AgentMessage } from '../types/index.js';
|
|
3
|
+
export declare class ClaudeCodeAdapter extends BaseAgentAdapter {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
capabilities: string[];
|
|
8
|
+
private readonly cliPath;
|
|
9
|
+
constructor(cliPath?: string);
|
|
10
|
+
/**
|
|
11
|
+
* 调用 Claude Code 执行任务
|
|
12
|
+
*/
|
|
13
|
+
invoke(request: AgentMessage): Promise<AgentMessage>;
|
|
14
|
+
/**
|
|
15
|
+
* 流式调用
|
|
16
|
+
*/
|
|
17
|
+
invokeStream(request: AgentMessage): AsyncGenerator<AgentMessage, void, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* 健康检查
|
|
20
|
+
*/
|
|
21
|
+
health(): Promise<boolean>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { BaseAgentAdapter } from './base.js';
|
|
4
|
+
export class ClaudeCodeAdapter extends BaseAgentAdapter {
|
|
5
|
+
id = 'claude-code';
|
|
6
|
+
name = 'Claude Code';
|
|
7
|
+
type = 'claude-code';
|
|
8
|
+
capabilities = [
|
|
9
|
+
'code-generation',
|
|
10
|
+
'code-review',
|
|
11
|
+
'debugging',
|
|
12
|
+
'refactoring',
|
|
13
|
+
'documentation',
|
|
14
|
+
'file-operations'
|
|
15
|
+
];
|
|
16
|
+
cliPath;
|
|
17
|
+
constructor(cliPath = 'claude') {
|
|
18
|
+
super();
|
|
19
|
+
this.cliPath = cliPath;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 调用 Claude Code 执行任务
|
|
23
|
+
*/
|
|
24
|
+
async invoke(request) {
|
|
25
|
+
const task = request.payload?.task || '';
|
|
26
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
27
|
+
try {
|
|
28
|
+
// Claude Code 的 -p 模式需要从 stdin 输入
|
|
29
|
+
const result = await execa(this.cliPath, ['-p'], {
|
|
30
|
+
input: task,
|
|
31
|
+
timeout: (request.payload?.options?.timeout || 300) * 1000,
|
|
32
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
id: uuidv4(),
|
|
36
|
+
type: 'response',
|
|
37
|
+
source: this.id,
|
|
38
|
+
target: request.source,
|
|
39
|
+
correlation_id: correlationId,
|
|
40
|
+
timestamp: Date.now(),
|
|
41
|
+
result: result.stdout
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
id: uuidv4(),
|
|
47
|
+
type: 'response',
|
|
48
|
+
source: this.id,
|
|
49
|
+
target: request.source,
|
|
50
|
+
correlation_id: correlationId,
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
error: {
|
|
53
|
+
code: 'EXECUTION_ERROR',
|
|
54
|
+
message: error.message || String(error)
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 流式调用
|
|
61
|
+
*/
|
|
62
|
+
async *invokeStream(request) {
|
|
63
|
+
const task = request.payload?.task || '';
|
|
64
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
65
|
+
try {
|
|
66
|
+
const process = execa(this.cliPath, ['-p', task], {
|
|
67
|
+
timeout: (request.payload?.options?.timeout || 300) * 1000,
|
|
68
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
69
|
+
});
|
|
70
|
+
// 监听 stdout 流
|
|
71
|
+
process.stdout?.on('data', (_chunk) => {
|
|
72
|
+
// 这里可以发送流式消息
|
|
73
|
+
});
|
|
74
|
+
const result = await process;
|
|
75
|
+
yield {
|
|
76
|
+
id: uuidv4(),
|
|
77
|
+
type: 'stream_end',
|
|
78
|
+
source: this.id,
|
|
79
|
+
target: request.source,
|
|
80
|
+
correlation_id: correlationId,
|
|
81
|
+
timestamp: Date.now(),
|
|
82
|
+
result: result.stdout
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
yield {
|
|
87
|
+
id: uuidv4(),
|
|
88
|
+
type: 'response',
|
|
89
|
+
source: this.id,
|
|
90
|
+
target: request.source,
|
|
91
|
+
correlation_id: correlationId,
|
|
92
|
+
timestamp: Date.now(),
|
|
93
|
+
error: {
|
|
94
|
+
code: 'EXECUTION_ERROR',
|
|
95
|
+
message: error.message || String(error)
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 健康检查
|
|
102
|
+
*/
|
|
103
|
+
async health() {
|
|
104
|
+
try {
|
|
105
|
+
await execa(this.cliPath, ['--version'], { timeout: 5000 });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseAgentAdapter } from './base.js';
|
|
2
|
+
import type { AgentMessage } from '../types/index.js';
|
|
3
|
+
export declare class OpenClawAdapter extends BaseAgentAdapter {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
capabilities: string[];
|
|
8
|
+
private readonly cliPath;
|
|
9
|
+
constructor(cliPath?: string);
|
|
10
|
+
/**
|
|
11
|
+
* 调用 OpenClaw 执行任务
|
|
12
|
+
*/
|
|
13
|
+
invoke(request: AgentMessage): Promise<AgentMessage>;
|
|
14
|
+
/**
|
|
15
|
+
* 流式调用
|
|
16
|
+
*/
|
|
17
|
+
invokeStream(request: AgentMessage): AsyncGenerator<AgentMessage, void, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* 健康检查
|
|
20
|
+
*/
|
|
21
|
+
health(): Promise<boolean>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { BaseAgentAdapter } from './base.js';
|
|
4
|
+
export class OpenClawAdapter extends BaseAgentAdapter {
|
|
5
|
+
id = 'openclaw';
|
|
6
|
+
name = 'OpenClaw';
|
|
7
|
+
type = 'openclaw';
|
|
8
|
+
capabilities = [
|
|
9
|
+
'browser-automation',
|
|
10
|
+
'web-scraping',
|
|
11
|
+
'form-filling',
|
|
12
|
+
'ui-testing'
|
|
13
|
+
];
|
|
14
|
+
cliPath;
|
|
15
|
+
constructor(cliPath = 'openclaw') {
|
|
16
|
+
super();
|
|
17
|
+
this.cliPath = cliPath;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 调用 OpenClaw 执行任务
|
|
21
|
+
*/
|
|
22
|
+
async invoke(request) {
|
|
23
|
+
const task = request.payload?.task || '';
|
|
24
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
25
|
+
try {
|
|
26
|
+
// OpenClaw CLI 调用方式(假设使用 --task 或类似参数)
|
|
27
|
+
const result = await execa(this.cliPath, ['--task', task], {
|
|
28
|
+
timeout: (request.payload?.options?.timeout || 300) * 1000,
|
|
29
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
id: uuidv4(),
|
|
33
|
+
type: 'response',
|
|
34
|
+
source: this.id,
|
|
35
|
+
target: request.source,
|
|
36
|
+
correlation_id: correlationId,
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
result: result.stdout
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
43
|
+
return {
|
|
44
|
+
id: uuidv4(),
|
|
45
|
+
type: 'response',
|
|
46
|
+
source: this.id,
|
|
47
|
+
target: request.source,
|
|
48
|
+
correlation_id: correlationId,
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
error: {
|
|
51
|
+
code: 'EXECUTION_ERROR',
|
|
52
|
+
message: errorMessage
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 流式调用
|
|
59
|
+
*/
|
|
60
|
+
async *invokeStream(request) {
|
|
61
|
+
const task = request.payload?.task || '';
|
|
62
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
63
|
+
try {
|
|
64
|
+
const process = execa(this.cliPath, ['--task', task], {
|
|
65
|
+
timeout: (request.payload?.options?.timeout || 300) * 1000,
|
|
66
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
67
|
+
});
|
|
68
|
+
process.stdout?.on('data', (_chunk) => {
|
|
69
|
+
// 可以发送流式消息
|
|
70
|
+
});
|
|
71
|
+
const result = await process;
|
|
72
|
+
yield {
|
|
73
|
+
id: uuidv4(),
|
|
74
|
+
type: 'stream_end',
|
|
75
|
+
source: this.id,
|
|
76
|
+
target: request.source,
|
|
77
|
+
correlation_id: correlationId,
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
result: result.stdout
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
84
|
+
yield {
|
|
85
|
+
id: uuidv4(),
|
|
86
|
+
type: 'response',
|
|
87
|
+
source: this.id,
|
|
88
|
+
target: request.source,
|
|
89
|
+
correlation_id: correlationId,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
error: {
|
|
92
|
+
code: 'EXECUTION_ERROR',
|
|
93
|
+
message: errorMessage
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 健康检查
|
|
100
|
+
*/
|
|
101
|
+
async health() {
|
|
102
|
+
try {
|
|
103
|
+
await execa(this.cliPath, ['--version'], { timeout: 5000 });
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BaseAgentAdapter } from './base.js';
|
|
2
|
+
import type { AgentMessage } from '../types/index.js';
|
|
3
|
+
interface ProcessConfig {
|
|
4
|
+
command: string;
|
|
5
|
+
args?: string[];
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare class ProcessAdapter extends BaseAgentAdapter {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
capabilities: string[];
|
|
13
|
+
private config;
|
|
14
|
+
constructor(id: string, name: string, capabilities: string[], config: ProcessConfig);
|
|
15
|
+
/**
|
|
16
|
+
* 调用进程执行任务
|
|
17
|
+
*/
|
|
18
|
+
invoke(request: AgentMessage): Promise<AgentMessage>;
|
|
19
|
+
/**
|
|
20
|
+
* 流式调用
|
|
21
|
+
*/
|
|
22
|
+
invokeStream(request: AgentMessage): AsyncGenerator<AgentMessage, void, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* 健康检查
|
|
25
|
+
*/
|
|
26
|
+
health(): Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { BaseAgentAdapter } from './base.js';
|
|
4
|
+
export class ProcessAdapter extends BaseAgentAdapter {
|
|
5
|
+
id;
|
|
6
|
+
name;
|
|
7
|
+
type = 'process';
|
|
8
|
+
capabilities;
|
|
9
|
+
config;
|
|
10
|
+
constructor(id, name, capabilities, config) {
|
|
11
|
+
super();
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.capabilities = capabilities;
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 调用进程执行任务
|
|
19
|
+
*/
|
|
20
|
+
async invoke(request) {
|
|
21
|
+
const task = request.payload?.task || '';
|
|
22
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
23
|
+
const timeout = (request.payload?.options?.timeout || 300) * 1000;
|
|
24
|
+
try {
|
|
25
|
+
// 构建参数:将任务作为 stdin 或参数传入
|
|
26
|
+
const args = this.config.args || [];
|
|
27
|
+
const result = await execa(this.config.command, [...args, task], {
|
|
28
|
+
timeout,
|
|
29
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
30
|
+
env: { ...process.env, ...this.config.env }
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
id: uuidv4(),
|
|
34
|
+
type: 'response',
|
|
35
|
+
source: this.id,
|
|
36
|
+
target: request.source,
|
|
37
|
+
correlation_id: correlationId,
|
|
38
|
+
timestamp: Date.now(),
|
|
39
|
+
result: result.stdout
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
44
|
+
return {
|
|
45
|
+
id: uuidv4(),
|
|
46
|
+
type: 'response',
|
|
47
|
+
source: this.id,
|
|
48
|
+
target: request.source,
|
|
49
|
+
correlation_id: correlationId,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
error: {
|
|
52
|
+
code: 'EXECUTION_ERROR',
|
|
53
|
+
message: errorMessage
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 流式调用
|
|
60
|
+
*/
|
|
61
|
+
async *invokeStream(request) {
|
|
62
|
+
const task = request.payload?.task || '';
|
|
63
|
+
const correlationId = request.correlation_id || uuidv4();
|
|
64
|
+
const timeout = (request.payload?.options?.timeout || 300) * 1000;
|
|
65
|
+
try {
|
|
66
|
+
const args = this.config.args || [];
|
|
67
|
+
const proc = execa(this.config.command, [...args, task], {
|
|
68
|
+
timeout,
|
|
69
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
70
|
+
env: { ...globalThis.process.env, ...this.config.env }
|
|
71
|
+
});
|
|
72
|
+
proc.stdout?.on('data', (_chunk) => {
|
|
73
|
+
// 可以发送流式消息
|
|
74
|
+
});
|
|
75
|
+
const result = await proc;
|
|
76
|
+
yield {
|
|
77
|
+
id: uuidv4(),
|
|
78
|
+
type: 'stream_end',
|
|
79
|
+
source: this.id,
|
|
80
|
+
target: request.source,
|
|
81
|
+
correlation_id: correlationId,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
result: result.stdout
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
88
|
+
yield {
|
|
89
|
+
id: uuidv4(),
|
|
90
|
+
type: 'response',
|
|
91
|
+
source: this.id,
|
|
92
|
+
target: request.source,
|
|
93
|
+
correlation_id: correlationId,
|
|
94
|
+
timestamp: Date.now(),
|
|
95
|
+
error: {
|
|
96
|
+
code: 'EXECUTION_ERROR',
|
|
97
|
+
message: errorMessage
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 健康检查
|
|
104
|
+
*/
|
|
105
|
+
async health() {
|
|
106
|
+
try {
|
|
107
|
+
await execa(this.config.command, ['--version'], { timeout: 5000 });
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// 尝试其他版本检查方式
|
|
112
|
+
try {
|
|
113
|
+
await execa(this.config.command, ['-v'], { timeout: 5000 });
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
package/dist/cli.d.ts
ADDED