agents-bridge 0.1.36 → 0.1.38
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/.env.example +20 -20
- package/LICENSE +21 -21
- package/README.md +312 -312
- package/bin/agent-bridge.mjs +13 -13
- package/config.example.json +208 -208
- package/config.multi-agent.example.json +113 -113
- package/dist/cli/botlink-openapi.d.ts +2 -0
- package/dist/cli/botlink-openapi.d.ts.map +1 -1
- package/dist/cli/botlink-openapi.js.map +1 -1
- package/dist/cli/cmd-contacts.js +1 -1
- package/dist/cli/cmd-contacts.js.map +1 -1
- package/dist/cli/cmd-list-groups.d.ts.map +1 -1
- package/dist/cli/cmd-list-groups.js +3 -2
- package/dist/cli/cmd-list-groups.js.map +1 -1
- package/dist/cli/cmd-schedules.d.ts +7 -0
- package/dist/cli/cmd-schedules.d.ts.map +1 -0
- package/dist/cli/cmd-schedules.js +137 -0
- package/dist/cli/cmd-schedules.js.map +1 -0
- package/dist/cli/cmd-send-message.d.ts.map +1 -1
- package/dist/cli/cmd-send-message.js +1 -0
- package/dist/cli/cmd-send-message.js.map +1 -1
- package/dist/cli/cmd-update.js +70 -70
- package/dist/cli/run-main.d.ts +9 -1
- package/dist/cli/run-main.d.ts.map +1 -1
- package/dist/cli/run-main.js +169 -122
- package/dist/cli/run-main.js.map +1 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +16 -0
- package/dist/entry.js.map +1 -1
- package/package.json +69 -69
package/README.md
CHANGED
|
@@ -1,312 +1,312 @@
|
|
|
1
|
-
# agents-bridge
|
|
2
|
-
|
|
3
|
-
本地 Agent 网关,部署在客户本地机器上,通过长轮询连接 botlink 平台,把消息转发给本机运行的 Claude Code / Codex 等 Agent 运行时。
|
|
4
|
-
|
|
5
|
-
核心特点:
|
|
6
|
-
|
|
7
|
-
- 客户端主动外连,无需暴露入站端口
|
|
8
|
-
- 支持 `claude-cli/...`、`codex-cli/...`、`qwen-cli/...`、`wukong-cli/...` 这类 CLI 模型引用
|
|
9
|
-
- 支持多 agent 配置与按绑定规则路由
|
|
10
|
-
- 提供 `onboard`、`add-agent`、`doctor`、`logs`、`config` 等运维命令
|
|
11
|
-
- 支持前台运行和守护进程模式
|
|
12
|
-
|
|
13
|
-
## 架构概览
|
|
14
|
-
|
|
15
|
-
链路可以简化为:
|
|
16
|
-
|
|
17
|
-
`botlink cloud -> 长轮询 -> agents-bridge -> 本地 CLI backend / Agent Runtime`
|
|
18
|
-
|
|
19
|
-
其中:
|
|
20
|
-
|
|
21
|
-
- botlink 负责云端消息入口
|
|
22
|
-
- agents-bridge 负责轮询、路由、会话管理、日志和文件中转
|
|
23
|
-
- 本地 Agent Runtime 负责实际执行 Claude Code、Codex 等 CLI
|
|
24
|
-
|
|
25
|
-
## 快速开始
|
|
26
|
-
|
|
27
|
-
### 方式 A:npm 全局安装
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install -g agents-bridge@latest
|
|
31
|
-
|
|
32
|
-
# 交互式初始化:输入 gateway URL、bot token、选择模型
|
|
33
|
-
agents-bridge onboard
|
|
34
|
-
|
|
35
|
-
# 前台启动
|
|
36
|
-
agents-bridge start
|
|
37
|
-
|
|
38
|
-
# 或后台启动
|
|
39
|
-
agents-bridge start --daemon
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### 方式 B:Docker Compose
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
cp .env.example .env
|
|
46
|
-
# 编辑 .env,填写 GATEWAY_URL、BOT_TOKEN 等变量
|
|
47
|
-
|
|
48
|
-
docker compose up -d
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
`docker-compose.yml` 默认会:
|
|
52
|
-
|
|
53
|
-
- 挂载 `${WORKSPACE_DIR:-./workspace}` 到容器内 `/workspace`
|
|
54
|
-
- 持久化 `/root/.agent-bridge`
|
|
55
|
-
- 通过环境变量覆盖网关地址、Bot Token 和日志级别
|
|
56
|
-
|
|
57
|
-
### 方式 C:源码运行
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
git clone <repo-url>
|
|
61
|
-
cd agent-bridge
|
|
62
|
-
pnpm install
|
|
63
|
-
pnpm build
|
|
64
|
-
cp config.example.json config.json
|
|
65
|
-
# 编辑 config.json
|
|
66
|
-
node dist/entry.js start
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
开发模式:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
pnpm dev
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## CLI 命令
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
agents-bridge start # 前台启动
|
|
79
|
-
agents-bridge start --daemon # 后台启动
|
|
80
|
-
agents-bridge start -c ./config.json # 指定配置文件
|
|
81
|
-
agents-bridge stop # 停止守护进程
|
|
82
|
-
agents-bridge restart # 重启
|
|
83
|
-
agents-bridge reload # 热加载配置
|
|
84
|
-
agents-bridge status # 查看运行状态
|
|
85
|
-
agents-bridge onboard # 交互式初始化
|
|
86
|
-
agents-bridge add-agent # 交互式追加一个 agent
|
|
87
|
-
agents-bridge add-agent --account-id office-bot
|
|
88
|
-
agents-bridge add-agent office-codex --model codex-cli/gpt-5.5 --workspace D:\workspace\office --account-id office-bot --no-interactive
|
|
89
|
-
agents-bridge add-agent --create-account office-bot --account-gateway-url https://botlink.example.com --account-bot-token bot_xxx
|
|
90
|
-
agents-bridge list-groups --account-id office-bot --json
|
|
91
|
-
agents-bridge list-members --account-id office-bot --group-id conv_xxx
|
|
92
|
-
agents-bridge list-members --account-id office-bot --chat-id -100123456789 --json
|
|
93
|
-
agents-bridge send-message --account-id office-bot --group-id conv_xxx --text "hello"
|
|
94
|
-
agents-bridge doctor # 检查环境、CLI、API Key 和配置
|
|
95
|
-
agents-bridge logs # 查看最近日志
|
|
96
|
-
agents-bridge config # 输出当前配置
|
|
97
|
-
agents-bridge update # 更新已安装的 CLI
|
|
98
|
-
agents-bridge version # 查看版本
|
|
99
|
-
agents-bridge help # 查看帮助
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 配置
|
|
103
|
-
|
|
104
|
-
### 配置文件搜索顺序
|
|
105
|
-
|
|
106
|
-
当前实现会按以下顺序读取第一个存在的配置文件:
|
|
107
|
-
|
|
108
|
-
1. `agents-bridge start -c /path/to/config.json`
|
|
109
|
-
2. 环境变量 `AGENT_BRIDGE_CONFIG`
|
|
110
|
-
3. 当前目录 `./config.json`
|
|
111
|
-
4. 用户目录 `~/.agent-bridge/config.json`
|
|
112
|
-
|
|
113
|
-
### 最小配置示例
|
|
114
|
-
|
|
115
|
-
```json
|
|
116
|
-
{
|
|
117
|
-
"channels": {
|
|
118
|
-
"botlink": {
|
|
119
|
-
"accounts": {
|
|
120
|
-
"default": {
|
|
121
|
-
"gateway_url": "https://your-botlink.com",
|
|
122
|
-
"bot_token": "bot_xxx",
|
|
123
|
-
"poll_timeout": 30,
|
|
124
|
-
"retry_interval": 5,
|
|
125
|
-
"max_retry_interval": 60
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
"agents": {
|
|
131
|
-
"defaults": {
|
|
132
|
-
"model": {
|
|
133
|
-
"primary": "claude-cli/opus-4.6"
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
"list": [
|
|
137
|
-
{
|
|
138
|
-
"id": "default",
|
|
139
|
-
"default": true
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
},
|
|
143
|
-
"bindings": [
|
|
144
|
-
{
|
|
145
|
-
"agentId": "default",
|
|
146
|
-
"match": {
|
|
147
|
-
"channel": "*"
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
完整示例见:
|
|
155
|
-
|
|
156
|
-
- [config.example.json](./config.example.json)
|
|
157
|
-
- [config.multi-agent.example.json](./config.multi-agent.example.json)
|
|
158
|
-
|
|
159
|
-
botlink 配置读取时兼容旧的顶层 `gateway_url` / `bot_token` 写法,但新的配置写入会统一落到 `channels.botlink.accounts`。
|
|
160
|
-
|
|
161
|
-
兼容性说明:
|
|
162
|
-
|
|
163
|
-
- 老配置仍可继续使用:顶层 `channels.botlink.gateway_url` / `bot_token` 仍然会被读取
|
|
164
|
-
- 新示例配置统一使用 `channels.botlink.accounts` 格式
|
|
165
|
-
- `add-agent` 会兼容读取老配置,并在保存时自动迁移成 `channels.botlink.accounts`
|
|
166
|
-
- `onboard` 会先备份已有配置,再按新的 `channels.botlink.accounts` 格式重建配置
|
|
167
|
-
|
|
168
|
-
### 关键配置项
|
|
169
|
-
|
|
170
|
-
- `channels.botlink.accounts.<accountId>.gateway_url`:botlink 网关地址
|
|
171
|
-
- `channels.botlink.accounts.<accountId>.bot_token`:bot token
|
|
172
|
-
- `agents.defaults.model.primary`:主模型引用,例如 `claude-cli/opus-4.6`、`codex-cli/gpt-5.4`、`qwen-cli/qwen3-coder-plus` 或 `wukong-cli/wukong-coder`
|
|
173
|
-
- `agents.defaults.model.fallbacks`:备用模型链
|
|
174
|
-
- `agents.defaults.cliBackends`:CLI backend 启动参数与运行模式
|
|
175
|
-
- `agents.list`:命名 agent 列表
|
|
176
|
-
- `bindings`:消息路由规则,可按 `channel`、`accountId`、`peer.id` 等条件匹配
|
|
177
|
-
- `files.temp_dir`:文件中转目录
|
|
178
|
-
- `logging.level`:日志级别
|
|
179
|
-
|
|
180
|
-
### 多 agent 配置
|
|
181
|
-
|
|
182
|
-
多 agent 模式通过 `agents.list` 定义运行实例,通过 `bindings` 决定消息路由到哪个 agent。
|
|
183
|
-
|
|
184
|
-
追加 agent 时,也可以直接运行:
|
|
185
|
-
|
|
186
|
-
```bash
|
|
187
|
-
agents-bridge add-agent
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
该命令会在现有配置上:
|
|
191
|
-
|
|
192
|
-
- 追加一个 `agents.list[]` 项
|
|
193
|
-
- 可选绑定已有 botlink `accountId`
|
|
194
|
-
- 可选创建新的 botlink account 并立刻绑定
|
|
195
|
-
- 兼容旧的顶层 botlink 配置写法,并在保存时自动迁移成 `channels.botlink.accounts.default`
|
|
196
|
-
- 写入前自动备份原配置文件
|
|
197
|
-
|
|
198
|
-
如果现有 account 已被其他 agent 占用,交互流程会提示该 account 当前绑定到哪个 agent,并允许直接创建新的 account 后继续绑定。
|
|
199
|
-
|
|
200
|
-
也可以显式指定:
|
|
201
|
-
|
|
202
|
-
```bash
|
|
203
|
-
agents-bridge add-agent --account-id office-bot
|
|
204
|
-
agents-bridge add-agent --create-account office-bot --account-gateway-url https://botlink.example.com --account-bot-token bot_xxx
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
例如:
|
|
208
|
-
|
|
209
|
-
- 一个 bot 绑定到 Codex
|
|
210
|
-
- 一个 bot 绑定到 Claude Code
|
|
211
|
-
- 不同工作区使用不同 `workspace`
|
|
212
|
-
- 通过预置 `cliSessionId` 复用既有 CLI 会话
|
|
213
|
-
|
|
214
|
-
详见 [config.multi-agent.example.json](./config.multi-agent.example.json)。
|
|
215
|
-
|
|
216
|
-
### 环境变量覆盖
|
|
217
|
-
|
|
218
|
-
环境变量可覆盖配置文件中的对应值:
|
|
219
|
-
|
|
220
|
-
| 环境变量 | 覆盖字段 | 说明 |
|
|
221
|
-
|---|---|---|
|
|
222
|
-
| `AGENT_BRIDGE_CONFIG` | 配置文件路径 | 指定要加载的 `config.json` |
|
|
223
|
-
| `AGENT_BRIDGE_GATEWAY_URL` | `channels.botlink.accounts.default.gateway_url` 或旧格式 `channels.botlink.gateway_url` | 优先覆盖默认 botlink 账号;旧配置会覆盖顶层网关地址 |
|
|
224
|
-
| `AGENT_BRIDGE_BOT_TOKEN` | `channels.botlink.accounts.default.bot_token` 或旧格式 `channels.botlink.bot_token` | 优先覆盖默认 botlink 账号;旧配置会覆盖顶层 Bot Token |
|
|
225
|
-
| `AGENT_BRIDGE_LOG_LEVEL` | `logging.level` | 日志级别 |
|
|
226
|
-
| `AGENT_BRIDGE_TEMP_DIR` | `files.temp_dir` | 临时文件目录 |
|
|
227
|
-
| `ANTHROPIC_API_KEY` | 环境变量 | 供诊断或后续 API 模式使用 |
|
|
228
|
-
| `OPENAI_API_KEY` | 环境变量 | 供诊断或后续 API 模式使用 |
|
|
229
|
-
|
|
230
|
-
## 模型与运行模式
|
|
231
|
-
|
|
232
|
-
当前消息执行链路仅支持 CLI 模式模型,也就是:
|
|
233
|
-
|
|
234
|
-
- `claude-cli/...`
|
|
235
|
-
- `codex-cli/...`
|
|
236
|
-
- `qwen-cli/...`
|
|
237
|
-
- `wukong-cli/...`
|
|
238
|
-
|
|
239
|
-
配置层已经允许 `anthropic/...`、`openai/...` 这类 API provider 引用,但当前主运行时尚未实现 API 模式;若把它们设为主模型,程序会返回“当前仅支持 CLI 模式模型”。
|
|
240
|
-
|
|
241
|
-
内置 `wukong-cli` 默认按通用 JSON exec 模式启动:
|
|
242
|
-
|
|
243
|
-
```bash
|
|
244
|
-
wukong-cli --output-format json --no-color --quiet --model <model> --prompt "<prompt>"
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
如果本地悟空 CLI 的可执行文件不在 `PATH`,可以把 `command` 覆盖为完整路径。若参数不同,可以在 `agents.defaults.cliBackends.wukong-cli` 或单个 agent 的 `cliBackends.wukong-cli` 中覆盖 `command`、`args`、`modelArg`、`promptArg` 等字段。
|
|
248
|
-
|
|
249
|
-
## 数据目录
|
|
250
|
-
|
|
251
|
-
运行时数据默认保存在 `~/.agent-bridge/`:
|
|
252
|
-
|
|
253
|
-
```text
|
|
254
|
-
~/.agent-bridge/
|
|
255
|
-
├── config.json
|
|
256
|
-
├── agent-bridge.pid
|
|
257
|
-
├── agents/
|
|
258
|
-
│ └── <agentId>/
|
|
259
|
-
│ └── cli-sessions.json
|
|
260
|
-
├── data/
|
|
261
|
-
│ ├── files/
|
|
262
|
-
│ ├── logs/
|
|
263
|
-
│ └── sessions/
|
|
264
|
-
└── skills/
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
其中:
|
|
268
|
-
|
|
269
|
-
- `config.json`:全局配置文件
|
|
270
|
-
- `agent-bridge.pid`:守护进程 PID 文件
|
|
271
|
-
- `agents/<agentId>/cli-sessions.json`:每个 agent 的 CLI 会话映射
|
|
272
|
-
- `data/logs/`:按天滚动的日志文件
|
|
273
|
-
- `skills/`:自定义技能目录
|
|
274
|
-
|
|
275
|
-
## 项目结构
|
|
276
|
-
|
|
277
|
-
```text
|
|
278
|
-
agent-bridge/
|
|
279
|
-
├── bin/ # CLI 入口
|
|
280
|
-
├── src/
|
|
281
|
-
│ ├── cli/ # start / stop / onboard / doctor 等命令
|
|
282
|
-
│ ├── agents/ # Agent 解析、路由、CLI 执行
|
|
283
|
-
│ ├── channels/ # Channel 插件(如 botlink)
|
|
284
|
-
│ ├── config/ # 配置加载、校验、默认值
|
|
285
|
-
│ ├── types/ # 类型定义
|
|
286
|
-
│ └── logger.ts # 日志
|
|
287
|
-
├── extensions/ # 扩展点
|
|
288
|
-
├── skills/ # 本地技能目录
|
|
289
|
-
├── config.example.json
|
|
290
|
-
├── config.multi-agent.example.json
|
|
291
|
-
├── docker-compose.yml
|
|
292
|
-
├── Dockerfile
|
|
293
|
-
└── package.json
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## 开发
|
|
297
|
-
|
|
298
|
-
```bash
|
|
299
|
-
pnpm install
|
|
300
|
-
pnpm build
|
|
301
|
-
pnpm typecheck
|
|
302
|
-
pnpm dev
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
环境要求:
|
|
306
|
-
|
|
307
|
-
- Node.js >= 22.0.0
|
|
308
|
-
- pnpm >= 9.0.0
|
|
309
|
-
|
|
310
|
-
## 许可证
|
|
311
|
-
|
|
312
|
-
[MIT](./LICENSE)
|
|
1
|
+
# agents-bridge
|
|
2
|
+
|
|
3
|
+
本地 Agent 网关,部署在客户本地机器上,通过长轮询连接 botlink 平台,把消息转发给本机运行的 Claude Code / Codex 等 Agent 运行时。
|
|
4
|
+
|
|
5
|
+
核心特点:
|
|
6
|
+
|
|
7
|
+
- 客户端主动外连,无需暴露入站端口
|
|
8
|
+
- 支持 `claude-cli/...`、`codex-cli/...`、`qwen-cli/...`、`wukong-cli/...` 这类 CLI 模型引用
|
|
9
|
+
- 支持多 agent 配置与按绑定规则路由
|
|
10
|
+
- 提供 `onboard`、`add-agent`、`doctor`、`logs`、`config` 等运维命令
|
|
11
|
+
- 支持前台运行和守护进程模式
|
|
12
|
+
|
|
13
|
+
## 架构概览
|
|
14
|
+
|
|
15
|
+
链路可以简化为:
|
|
16
|
+
|
|
17
|
+
`botlink cloud -> 长轮询 -> agents-bridge -> 本地 CLI backend / Agent Runtime`
|
|
18
|
+
|
|
19
|
+
其中:
|
|
20
|
+
|
|
21
|
+
- botlink 负责云端消息入口
|
|
22
|
+
- agents-bridge 负责轮询、路由、会话管理、日志和文件中转
|
|
23
|
+
- 本地 Agent Runtime 负责实际执行 Claude Code、Codex 等 CLI
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
### 方式 A:npm 全局安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g agents-bridge@latest
|
|
31
|
+
|
|
32
|
+
# 交互式初始化:输入 gateway URL、bot token、选择模型
|
|
33
|
+
agents-bridge onboard
|
|
34
|
+
|
|
35
|
+
# 前台启动
|
|
36
|
+
agents-bridge start
|
|
37
|
+
|
|
38
|
+
# 或后台启动
|
|
39
|
+
agents-bridge start --daemon
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 方式 B:Docker Compose
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
cp .env.example .env
|
|
46
|
+
# 编辑 .env,填写 GATEWAY_URL、BOT_TOKEN 等变量
|
|
47
|
+
|
|
48
|
+
docker compose up -d
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`docker-compose.yml` 默认会:
|
|
52
|
+
|
|
53
|
+
- 挂载 `${WORKSPACE_DIR:-./workspace}` 到容器内 `/workspace`
|
|
54
|
+
- 持久化 `/root/.agent-bridge`
|
|
55
|
+
- 通过环境变量覆盖网关地址、Bot Token 和日志级别
|
|
56
|
+
|
|
57
|
+
### 方式 C:源码运行
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone <repo-url>
|
|
61
|
+
cd agent-bridge
|
|
62
|
+
pnpm install
|
|
63
|
+
pnpm build
|
|
64
|
+
cp config.example.json config.json
|
|
65
|
+
# 编辑 config.json
|
|
66
|
+
node dist/entry.js start
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
开发模式:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm dev
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## CLI 命令
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
agents-bridge start # 前台启动
|
|
79
|
+
agents-bridge start --daemon # 后台启动
|
|
80
|
+
agents-bridge start -c ./config.json # 指定配置文件
|
|
81
|
+
agents-bridge stop # 停止守护进程
|
|
82
|
+
agents-bridge restart # 重启
|
|
83
|
+
agents-bridge reload # 热加载配置
|
|
84
|
+
agents-bridge status # 查看运行状态
|
|
85
|
+
agents-bridge onboard # 交互式初始化
|
|
86
|
+
agents-bridge add-agent # 交互式追加一个 agent
|
|
87
|
+
agents-bridge add-agent --account-id office-bot
|
|
88
|
+
agents-bridge add-agent office-codex --model codex-cli/gpt-5.5 --workspace D:\workspace\office --account-id office-bot --no-interactive
|
|
89
|
+
agents-bridge add-agent --create-account office-bot --account-gateway-url https://botlink.example.com --account-bot-token bot_xxx
|
|
90
|
+
agents-bridge list-groups --account-id office-bot --json
|
|
91
|
+
agents-bridge list-members --account-id office-bot --group-id conv_xxx
|
|
92
|
+
agents-bridge list-members --account-id office-bot --chat-id -100123456789 --json
|
|
93
|
+
agents-bridge send-message --account-id office-bot --group-id conv_xxx --text "hello"
|
|
94
|
+
agents-bridge doctor # 检查环境、CLI、API Key 和配置
|
|
95
|
+
agents-bridge logs # 查看最近日志
|
|
96
|
+
agents-bridge config # 输出当前配置
|
|
97
|
+
agents-bridge update # 更新已安装的 CLI
|
|
98
|
+
agents-bridge version # 查看版本
|
|
99
|
+
agents-bridge help # 查看帮助
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 配置
|
|
103
|
+
|
|
104
|
+
### 配置文件搜索顺序
|
|
105
|
+
|
|
106
|
+
当前实现会按以下顺序读取第一个存在的配置文件:
|
|
107
|
+
|
|
108
|
+
1. `agents-bridge start -c /path/to/config.json`
|
|
109
|
+
2. 环境变量 `AGENT_BRIDGE_CONFIG`
|
|
110
|
+
3. 当前目录 `./config.json`
|
|
111
|
+
4. 用户目录 `~/.agent-bridge/config.json`
|
|
112
|
+
|
|
113
|
+
### 最小配置示例
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"channels": {
|
|
118
|
+
"botlink": {
|
|
119
|
+
"accounts": {
|
|
120
|
+
"default": {
|
|
121
|
+
"gateway_url": "https://your-botlink.com",
|
|
122
|
+
"bot_token": "bot_xxx",
|
|
123
|
+
"poll_timeout": 30,
|
|
124
|
+
"retry_interval": 5,
|
|
125
|
+
"max_retry_interval": 60
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"agents": {
|
|
131
|
+
"defaults": {
|
|
132
|
+
"model": {
|
|
133
|
+
"primary": "claude-cli/opus-4.6"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"list": [
|
|
137
|
+
{
|
|
138
|
+
"id": "default",
|
|
139
|
+
"default": true
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
"bindings": [
|
|
144
|
+
{
|
|
145
|
+
"agentId": "default",
|
|
146
|
+
"match": {
|
|
147
|
+
"channel": "*"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
完整示例见:
|
|
155
|
+
|
|
156
|
+
- [config.example.json](./config.example.json)
|
|
157
|
+
- [config.multi-agent.example.json](./config.multi-agent.example.json)
|
|
158
|
+
|
|
159
|
+
botlink 配置读取时兼容旧的顶层 `gateway_url` / `bot_token` 写法,但新的配置写入会统一落到 `channels.botlink.accounts`。
|
|
160
|
+
|
|
161
|
+
兼容性说明:
|
|
162
|
+
|
|
163
|
+
- 老配置仍可继续使用:顶层 `channels.botlink.gateway_url` / `bot_token` 仍然会被读取
|
|
164
|
+
- 新示例配置统一使用 `channels.botlink.accounts` 格式
|
|
165
|
+
- `add-agent` 会兼容读取老配置,并在保存时自动迁移成 `channels.botlink.accounts`
|
|
166
|
+
- `onboard` 会先备份已有配置,再按新的 `channels.botlink.accounts` 格式重建配置
|
|
167
|
+
|
|
168
|
+
### 关键配置项
|
|
169
|
+
|
|
170
|
+
- `channels.botlink.accounts.<accountId>.gateway_url`:botlink 网关地址
|
|
171
|
+
- `channels.botlink.accounts.<accountId>.bot_token`:bot token
|
|
172
|
+
- `agents.defaults.model.primary`:主模型引用,例如 `claude-cli/opus-4.6`、`codex-cli/gpt-5.4`、`qwen-cli/qwen3-coder-plus` 或 `wukong-cli/wukong-coder`
|
|
173
|
+
- `agents.defaults.model.fallbacks`:备用模型链
|
|
174
|
+
- `agents.defaults.cliBackends`:CLI backend 启动参数与运行模式
|
|
175
|
+
- `agents.list`:命名 agent 列表
|
|
176
|
+
- `bindings`:消息路由规则,可按 `channel`、`accountId`、`peer.id` 等条件匹配
|
|
177
|
+
- `files.temp_dir`:文件中转目录
|
|
178
|
+
- `logging.level`:日志级别
|
|
179
|
+
|
|
180
|
+
### 多 agent 配置
|
|
181
|
+
|
|
182
|
+
多 agent 模式通过 `agents.list` 定义运行实例,通过 `bindings` 决定消息路由到哪个 agent。
|
|
183
|
+
|
|
184
|
+
追加 agent 时,也可以直接运行:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
agents-bridge add-agent
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
该命令会在现有配置上:
|
|
191
|
+
|
|
192
|
+
- 追加一个 `agents.list[]` 项
|
|
193
|
+
- 可选绑定已有 botlink `accountId`
|
|
194
|
+
- 可选创建新的 botlink account 并立刻绑定
|
|
195
|
+
- 兼容旧的顶层 botlink 配置写法,并在保存时自动迁移成 `channels.botlink.accounts.default`
|
|
196
|
+
- 写入前自动备份原配置文件
|
|
197
|
+
|
|
198
|
+
如果现有 account 已被其他 agent 占用,交互流程会提示该 account 当前绑定到哪个 agent,并允许直接创建新的 account 后继续绑定。
|
|
199
|
+
|
|
200
|
+
也可以显式指定:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
agents-bridge add-agent --account-id office-bot
|
|
204
|
+
agents-bridge add-agent --create-account office-bot --account-gateway-url https://botlink.example.com --account-bot-token bot_xxx
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
例如:
|
|
208
|
+
|
|
209
|
+
- 一个 bot 绑定到 Codex
|
|
210
|
+
- 一个 bot 绑定到 Claude Code
|
|
211
|
+
- 不同工作区使用不同 `workspace`
|
|
212
|
+
- 通过预置 `cliSessionId` 复用既有 CLI 会话
|
|
213
|
+
|
|
214
|
+
详见 [config.multi-agent.example.json](./config.multi-agent.example.json)。
|
|
215
|
+
|
|
216
|
+
### 环境变量覆盖
|
|
217
|
+
|
|
218
|
+
环境变量可覆盖配置文件中的对应值:
|
|
219
|
+
|
|
220
|
+
| 环境变量 | 覆盖字段 | 说明 |
|
|
221
|
+
|---|---|---|
|
|
222
|
+
| `AGENT_BRIDGE_CONFIG` | 配置文件路径 | 指定要加载的 `config.json` |
|
|
223
|
+
| `AGENT_BRIDGE_GATEWAY_URL` | `channels.botlink.accounts.default.gateway_url` 或旧格式 `channels.botlink.gateway_url` | 优先覆盖默认 botlink 账号;旧配置会覆盖顶层网关地址 |
|
|
224
|
+
| `AGENT_BRIDGE_BOT_TOKEN` | `channels.botlink.accounts.default.bot_token` 或旧格式 `channels.botlink.bot_token` | 优先覆盖默认 botlink 账号;旧配置会覆盖顶层 Bot Token |
|
|
225
|
+
| `AGENT_BRIDGE_LOG_LEVEL` | `logging.level` | 日志级别 |
|
|
226
|
+
| `AGENT_BRIDGE_TEMP_DIR` | `files.temp_dir` | 临时文件目录 |
|
|
227
|
+
| `ANTHROPIC_API_KEY` | 环境变量 | 供诊断或后续 API 模式使用 |
|
|
228
|
+
| `OPENAI_API_KEY` | 环境变量 | 供诊断或后续 API 模式使用 |
|
|
229
|
+
|
|
230
|
+
## 模型与运行模式
|
|
231
|
+
|
|
232
|
+
当前消息执行链路仅支持 CLI 模式模型,也就是:
|
|
233
|
+
|
|
234
|
+
- `claude-cli/...`
|
|
235
|
+
- `codex-cli/...`
|
|
236
|
+
- `qwen-cli/...`
|
|
237
|
+
- `wukong-cli/...`
|
|
238
|
+
|
|
239
|
+
配置层已经允许 `anthropic/...`、`openai/...` 这类 API provider 引用,但当前主运行时尚未实现 API 模式;若把它们设为主模型,程序会返回“当前仅支持 CLI 模式模型”。
|
|
240
|
+
|
|
241
|
+
内置 `wukong-cli` 默认按通用 JSON exec 模式启动:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
wukong-cli --output-format json --no-color --quiet --model <model> --prompt "<prompt>"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
如果本地悟空 CLI 的可执行文件不在 `PATH`,可以把 `command` 覆盖为完整路径。若参数不同,可以在 `agents.defaults.cliBackends.wukong-cli` 或单个 agent 的 `cliBackends.wukong-cli` 中覆盖 `command`、`args`、`modelArg`、`promptArg` 等字段。
|
|
248
|
+
|
|
249
|
+
## 数据目录
|
|
250
|
+
|
|
251
|
+
运行时数据默认保存在 `~/.agent-bridge/`:
|
|
252
|
+
|
|
253
|
+
```text
|
|
254
|
+
~/.agent-bridge/
|
|
255
|
+
├── config.json
|
|
256
|
+
├── agent-bridge.pid
|
|
257
|
+
├── agents/
|
|
258
|
+
│ └── <agentId>/
|
|
259
|
+
│ └── cli-sessions.json
|
|
260
|
+
├── data/
|
|
261
|
+
│ ├── files/
|
|
262
|
+
│ ├── logs/
|
|
263
|
+
│ └── sessions/
|
|
264
|
+
└── skills/
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
其中:
|
|
268
|
+
|
|
269
|
+
- `config.json`:全局配置文件
|
|
270
|
+
- `agent-bridge.pid`:守护进程 PID 文件
|
|
271
|
+
- `agents/<agentId>/cli-sessions.json`:每个 agent 的 CLI 会话映射
|
|
272
|
+
- `data/logs/`:按天滚动的日志文件
|
|
273
|
+
- `skills/`:自定义技能目录
|
|
274
|
+
|
|
275
|
+
## 项目结构
|
|
276
|
+
|
|
277
|
+
```text
|
|
278
|
+
agent-bridge/
|
|
279
|
+
├── bin/ # CLI 入口
|
|
280
|
+
├── src/
|
|
281
|
+
│ ├── cli/ # start / stop / onboard / doctor 等命令
|
|
282
|
+
│ ├── agents/ # Agent 解析、路由、CLI 执行
|
|
283
|
+
│ ├── channels/ # Channel 插件(如 botlink)
|
|
284
|
+
│ ├── config/ # 配置加载、校验、默认值
|
|
285
|
+
│ ├── types/ # 类型定义
|
|
286
|
+
│ └── logger.ts # 日志
|
|
287
|
+
├── extensions/ # 扩展点
|
|
288
|
+
├── skills/ # 本地技能目录
|
|
289
|
+
├── config.example.json
|
|
290
|
+
├── config.multi-agent.example.json
|
|
291
|
+
├── docker-compose.yml
|
|
292
|
+
├── Dockerfile
|
|
293
|
+
└── package.json
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## 开发
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
pnpm install
|
|
300
|
+
pnpm build
|
|
301
|
+
pnpm typecheck
|
|
302
|
+
pnpm dev
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
环境要求:
|
|
306
|
+
|
|
307
|
+
- Node.js >= 22.0.0
|
|
308
|
+
- pnpm >= 9.0.0
|
|
309
|
+
|
|
310
|
+
## 许可证
|
|
311
|
+
|
|
312
|
+
[MIT](./LICENSE)
|
package/bin/agent-bridge.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// agents-bridge CLI entry point
|
|
4
|
-
// Used by: npm install -g agents-bridge / npx agents-bridge
|
|
5
|
-
|
|
6
|
-
import { fileURLToPath } from 'node:url'
|
|
7
|
-
import { dirname, resolve } from 'node:path'
|
|
8
|
-
import { pathToFileURL } from 'node:url'
|
|
9
|
-
|
|
10
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
|
-
|
|
12
|
-
// Import the compiled entry point
|
|
13
|
-
await import(pathToFileURL(resolve(__dirname, '..', 'dist', 'entry.js')).href)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// agents-bridge CLI entry point
|
|
4
|
+
// Used by: npm install -g agents-bridge / npx agents-bridge
|
|
5
|
+
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { dirname, resolve } from 'node:path'
|
|
8
|
+
import { pathToFileURL } from 'node:url'
|
|
9
|
+
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
|
|
12
|
+
// Import the compiled entry point
|
|
13
|
+
await import(pathToFileURL(resolve(__dirname, '..', 'dist', 'entry.js')).href)
|