@starlink-awaken/agentmesh 1.0.2 → 1.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.
- package/CHANGELOG.md +60 -41
- package/README.zh-CN.md +137 -167
- package/config/gateway.yaml +78 -0
- package/dist/src/adapters/base.d.ts +22 -0
- package/dist/src/adapters/base.js +10 -0
- package/dist/src/adapters/claude-code.d.ts +22 -0
- package/dist/src/adapters/claude-code.js +112 -0
- package/dist/src/adapters/openclaw.d.ts +22 -0
- package/dist/src/adapters/openclaw.js +110 -0
- package/dist/src/adapters/process.d.ts +28 -0
- package/dist/src/adapters/process.js +121 -0
- package/dist/src/cli/connect.d.ts +26 -0
- package/dist/src/cli/connect.js +544 -0
- package/dist/src/cli/setup.d.ts +2 -0
- package/dist/src/cli/setup.js +97 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +410 -0
- package/dist/src/core/agent-registry.d.ts +48 -0
- package/dist/src/core/agent-registry.js +295 -0
- package/dist/src/core/config.d.ts +59 -0
- package/dist/src/core/config.js +101 -0
- package/dist/src/core/context-manager.d.ts +52 -0
- package/dist/src/core/context-manager.js +165 -0
- package/dist/src/core/event-bus.d.ts +35 -0
- package/dist/src/core/event-bus.js +62 -0
- package/dist/src/core/logger.d.ts +14 -0
- package/dist/src/core/logger.js +57 -0
- package/dist/src/core/metrics.d.ts +87 -0
- package/dist/src/core/metrics.js +167 -0
- package/dist/src/core/router.d.ts +46 -0
- package/dist/src/core/router.js +90 -0
- package/dist/src/core/task-manager.d.ts +41 -0
- package/dist/src/core/task-manager.js +197 -0
- package/dist/src/core/vector-store.d.ts +37 -0
- package/dist/src/core/vector-store.js +175 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +105 -0
- package/dist/src/model-gateway/circuit-breaker.d.ts +21 -0
- package/dist/src/model-gateway/circuit-breaker.js +86 -0
- package/dist/src/model-gateway/health.d.ts +12 -0
- package/dist/src/model-gateway/health.js +80 -0
- package/dist/src/model-gateway/providers.d.ts +4 -0
- package/dist/src/model-gateway/providers.js +113 -0
- package/dist/src/model-gateway/quota.d.ts +4 -0
- package/dist/src/model-gateway/quota.js +107 -0
- package/dist/src/model-gateway/rate-limit.d.ts +12 -0
- package/dist/src/model-gateway/rate-limit.js +51 -0
- package/dist/src/model-gateway/retry.d.ts +14 -0
- package/dist/src/model-gateway/retry.js +48 -0
- package/dist/src/model-gateway/router.d.ts +4 -0
- package/dist/src/model-gateway/router.js +79 -0
- package/dist/src/model-gateway/routes.d.ts +2 -0
- package/dist/src/model-gateway/routes.js +172 -0
- package/dist/src/model-gateway/types.d.ts +47 -0
- package/dist/src/model-gateway/types.js +1 -0
- package/dist/src/routes/api.d.ts +2 -0
- package/dist/src/routes/api.js +128 -0
- package/dist/src/routes/websocket.d.ts +2 -0
- package/dist/src/routes/websocket.js +64 -0
- package/dist/src/types/index.d.ts +71 -0
- package/dist/src/types/index.js +1 -0
- package/dist/tests/core/context-manager.test.d.ts +1 -0
- package/dist/tests/core/context-manager.test.js +35 -0
- package/dist/tests/core/router.test.d.ts +1 -0
- package/dist/tests/core/router.test.js +79 -0
- package/dist/tests/model-gateway/circuit-breaker.test.d.ts +1 -0
- package/dist/tests/model-gateway/circuit-breaker.test.js +84 -0
- package/dist/tests/model-gateway/providers.test.d.ts +1 -0
- package/dist/tests/model-gateway/providers.test.js +80 -0
- package/dist/tests/model-gateway/quota.test.d.ts +1 -0
- package/dist/tests/model-gateway/quota.test.js +60 -0
- package/dist/tests/model-gateway/rate-limit.test.d.ts +1 -0
- package/dist/tests/model-gateway/rate-limit.test.js +42 -0
- package/dist/tests/model-gateway/retry.test.d.ts +1 -0
- package/dist/tests/model-gateway/retry.test.js +47 -0
- package/dist/tests/model-gateway/router.test.d.ts +1 -0
- package/dist/tests/model-gateway/router.test.js +108 -0
- package/dist/tests/model-gateway/routes.test.d.ts +1 -0
- package/dist/tests/model-gateway/routes.test.js +83 -0
- package/docs/api.md +187 -460
- package/docs/architecture.md +138 -0
- package/docs/configuration.md +188 -0
- package/package.json +3 -1
package/docs/api.md
CHANGED
|
@@ -1,566 +1,293 @@
|
|
|
1
|
-
#
|
|
1
|
+
# API Reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Base URL: `http://127.0.0.1:3000`
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Health & Status
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### `GET /health`
|
|
8
|
+
Health check with agent status overview.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## 认证
|
|
12
|
-
|
|
13
|
-
当前版本无需认证。生产环境建议添加 API Key 或 JWT 认证。
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## 端点概览
|
|
18
|
-
|
|
19
|
-
| 方法 | 路径 | 描述 |
|
|
20
|
-
|------|------|------|
|
|
21
|
-
| GET | `/health` | 健康检查 |
|
|
22
|
-
| POST | `/tasks` | 提交任务 |
|
|
23
|
-
| GET | `/tasks` | 获取所有任务 |
|
|
24
|
-
| GET | `/tasks/:taskId` | 获取任务状态 |
|
|
25
|
-
| POST | `/spaces` | 创建共享空间 |
|
|
26
|
-
| GET | `/spaces/:spaceId` | 获取共享空间 |
|
|
27
|
-
| GET | `/agents` | 获取 Agent 列表 |
|
|
28
|
-
| POST | `/agents` | 注册 Agent |
|
|
29
|
-
| GET | `/events` | Server-Sent Events 流 |
|
|
30
|
-
| GET | `/ws-info` | WebSocket 信息 |
|
|
31
|
-
| POST | `/broadcast` | 广播事件 |
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## 端点详情
|
|
36
|
-
|
|
37
|
-
### 1. 健康检查
|
|
38
|
-
|
|
39
|
-
检查网关状态和所有 Agent 的在线情况。
|
|
40
|
-
|
|
41
|
-
**请求**
|
|
42
|
-
```http
|
|
43
|
-
GET /health
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
**响应**
|
|
10
|
+
**Response:**
|
|
47
11
|
```json
|
|
48
12
|
{
|
|
49
13
|
"status": "ok",
|
|
50
|
-
"timestamp":
|
|
14
|
+
"timestamp": 1778935574177,
|
|
51
15
|
"agents": [
|
|
52
|
-
{
|
|
53
|
-
"id": "claude-code",
|
|
54
|
-
"name": "Claude Code",
|
|
55
|
-
"status": "online"
|
|
56
|
-
}
|
|
16
|
+
{"id": "claude-code", "name": "Claude Code", "status": "online"}
|
|
57
17
|
]
|
|
58
18
|
}
|
|
59
19
|
```
|
|
60
20
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### 2. 提交任务
|
|
21
|
+
### `GET /model-gateway/health`
|
|
22
|
+
Model gateway health with provider availability and quota summary.
|
|
64
23
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
**请求**
|
|
68
|
-
```http
|
|
69
|
-
POST /tasks
|
|
70
|
-
Content-Type: application/json
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
**请求体**
|
|
24
|
+
**Response:**
|
|
74
25
|
```json
|
|
75
26
|
{
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
27
|
+
"status": "ok",
|
|
28
|
+
"timestamp": 1778935574177,
|
|
29
|
+
"providers_available": [
|
|
30
|
+
{"name": "deepseek", "summary": "Balance: ¥561.18"}
|
|
31
|
+
],
|
|
32
|
+
"providers_unavailable": [
|
|
33
|
+
{"name": "codex", "summary": "Credits: 0"}
|
|
34
|
+
]
|
|
86
35
|
}
|
|
87
36
|
```
|
|
88
37
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
"id": "uuid-可选-会自动生成",
|
|
93
|
-
"type": "request",
|
|
94
|
-
"source": "api",
|
|
95
|
-
"target": "gateway",
|
|
96
|
-
"correlation_id": "uuid-可选",
|
|
97
|
-
"timestamp": 1708531200000,
|
|
98
|
-
"payload": {
|
|
99
|
-
"task": "任务描述",
|
|
100
|
-
"context": {
|
|
101
|
-
"shared_space_id": "空间ID-可选"
|
|
102
|
-
},
|
|
103
|
-
"files": ["文件路径-可选"],
|
|
104
|
-
"options": {
|
|
105
|
-
"stream": false,
|
|
106
|
-
"timeout": 300
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
38
|
+
### `GET /model-gateway/quota`
|
|
39
|
+
Real-time quota data from codexbar. Cached for 60 seconds.
|
|
111
40
|
|
|
112
|
-
|
|
41
|
+
**Response:**
|
|
113
42
|
```json
|
|
114
43
|
{
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
|
|
44
|
+
"codex": {
|
|
45
|
+
"provider": "codex",
|
|
46
|
+
"available": false,
|
|
47
|
+
"usedPercent": 98,
|
|
48
|
+
"summary": "Credits: 0, Secondary: 98%"
|
|
49
|
+
},
|
|
50
|
+
"deepseek": {
|
|
51
|
+
"provider": "deepseek",
|
|
52
|
+
"available": true,
|
|
53
|
+
"balance": 561.18,
|
|
54
|
+
"summary": "Balance: ¥561.18"
|
|
55
|
+
},
|
|
56
|
+
"ollama": {
|
|
57
|
+
"provider": "ollama",
|
|
58
|
+
"available": true,
|
|
59
|
+
"summary": "Local - always available"
|
|
127
60
|
}
|
|
128
61
|
}
|
|
129
62
|
```
|
|
130
63
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### 3. 获取所有任务
|
|
134
|
-
|
|
135
|
-
列出所有任务。
|
|
136
|
-
|
|
137
|
-
**请求**
|
|
138
|
-
```http
|
|
139
|
-
GET /tasks
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**响应**
|
|
143
|
-
```json
|
|
144
|
-
[
|
|
145
|
-
{
|
|
146
|
-
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
147
|
-
"status": "completed",
|
|
148
|
-
"assigned_agents": ["claude-code"],
|
|
149
|
-
"created_at": 1708531200000
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
### 4. 获取任务状态
|
|
157
|
-
|
|
158
|
-
查询特定任务的详细状态和结果。
|
|
159
|
-
|
|
160
|
-
**请求**
|
|
161
|
-
```http
|
|
162
|
-
GET /tasks/:taskId
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
**路径参数**
|
|
166
|
-
| 参数 | 类型 | 描述 |
|
|
167
|
-
|------|------|------|
|
|
168
|
-
| taskId | string | 任务 ID |
|
|
64
|
+
## Model Gateway
|
|
169
65
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
{
|
|
173
|
-
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
174
|
-
"status": "completed",
|
|
175
|
-
"assigned_agents": ["claude-code"],
|
|
176
|
-
"result": "任务执行结果",
|
|
177
|
-
"error": null,
|
|
178
|
-
"created_at": 1708531200000,
|
|
179
|
-
"updated_at": 1708531200100
|
|
180
|
-
}
|
|
181
|
-
```
|
|
66
|
+
### `GET /v1/models`
|
|
67
|
+
List available models across all configured providers.
|
|
182
68
|
|
|
183
|
-
|
|
69
|
+
**Response:**
|
|
184
70
|
```json
|
|
185
71
|
{
|
|
186
|
-
"
|
|
187
|
-
|
|
188
|
-
"
|
|
189
|
-
|
|
72
|
+
"object": "list",
|
|
73
|
+
"data": [
|
|
74
|
+
{"id": "deepseek-chat", "object": "model", "owned_by": "deepseek"},
|
|
75
|
+
{"id": "deepseek-v4-pro", "object": "model", "owned_by": "deepseek"},
|
|
76
|
+
{"id": "gpt-5.1", "object": "model", "owned_by": "openai"},
|
|
77
|
+
{"id": "o4-mini", "object": "model", "owned_by": "openai"},
|
|
78
|
+
{"id": "qwen3:14b", "object": "model", "owned_by": "ollama"}
|
|
79
|
+
]
|
|
190
80
|
}
|
|
191
81
|
```
|
|
192
82
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
### 5. 创建共享空间
|
|
196
|
-
|
|
197
|
-
创建一个用于多 Agent 协作的共享上下文空间。
|
|
198
|
-
|
|
199
|
-
**请求**
|
|
200
|
-
```http
|
|
201
|
-
POST /spaces
|
|
202
|
-
Content-Type: application/json
|
|
203
|
-
```
|
|
83
|
+
### `POST /v1/chat/completions`
|
|
84
|
+
Standard OpenAI-compatible chat completions. Supports streaming (SSE).
|
|
204
85
|
|
|
205
|
-
|
|
86
|
+
**Request:**
|
|
206
87
|
```json
|
|
207
88
|
{
|
|
208
|
-
"
|
|
209
|
-
|
|
210
|
-
"
|
|
211
|
-
|
|
89
|
+
"model": "deepseek-chat",
|
|
90
|
+
"messages": [
|
|
91
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
92
|
+
{"role": "user", "content": "Hello!"}
|
|
93
|
+
],
|
|
94
|
+
"stream": false,
|
|
95
|
+
"temperature": 0.7,
|
|
96
|
+
"max_tokens": 1024,
|
|
97
|
+
"tools": []
|
|
212
98
|
}
|
|
213
99
|
```
|
|
214
100
|
|
|
215
|
-
|
|
101
|
+
**Response (non-streaming):**
|
|
216
102
|
```json
|
|
217
103
|
{
|
|
218
|
-
"
|
|
104
|
+
"id": "chatcmpl-xxx",
|
|
105
|
+
"object": "chat.completion",
|
|
106
|
+
"model": "deepseek-chat",
|
|
107
|
+
"choices": [
|
|
108
|
+
{
|
|
109
|
+
"index": 0,
|
|
110
|
+
"message": {
|
|
111
|
+
"role": "assistant",
|
|
112
|
+
"content": "Hello! How can I help you today?"
|
|
113
|
+
},
|
|
114
|
+
"finish_reason": "stop"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"usage": {
|
|
118
|
+
"prompt_tokens": 20,
|
|
119
|
+
"completion_tokens": 10,
|
|
120
|
+
"total_tokens": 30
|
|
121
|
+
}
|
|
219
122
|
}
|
|
220
123
|
```
|
|
221
124
|
|
|
222
|
-
|
|
125
|
+
**Streaming:** Returns `text/event-stream` with SSE chunks.
|
|
223
126
|
|
|
224
|
-
###
|
|
127
|
+
### `POST /v1/responses`
|
|
128
|
+
Codex Desktop Responses API adapter. Converts between Responses API and Chat Completions.
|
|
225
129
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
**请求**
|
|
229
|
-
```http
|
|
230
|
-
GET /spaces/:spaceId
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
**路径参数**
|
|
234
|
-
| 参数 | 类型 | 描述 |
|
|
235
|
-
|------|------|------|
|
|
236
|
-
| spaceId | string | 空间 ID |
|
|
237
|
-
|
|
238
|
-
**响应**
|
|
130
|
+
**Request:**
|
|
239
131
|
```json
|
|
240
132
|
{
|
|
241
|
-
"
|
|
242
|
-
"
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
"
|
|
248
|
-
"
|
|
133
|
+
"model": "deepseek-v4-pro",
|
|
134
|
+
"input": [
|
|
135
|
+
{"role": "system", "content": "You are a coding assistant."},
|
|
136
|
+
{"role": "user", "content": "Write a sorting function"}
|
|
137
|
+
],
|
|
138
|
+
"instructions": "Be concise.",
|
|
139
|
+
"stream": false,
|
|
140
|
+
"tools": []
|
|
249
141
|
}
|
|
250
142
|
```
|
|
251
143
|
|
|
252
|
-
|
|
144
|
+
**Response:**
|
|
253
145
|
```json
|
|
254
146
|
{
|
|
255
|
-
"
|
|
256
|
-
|
|
257
|
-
|
|
147
|
+
"id": "resp_xxx",
|
|
148
|
+
"object": "response",
|
|
149
|
+
"model": "deepseek-v4-pro",
|
|
150
|
+
"output": [
|
|
151
|
+
{
|
|
152
|
+
"type": "message",
|
|
153
|
+
"role": "assistant",
|
|
154
|
+
"content": [
|
|
155
|
+
{
|
|
156
|
+
"type": "output_text",
|
|
157
|
+
"text": "Here is a sorting function...\n\n```python\ndef sort(arr):...\n```"
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"usage": {
|
|
163
|
+
"input_tokens": 30,
|
|
164
|
+
"output_tokens": 150,
|
|
165
|
+
"total_tokens": 180
|
|
258
166
|
}
|
|
259
167
|
}
|
|
260
168
|
```
|
|
261
169
|
|
|
262
|
-
|
|
170
|
+
**Input Mapping:**
|
|
171
|
+
- `input[].role` → `messages[].role`
|
|
172
|
+
- `input[].content` (text/list) → `messages[].content` (string)
|
|
173
|
+
- `input[].type: "message"` → message entry
|
|
174
|
+
- `instructions` → prepended system message
|
|
263
175
|
|
|
264
|
-
|
|
176
|
+
**Output Mapping:**
|
|
177
|
+
- Chat `choices[0].message.content` → Responses `output[].content[].text`
|
|
178
|
+
- Chat `choices[0].message.tool_calls` → Responses `output[].type: "function_call"`
|
|
265
179
|
|
|
266
|
-
|
|
180
|
+
## Agent Management
|
|
267
181
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
GET /agents
|
|
271
|
-
```
|
|
182
|
+
### `GET /agents`
|
|
183
|
+
List all registered agents.
|
|
272
184
|
|
|
273
|
-
|
|
185
|
+
**Response:**
|
|
274
186
|
```json
|
|
275
187
|
[
|
|
276
188
|
{
|
|
277
189
|
"id": "claude-code",
|
|
278
190
|
"name": "Claude Code",
|
|
279
191
|
"type": "claude-code",
|
|
280
|
-
"capabilities": [
|
|
281
|
-
"code-generation",
|
|
282
|
-
"code-review",
|
|
283
|
-
"debugging",
|
|
284
|
-
"refactoring",
|
|
285
|
-
"documentation",
|
|
286
|
-
"file-operations"
|
|
287
|
-
],
|
|
192
|
+
"capabilities": ["code-generation", "code-review"],
|
|
288
193
|
"status": "online",
|
|
289
|
-
"lastSeen":
|
|
194
|
+
"lastSeen": 1778935574177
|
|
290
195
|
}
|
|
291
196
|
]
|
|
292
197
|
```
|
|
293
198
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
### 8. 注册 Agent
|
|
199
|
+
### `POST /agents`
|
|
200
|
+
Register a new agent.
|
|
297
201
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
**请求**
|
|
301
|
-
```http
|
|
302
|
-
POST /agents
|
|
303
|
-
Content-Type: application/json
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
**请求体**
|
|
202
|
+
**Request:**
|
|
307
203
|
```json
|
|
308
204
|
{
|
|
309
205
|
"id": "my-agent",
|
|
310
206
|
"name": "My Custom Agent",
|
|
311
|
-
"type": "
|
|
312
|
-
"capabilities": ["code-generation"
|
|
313
|
-
"endpoint": "http://
|
|
314
|
-
}
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
**响应** (201 Created)
|
|
318
|
-
```json
|
|
319
|
-
{
|
|
320
|
-
"id": "my-agent",
|
|
321
|
-
"status": "registered"
|
|
207
|
+
"type": "process",
|
|
208
|
+
"capabilities": ["code-generation"],
|
|
209
|
+
"endpoint": "http://127.0.0.1:8080"
|
|
322
210
|
}
|
|
323
211
|
```
|
|
324
212
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
### 9. Server-Sent Events (SSE)
|
|
213
|
+
### `POST /tasks`
|
|
214
|
+
Submit a task for agent execution.
|
|
328
215
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
**请求**
|
|
332
|
-
```http
|
|
333
|
-
GET /events?taskId=xxx&spaceId=xxx
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
**查询参数**
|
|
337
|
-
| 参数 | 类型 | 描述 |
|
|
338
|
-
|------|------|------|
|
|
339
|
-
| taskId | string | 可选 - 订阅特定任务的事件 |
|
|
340
|
-
| spaceId | string | 可选 - 订阅特定空间的事件 |
|
|
341
|
-
|
|
342
|
-
**响应**
|
|
343
|
-
```http
|
|
344
|
-
HTTP/1.1 200 OK
|
|
345
|
-
Content-Type: text/event-stream
|
|
346
|
-
Cache-Control: no-cache
|
|
347
|
-
Connection: keep-alive
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
**事件格式**
|
|
351
|
-
```json
|
|
352
|
-
data: {"type": "connected", "client_id": "xxx"}
|
|
353
|
-
|
|
354
|
-
data: {"type": "task_status", "task": {...}}
|
|
355
|
-
|
|
356
|
-
data: {"type": "welcome", "agents": [...]}
|
|
357
|
-
|
|
358
|
-
data: {"type": "heartbeat", "timestamp": 1708531200000}
|
|
359
|
-
|
|
360
|
-
data: {"type": "task.submitted", "task_id": "xxx", "timestamp": 1708531200000}
|
|
361
|
-
|
|
362
|
-
data: {"type": "task.completed", "task_id": "xxx", "result": "xxx", "timestamp": 1708531200000}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
---
|
|
366
|
-
|
|
367
|
-
### 10. 广播事件
|
|
368
|
-
|
|
369
|
-
向所有连接的客户端广播事件。
|
|
370
|
-
|
|
371
|
-
**请求**
|
|
372
|
-
```http
|
|
373
|
-
POST /broadcast
|
|
374
|
-
Content-Type: application/json
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
**请求体**
|
|
216
|
+
**Request:**
|
|
378
217
|
```json
|
|
379
218
|
{
|
|
380
|
-
"type": "
|
|
381
|
-
"
|
|
382
|
-
|
|
219
|
+
"type": "request",
|
|
220
|
+
"source": "api",
|
|
221
|
+
"target": "gateway",
|
|
222
|
+
"payload": {
|
|
223
|
+
"task": "Help me write a sorting algorithm",
|
|
224
|
+
"options": { "stream": false, "timeout": 300 }
|
|
383
225
|
}
|
|
384
226
|
}
|
|
385
227
|
```
|
|
386
228
|
|
|
387
|
-
|
|
229
|
+
### `GET /tasks`
|
|
230
|
+
List all tasks.
|
|
231
|
+
|
|
232
|
+
### `GET /tasks/:taskId`
|
|
233
|
+
Task status and result.
|
|
234
|
+
|
|
235
|
+
**Response:**
|
|
388
236
|
```json
|
|
389
237
|
{
|
|
390
|
-
"
|
|
391
|
-
"
|
|
238
|
+
"id": "task-xxx",
|
|
239
|
+
"status": "completed",
|
|
240
|
+
"assigned_agents": ["claude-code"],
|
|
241
|
+
"result": "...",
|
|
242
|
+
"created_at": 1778935574177,
|
|
243
|
+
"updated_at": 1778935580000
|
|
392
244
|
}
|
|
393
245
|
```
|
|
394
246
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
## 数据类型
|
|
398
|
-
|
|
399
|
-
### AgentMessage
|
|
400
|
-
|
|
401
|
-
```typescript
|
|
402
|
-
interface AgentMessage {
|
|
403
|
-
// 基础字段
|
|
404
|
-
id: string;
|
|
405
|
-
type: 'request' | 'response' | 'event' | 'stream' | 'stream_end';
|
|
406
|
-
source: string;
|
|
407
|
-
target: string;
|
|
408
|
-
correlation_id: string;
|
|
409
|
-
timestamp: number;
|
|
410
|
-
|
|
411
|
-
// 请求内容
|
|
412
|
-
payload?: {
|
|
413
|
-
task?: string;
|
|
414
|
-
context?: {
|
|
415
|
-
shared_space_id: string;
|
|
416
|
-
history?: string[];
|
|
417
|
-
artifacts?: string[];
|
|
418
|
-
};
|
|
419
|
-
files?: string[];
|
|
420
|
-
options?: {
|
|
421
|
-
stream?: boolean;
|
|
422
|
-
timeout?: number;
|
|
423
|
-
};
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
// 事件驱动
|
|
427
|
-
event_type?: string;
|
|
428
|
-
event_data?: Record<string, unknown>;
|
|
429
|
-
|
|
430
|
-
// 响应
|
|
431
|
-
result?: unknown;
|
|
432
|
-
error?: {
|
|
433
|
-
code: string;
|
|
434
|
-
message: string;
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
```
|
|
247
|
+
## Spaces
|
|
438
248
|
|
|
439
|
-
###
|
|
440
|
-
|
|
441
|
-
```typescript
|
|
442
|
-
interface Task {
|
|
443
|
-
id: string;
|
|
444
|
-
status: 'pending' | 'assigned' | 'running' | 'completed' | 'failed';
|
|
445
|
-
message: AgentMessage;
|
|
446
|
-
assignedAgents: string[];
|
|
447
|
-
result?: unknown;
|
|
448
|
-
error?: {
|
|
449
|
-
code: string;
|
|
450
|
-
message: string;
|
|
451
|
-
};
|
|
452
|
-
createdAt: number;
|
|
453
|
-
updatedAt: number;
|
|
454
|
-
}
|
|
455
|
-
```
|
|
249
|
+
### `POST /spaces`
|
|
250
|
+
Create a shared context space.
|
|
456
251
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
id: string;
|
|
462
|
-
name: string;
|
|
463
|
-
type: string;
|
|
464
|
-
capabilities: string[];
|
|
465
|
-
status: 'online' | 'offline' | 'busy';
|
|
466
|
-
endpoint?: string;
|
|
467
|
-
lastSeen: number;
|
|
252
|
+
**Request:**
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"metadata": { "name": "Project A", "createdBy": "cli" }
|
|
468
256
|
}
|
|
469
257
|
```
|
|
470
258
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
## 错误码
|
|
474
|
-
|
|
475
|
-
| 错误码 | HTTP 状态码 | 描述 |
|
|
476
|
-
|--------|-------------|------|
|
|
477
|
-
| TASK_NOT_FOUND | 404 | 任务不存在 |
|
|
478
|
-
| TASK_FAILED | 500 | 任务执行失败 |
|
|
479
|
-
| SPACE_NOT_FOUND | 404 | 共享空间不存在 |
|
|
480
|
-
| AGENT_NOT_FOUND | 404 | Agent 不存在 |
|
|
481
|
-
| INVALID_REQUEST | 400 | 请求参数无效 |
|
|
482
|
-
|
|
483
|
-
---
|
|
484
|
-
|
|
485
|
-
## 示例
|
|
486
|
-
|
|
487
|
-
### cURL
|
|
488
|
-
|
|
489
|
-
```bash
|
|
490
|
-
# 健康检查
|
|
491
|
-
curl http://localhost:3000/health
|
|
492
|
-
|
|
493
|
-
# 提交任务
|
|
494
|
-
curl -X POST http://localhost:3000/tasks \
|
|
495
|
-
-H "Content-Type: application/json" \
|
|
496
|
-
-d '{"payload": {"task": "帮我写一个排序算法"}}'
|
|
497
|
-
|
|
498
|
-
# 查询任务状态
|
|
499
|
-
curl http://localhost:3000/tasks/{task_id}
|
|
500
|
-
|
|
501
|
-
# 获取 Agent 列表
|
|
502
|
-
curl http://localhost:3000/agents
|
|
503
|
-
|
|
504
|
-
# 创建共享空间
|
|
505
|
-
curl -X POST http://localhost:3000/spaces \
|
|
506
|
-
-H "Content-Type: application/json" \
|
|
507
|
-
-d '{"metadata": {"name": "项目A"}}'
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
### JavaScript
|
|
259
|
+
**Response:** `{ "space_id": "space-xxx" }`
|
|
511
260
|
|
|
512
|
-
|
|
513
|
-
|
|
261
|
+
### `GET /spaces/:spaceId`
|
|
262
|
+
Shared space details.
|
|
514
263
|
|
|
515
|
-
|
|
516
|
-
async function submitTask(task) {
|
|
517
|
-
const response = await fetch(`${baseUrl}/tasks`, {
|
|
518
|
-
method: 'POST',
|
|
519
|
-
headers: { 'Content-Type': 'application/json' },
|
|
520
|
-
body: JSON.stringify({ payload: { task } })
|
|
521
|
-
});
|
|
522
|
-
return response.json();
|
|
523
|
-
}
|
|
264
|
+
## Error Format
|
|
524
265
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
};
|
|
532
|
-
return eventSource;
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"error": {
|
|
269
|
+
"code": "PROVIDER_ERROR",
|
|
270
|
+
"message": "DeepSeek: insufficient_quota"
|
|
271
|
+
}
|
|
533
272
|
}
|
|
534
273
|
```
|
|
535
274
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
## CLI 命令
|
|
539
|
-
|
|
540
|
-
安装 CLI 后可使用以下命令:
|
|
541
|
-
|
|
542
|
-
```bash
|
|
543
|
-
# 列出所有 Agent
|
|
544
|
-
agent-gateway agents
|
|
545
|
-
|
|
546
|
-
# 提交通用任务(自动路由)
|
|
547
|
-
agent-gateway task 帮我写一个排序算法
|
|
275
|
+
### Error Codes
|
|
548
276
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
agent-gateway tasks
|
|
557
|
-
|
|
558
|
-
# 检查 Gateway 状态
|
|
559
|
-
agent-gateway health
|
|
560
|
-
```
|
|
277
|
+
| Code | HTTP Status | Description |
|
|
278
|
+
|------|-------------|-------------|
|
|
279
|
+
| `TASK_FAILED` | 500 | Task processing failed |
|
|
280
|
+
| `TASK_NOT_FOUND` | 404 | Task ID not found |
|
|
281
|
+
| `SPACE_NOT_FOUND` | 404 | Space ID not found |
|
|
282
|
+
| Provider errors | 502 | Upstream provider error |
|
|
283
|
+
| No provider | 503 | All providers unavailable |
|
|
561
284
|
|
|
562
|
-
|
|
285
|
+
## Routing
|
|
563
286
|
|
|
564
|
-
|
|
287
|
+
The model router selects providers based on:
|
|
288
|
+
1. Model name pattern matching
|
|
289
|
+
2. Quota availability (via codexbar)
|
|
290
|
+
3. API key presence
|
|
291
|
+
4. Fallback chain priority
|
|
565
292
|
|
|
566
|
-
|
|
293
|
+
See [Configuration Guide](./configuration.md) for routing rules.
|