nexus-agentd 0.1.1 → 0.1.6
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/LICENSE +22 -0
- package/README.md +350 -188
- package/dist/a2a/runtime.d.ts +30 -0
- package/dist/a2a/runtime.js +374 -0
- package/dist/acp/runtime.d.ts +12 -3
- package/dist/acp/runtime.js +248 -17
- package/dist/artifact-store.d.ts +41 -0
- package/dist/artifact-store.js +340 -0
- package/dist/auth.d.ts +13 -0
- package/dist/auth.js +77 -0
- package/dist/cli.js +58 -1
- package/dist/config.d.ts +10 -0
- package/dist/config.js +281 -53
- package/dist/control-plane.d.ts +91 -0
- package/dist/control-plane.js +629 -0
- package/dist/drivers/hermes.d.ts +2 -0
- package/dist/drivers/hermes.js +10 -0
- package/dist/drivers/index.js +6 -0
- package/dist/events.js +13 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +15 -3
- package/dist/run-store.d.ts +49 -0
- package/dist/run-store.js +291 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.js +911 -41
- package/dist/session-contract.d.ts +16 -4
- package/dist/session.d.ts +74 -8
- package/dist/session.js +433 -38
- package/dist/types.d.ts +193 -6
- package/dist/types.js +2 -1
- package/dist/webui/app.d.ts +1 -0
- package/dist/webui/app.js +1072 -0
- package/dist/webui/icons.d.ts +9 -0
- package/dist/webui/icons.js +10 -0
- package/dist/webui/index.d.ts +3 -0
- package/dist/webui/index.js +32 -0
- package/dist/webui/markup.d.ts +1 -0
- package/dist/webui/markup.js +68 -0
- package/dist/webui/styles.d.ts +1 -0
- package/dist/webui/styles.js +269 -0
- package/dist/workspace-files.d.ts +48 -0
- package/dist/workspace-files.js +269 -0
- package/nexus-agentd.example.json +30 -27
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lumia1998
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,39 +1,201 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agent Nexus Gateway
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
向 AgentNexus 暴露本机白名单 Agent。当前支持 OpenCode、Claude Code、Codex、Pi 和
|
|
5
|
-
OpenClaw ACP Driver;Hermes 使用其原生 A2A Server,不经过 agentd。
|
|
3
|
+
[](https://github.com/lumia1998/nexus-gateway/actions/workflows/ci.yml)
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
`nexus-agentd` 是 Agent Nexus 的本地 Gateway。它在一台机器上统一管理 ACP 进程和远程 A2A
|
|
6
|
+
Agent,并向 Koishi AgentNexus 或其他客户端提供 HTTP/SSE API。管理控制台使用 **Agent Nexus**
|
|
7
|
+
品牌,不依赖 CDN、前端框架或父仓库。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
│ HTTP/SSE
|
|
12
|
-
▼
|
|
13
|
-
nexus-agentd
|
|
14
|
-
│ ACP stdio
|
|
15
|
-
▼
|
|
16
|
-
OpenCode / Claude Code / Codex / Pi / OpenClaw
|
|
17
|
-
```
|
|
9
|
+
如果你从 Koishi 使用 Gateway,请先阅读配套插件的
|
|
10
|
+
[安装与配置说明](https://github.com/lumia1998/koishi-plugin-agent-nexus#readme)。
|
|
18
11
|
|
|
19
|
-
##
|
|
12
|
+
## 快速开始
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
install-only 安装本包和缺失 Adapter,生成 Token/配置/systemd,并自动注册 Gateway 与逻辑
|
|
23
|
-
Agent,不需要手动导出环境变量。
|
|
24
|
-
|
|
25
|
-
以下命令用于独立部署、故障恢复或高级配置:
|
|
14
|
+
当前仓库代码建议按下面的源码部署流程启动;安装、首次初始化、systemd 和 Agent 准备的完整说明见下文。
|
|
26
15
|
|
|
27
16
|
```bash
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
git clone https://github.com/lumia1998/nexus-gateway.git
|
|
18
|
+
cd nexus-gateway
|
|
19
|
+
mkdir -p "$HOME/.config/agent-nexus" "$HOME/projects"
|
|
20
|
+
npm ci
|
|
21
|
+
npm run build
|
|
22
|
+
node dist/cli.js \
|
|
23
|
+
--config "$HOME/.config/agent-nexus/nexus-agentd.json" \
|
|
24
|
+
--host 0.0.0.0 \
|
|
25
|
+
--port 8787 \
|
|
26
|
+
--workspace "$HOME/projects"
|
|
34
27
|
```
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
如果使用 npm 包,请先用 `npm view nexus-agentd version` 确认 registry 中的版本。当前仓库的 package.json 版本不代表该版本已经发布到 npm;未发布时不要把 `npm install nexus-agentd` 当成当前仓库的安装方式。
|
|
30
|
+
|
|
31
|
+
## 安装与部署
|
|
32
|
+
|
|
33
|
+
### 运行要求
|
|
34
|
+
|
|
35
|
+
- Node.js 20 或更高版本。
|
|
36
|
+
- 一个明确的工作区目录。Gateway 只允许 Agent 访问 workspaceRoots 及其子目录。
|
|
37
|
+
- 计划使用的 ACP CLI/Adapter 已安装,并且对运行 Gateway 的同一个操作系统用户可用。
|
|
38
|
+
- LAN 部署需要在主机防火墙中限制 8787 端口来源;公网部署应放在 HTTPS/mTLS 反向代理或可信隧道后。
|
|
39
|
+
|
|
40
|
+
Gateway 不会替你安装 Agent,也不会替你执行 OpenCode、Claude Code 或 Hermes 的登录命令;这些属于宿主机运维步骤。
|
|
41
|
+
|
|
42
|
+
### npm 包安装(已发布版本)
|
|
43
|
+
|
|
44
|
+
注意:只有当目标版本已经发布到 npm 时才使用此方式。否则请使用下面的源码部署,或将本仓库打包后的 tarball 安装到目标机器。
|
|
45
|
+
|
|
46
|
+
当前仓库的 package.json 版本可能高于 npm registry 的 latest;发布状态可用 `npm view nexus-agentd version` 检查。
|
|
47
|
+
|
|
48
|
+
生产环境建议使用专用的低权限系统用户,并把 npm 全局包安装到用户目录:
|
|
49
|
+
|
|
50
|
+
~~~bash
|
|
51
|
+
NPM_CONFIG_PREFIX="$HOME/.local"
|
|
52
|
+
npm install --global --prefix "$NPM_CONFIG_PREFIX" nexus-agentd
|
|
53
|
+
export PATH="$NPM_CONFIG_PREFIX/bin:$PATH"
|
|
54
|
+
~~~
|
|
55
|
+
|
|
56
|
+
启动命令是 nexus-agentd,npm 包的 CLI 入口是 dist/cli.js。
|
|
57
|
+
|
|
58
|
+
### 首次初始化
|
|
59
|
+
|
|
60
|
+
首次启动时指定配置文件、监听地址和工作区:
|
|
61
|
+
|
|
62
|
+
~~~bash
|
|
63
|
+
mkdir -p "$HOME/.config/agent-nexus" "$HOME/projects"
|
|
64
|
+
nexus-agentd \
|
|
65
|
+
--config "$HOME/.config/agent-nexus/nexus-agentd.json" \
|
|
66
|
+
--host 0.0.0.0 \
|
|
67
|
+
--port 8787 \
|
|
68
|
+
--workspace "$HOME/projects"
|
|
69
|
+
~~~
|
|
70
|
+
|
|
71
|
+
首次启动后:
|
|
72
|
+
|
|
73
|
+
1. 打开终端打印的 http://<gateway-host>:8787/ui/。
|
|
74
|
+
2. 设置至少 12 位的 Console Password。
|
|
75
|
+
3. 在 API Keys 页面创建给 Koishi 或其他客户端使用的数据面 API Key。
|
|
76
|
+
4. 在 Workspaces 页面确认工作区 allowlist,在 Agents 页面检查 ACP/A2A Agent。
|
|
77
|
+
|
|
78
|
+
Console Password 和 API Key 是两套凭证:前者只用于管理页面登录,后者只用于数据面 API。不要把 Console Password 填到 Koishi 插件的 gatewayKey。
|
|
79
|
+
|
|
80
|
+
配置已经存在时,--host、--port 和 --workspace 不会重新覆盖已有配置;后续启动只需要指定同一个 --config。
|
|
81
|
+
也可以通过 NEXUS_AGENTD_CONFIG 环境变量提供配置路径。
|
|
82
|
+
|
|
83
|
+
### systemd user service(可选)
|
|
84
|
+
|
|
85
|
+
仓库不内置 systemd unit。使用 npm 包时,可以创建 ~/.config/systemd/user/nexus-agentd.service:
|
|
86
|
+
|
|
87
|
+
~~~ini
|
|
88
|
+
[Unit]
|
|
89
|
+
Description=Nexus Agent Gateway
|
|
90
|
+
After=network-online.target
|
|
91
|
+
Wants=network-online.target
|
|
92
|
+
|
|
93
|
+
[Service]
|
|
94
|
+
Type=simple
|
|
95
|
+
WorkingDirectory=%h/projects
|
|
96
|
+
Environment=NODE_ENV=production
|
|
97
|
+
Environment="PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin"
|
|
98
|
+
ExecStart=%h/.local/bin/nexus-agentd --config %h/.config/agent-nexus/nexus-agentd.json
|
|
99
|
+
Restart=on-failure
|
|
100
|
+
RestartSec=3
|
|
101
|
+
TimeoutStopSec=20
|
|
102
|
+
KillMode=mixed
|
|
103
|
+
UMask=0077
|
|
104
|
+
|
|
105
|
+
[Install]
|
|
106
|
+
WantedBy=default.target
|
|
107
|
+
~~~
|
|
108
|
+
|
|
109
|
+
加载、启用和检查:
|
|
110
|
+
|
|
111
|
+
~~~bash
|
|
112
|
+
systemctl --user daemon-reload
|
|
113
|
+
systemctl --user enable --now nexus-agentd.service
|
|
114
|
+
systemctl --user status nexus-agentd.service
|
|
115
|
+
~~~
|
|
116
|
+
|
|
117
|
+
常用运维命令:
|
|
118
|
+
|
|
119
|
+
~~~bash
|
|
120
|
+
systemctl --user restart nexus-agentd.service
|
|
121
|
+
journalctl --user -u nexus-agentd.service -n 100 --no-pager
|
|
122
|
+
curl http://127.0.0.1:8787/health
|
|
123
|
+
~~~
|
|
124
|
+
|
|
125
|
+
如果使用 nvm、mise 或其他用户级 Node 安装方式,请把 unit 中的 PATH 改成实际值,否则 Gateway 可能能启动,但找不到 Agent CLI。
|
|
126
|
+
需要用户未登录时也自动启动时,可按发行版策略执行 loginctl enable-linger "$USER"。
|
|
127
|
+
|
|
128
|
+
如果按源码部署,把 unit 中的 `WorkingDirectory` 改成 Gateway 工作树,并将 `ExecStart` 改为实际 Node
|
|
129
|
+
绝对路径加上 `dist/cli.js`,例如:`/usr/bin/node %h/nexus-gateway/dist/cli.js --config
|
|
130
|
+
%h/.config/agent-nexus/nexus-agentd.json`。不要在 systemd 中依赖交互式 Shell 的 nvm 初始化。
|
|
131
|
+
|
|
132
|
+
### 源码部署(当前仓库推荐)
|
|
133
|
+
|
|
134
|
+
源码部署适合当前仓库和尚未发布到 npm 的版本;生产环境请使用外部进程管理器负责守护,
|
|
135
|
+
不要把运行数据、Artifact 仓库或密钥放进 Git 工作树:
|
|
136
|
+
|
|
137
|
+
~~~bash
|
|
138
|
+
git clone https://github.com/lumia1998/nexus-gateway.git
|
|
139
|
+
cd nexus-gateway
|
|
140
|
+
mkdir -p "$HOME/.config/agent-nexus" "$HOME/projects"
|
|
141
|
+
npm ci
|
|
142
|
+
npm run build
|
|
143
|
+
node dist/cli.js \
|
|
144
|
+
--config "$HOME/.config/agent-nexus/nexus-agentd.json" \
|
|
145
|
+
--host 0.0.0.0 \
|
|
146
|
+
--port 8787 \
|
|
147
|
+
--workspace "$HOME/projects"
|
|
148
|
+
~~~
|
|
149
|
+
|
|
150
|
+
源码仓库没有 Docker、PM2 或 systemd 配置,需要由宿主机的进程管理器负责守护和重启。
|
|
151
|
+
|
|
152
|
+
## 认证边界
|
|
153
|
+
|
|
154
|
+
控制面和数据面使用不同凭证:
|
|
155
|
+
|
|
156
|
+
- Console Password 只用于管理员登录。服务端以 scrypt 哈希保存,登录后只下发
|
|
157
|
+
`HttpOnly; SameSite=Strict` Cookie,浏览器不保存密码。
|
|
158
|
+
- API Key 只用于 `/v1/agents` 和 `/v1/sessions/*`。Key 可以命名、限制为全部或指定 Agent、
|
|
159
|
+
停用、删除、重生成和按需 reveal。
|
|
160
|
+
- Key 自动生成为 `nx_sk_...`;也可设置至少 16 位的自定义值。
|
|
161
|
+
- 为支持管理员按需 reveal,API Key 可恢复地保存在权限为 `0600` 的配置文件中,不会出现在
|
|
162
|
+
普通配置响应或日志里。
|
|
163
|
+
|
|
164
|
+
旧配置中的 `authToken` 会继续作为名为 `Legacy Access Key` 的全 Agent 数据面 Key 工作。它不会
|
|
165
|
+
被当成 Console Password。升级后第一次打开 WebUI 会要求单独设置管理员密码,原有 Agent 和
|
|
166
|
+
Workspace 配置保持不变。
|
|
167
|
+
|
|
168
|
+
## WebUI
|
|
169
|
+
|
|
170
|
+
固定侧栏有总览、运行记录、智能体、工作区、文件、API 密钥和运行设置七个主页面。管理员菜单位于侧栏底部,
|
|
171
|
+
提供 Light / Dark / System 主题、修改密码和退出登录。
|
|
172
|
+
|
|
173
|
+
- Overview 只显示真实 Agent、Ready 和当前内存 Session 数量。
|
|
174
|
+
- 运行记录把当前任务和历史任务分开显示,记录用户原始任务、真实运行阶段、状态、结果摘要、
|
|
175
|
+
耗时和产物;每 5 秒自动刷新,也可查看完整详情。
|
|
176
|
+
- Agents 支持本地 ACP 与远程 A2A;readiness 每 20 秒自动刷新,也可手动刷新。
|
|
177
|
+
- Workspaces 管理 ACP 的 realpath allowlist;A2A 不使用本地 Workspace。
|
|
178
|
+
- 文件页面在 allowlist 内浏览、上传、下载、新建目录、重命名和删除文件,并可生成临时公开链接。
|
|
179
|
+
发布操作只复制选定文件,不会把工作区映射成公开静态目录。
|
|
180
|
+
- API Keys 显示真实状态和最后使用时间,并提供独立的显式 reveal 操作。
|
|
181
|
+
- 运行设置可以直接修改 Session 空闲有效期、ACP 单次任务超时和清理任务周期,保存后立即热生效。
|
|
182
|
+
默认值分别是 24 小时、30 分钟和 60 秒;A2A 请求超时在每个 Agent 的编辑页单独设置,默认 60 秒、
|
|
183
|
+
最大 30 分钟。
|
|
184
|
+
|
|
185
|
+
## Agent 协议
|
|
186
|
+
|
|
187
|
+
### ACP
|
|
188
|
+
|
|
189
|
+
| Driver | 默认入口 |
|
|
190
|
+
|---|---|
|
|
191
|
+
| `opencode` | `opencode acp` |
|
|
192
|
+
| `claude` | `claude-agent-acp` |
|
|
193
|
+
| `codex` | `codex-acp` |
|
|
194
|
+
| `pi` | `pi-acp` |
|
|
195
|
+
| `openclaw` | `openclaw acp` |
|
|
196
|
+
| `hermes` | `hermes acp` |
|
|
197
|
+
|
|
198
|
+
Claude Code、Codex、Pi 通常需要对应 Adapter:
|
|
37
199
|
|
|
38
200
|
```bash
|
|
39
201
|
npm install -g \
|
|
@@ -42,216 +204,212 @@ npm install -g \
|
|
|
42
204
|
pi-acp
|
|
43
205
|
```
|
|
44
206
|
|
|
45
|
-
|
|
46
|
-
|
|
207
|
+
`command`、`args`、`inheritEnv` 和 `env` 是仅可在本机配置文件修改的高级字段,WebUI 不接受这些
|
|
208
|
+
字段。Workspace 在启动进程前经过 `realpath` 边界校验。
|
|
47
209
|
|
|
48
|
-
|
|
210
|
+
### OpenCode、Claude Code 和 Hermes 的宿主机准备
|
|
49
211
|
|
|
50
|
-
|
|
51
|
-
export NEXUS_AGENTD_CONFIG=/etc/agent-nexus/nexus-agentd.json
|
|
52
|
-
nexus-agentd
|
|
53
|
-
```
|
|
212
|
+
这三个 Agent 不需要修改 Gateway 源码,差异只在宿主机的可执行文件、ACP 入口和登录环境:
|
|
54
213
|
|
|
55
|
-
|
|
214
|
+
| Agent | Gateway 默认启动命令 | readiness 检查 | 宿主机要求 |
|
|
215
|
+
| --- | --- | --- | --- |
|
|
216
|
+
| OpenCode | opencode acp | opencode --version | 安装 OpenCode CLI;使用原生 ACP。 |
|
|
217
|
+
| Claude Code(CC) | claude-agent-acp | claude-agent-acp --version | 安装 @agentclientprotocol/claude-agent-acp,并准备 Claude Code 登录环境。 |
|
|
218
|
+
| Hermes | hermes acp | hermes acp --check | 安装 Hermes CLI;使用原生 ACP。 |
|
|
56
219
|
|
|
57
|
-
|
|
58
|
-
npm install
|
|
59
|
-
npm run build
|
|
60
|
-
node dist/cli.js --config nexus-agentd.json
|
|
61
|
-
```
|
|
220
|
+
Claude Code、Codex 和 Pi 的常用 Adapter 可以一起安装:
|
|
62
221
|
|
|
63
|
-
|
|
222
|
+
~~~bash
|
|
223
|
+
npm install --global --prefix "$HOME/.local" \
|
|
224
|
+
@agentclientprotocol/claude-agent-acp \
|
|
225
|
+
@agentclientprotocol/codex-acp \
|
|
226
|
+
pi-acp
|
|
227
|
+
~~~
|
|
64
228
|
|
|
65
|
-
|
|
229
|
+
OpenCode 和 Hermes 请按各自项目的官方方式安装。Gateway 不执行 OpenCode、Claude Code 或 Hermes 的登录命令;登录必须在运行 nexus-agentd 的同一个操作系统用户环境中完成。
|
|
230
|
+
|
|
231
|
+
可在同一用户的交互式 Shell 中检查:
|
|
232
|
+
|
|
233
|
+
~~~bash
|
|
234
|
+
command -v opencode && opencode --version
|
|
235
|
+
command -v claude-agent-acp && claude-agent-acp --version
|
|
236
|
+
command -v hermes && hermes acp --check
|
|
237
|
+
~~~
|
|
238
|
+
|
|
239
|
+
如果命令在交互式 Shell 中可用、在 systemd 中不可用,检查 unit 的 PATH、HOME、XDG_CONFIG_HOME 和登录凭据。某个 Agent 未安装或检查失败不会影响其他 Agent。
|
|
240
|
+
|
|
241
|
+
一个最小的 ACP 配置示例(可在 WebUI 的 Agents 页面创建,也可写入本机配置文件):
|
|
242
|
+
|
|
243
|
+
~~~json
|
|
66
244
|
{
|
|
67
|
-
"
|
|
68
|
-
"host": "127.0.0.1",
|
|
69
|
-
"port": 8787
|
|
70
|
-
},
|
|
71
|
-
"authToken": "env:NEXUS_AGENTD_TOKEN",
|
|
72
|
-
"workspaceRoots": [
|
|
73
|
-
"/data/repos"
|
|
74
|
-
],
|
|
245
|
+
"workspaceRoots": ["/home/lumia/projects"],
|
|
75
246
|
"agents": {
|
|
76
247
|
"opencode": {
|
|
248
|
+
"protocol": "acp",
|
|
77
249
|
"driver": "opencode",
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"permissionPolicy": "ask",
|
|
81
|
-
"inheritEnv": [
|
|
82
|
-
"OPENAI_API_KEY",
|
|
83
|
-
"ANTHROPIC_API_KEY"
|
|
84
|
-
]
|
|
250
|
+
"name": "OpenCode",
|
|
251
|
+
"workspace": "/home/lumia/projects"
|
|
85
252
|
},
|
|
86
253
|
"claude": {
|
|
254
|
+
"protocol": "acp",
|
|
87
255
|
"driver": "claude",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
},
|
|
91
|
-
"codex": {
|
|
92
|
-
"driver": "codex",
|
|
93
|
-
"command": "codex-acp",
|
|
94
|
-
"permissionPolicy": "ask"
|
|
256
|
+
"name": "Claude Code",
|
|
257
|
+
"workspace": "/home/lumia/projects"
|
|
95
258
|
},
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
"openclaw": {
|
|
102
|
-
"driver": "openclaw",
|
|
103
|
-
"command": "openclaw",
|
|
104
|
-
"args": ["acp"],
|
|
105
|
-
"permissionPolicy": "ask"
|
|
259
|
+
"hermes": {
|
|
260
|
+
"protocol": "acp",
|
|
261
|
+
"driver": "hermes",
|
|
262
|
+
"name": "Hermes",
|
|
263
|
+
"workspace": "/home/lumia/projects"
|
|
106
264
|
}
|
|
107
265
|
}
|
|
108
266
|
}
|
|
109
|
-
|
|
267
|
+
~~~
|
|
110
268
|
|
|
111
|
-
|
|
269
|
+
`workspace` 必须位于 `workspaceRoots` 之下;如果只通过 WebUI 配置,Gateway 会校验并保存这些字段。
|
|
112
270
|
|
|
113
|
-
|
|
114
|
-
|---|---|
|
|
115
|
-
| `listen.host` | 默认 `127.0.0.1`;LAN 访问需显式改为内网地址或 `0.0.0.0` |
|
|
116
|
-
| `listen.port` | HTTP/SSE 监听端口,默认 `8787` |
|
|
117
|
-
| `authToken` | 必填 Bearer Token,支持 `env:VAR` |
|
|
118
|
-
| `workspaceRoots` | 允许启动 ACP Session 的目录根列表 |
|
|
119
|
-
| `agents` | daemon 本地 Agent 白名单 |
|
|
120
|
-
| `driver` | `opencode`、`claude`、`codex`、`pi` 或 `openclaw` |
|
|
121
|
-
| `permissionPolicy` | `ask` 或 `deny`,默认 `ask` |
|
|
122
|
-
| `permissionTimeoutMs` | 权限或输入请求等待时间 |
|
|
123
|
-
| `inheritEnv` | 额外允许传给 Agent 子进程的本机环境变量名 |
|
|
124
|
-
| `env` | 显式环境变量,值支持 `env:VAR` |
|
|
125
|
-
|
|
126
|
-
默认入口:
|
|
127
|
-
|
|
128
|
-
| Driver | 默认命令 | 说明 |
|
|
129
|
-
|---|---|---|
|
|
130
|
-
| `opencode` | `opencode acp` | OpenCode 原生 ACP Server |
|
|
131
|
-
| `claude` | `claude-agent-acp` | `@agentclientprotocol/claude-agent-acp` |
|
|
132
|
-
| `codex` | `codex-acp` | `@agentclientprotocol/codex-acp`,自带兼容 Codex 依赖 |
|
|
133
|
-
| `pi` | `pi-acp` | adapter 再启动本机 `pi --mode rpc` |
|
|
134
|
-
| `openclaw` | `openclaw acp` | OpenClaw 原生 Gateway ACP Bridge |
|
|
135
|
-
|
|
136
|
-
OpenClaw Gateway 必须已运行并可被 `openclaw acp` 访问。可通过 OpenClaw 本机配置保存 Gateway
|
|
137
|
-
地址和凭据,也可在 `args` 中使用 `--url` 与 `--token-file`。不要把明文 Token 提交到仓库。
|
|
138
|
-
|
|
139
|
-
Pi Driver 会同时探测 `pi-acp` 和底层 `pi`。如果 Pi 可执行文件不是默认名称,通过
|
|
140
|
-
`env.PI_ACP_PI_COMMAND` 指定。
|
|
141
|
-
|
|
142
|
-
`command` 和 `args` 只从 agentd 本机配置读取。HTTP 客户端不能覆盖它们。
|
|
271
|
+
### A2A
|
|
143
272
|
|
|
144
|
-
|
|
273
|
+
A2A 使用官方 `@a2a-js/sdk` 客户端,通过完整的 Agent Card URL 发现名称、能力和实际调用地址,
|
|
274
|
+
支持 JSON-RPC / HTTP+JSON 传输、流式消息(SDK 自动回退为非流式)、任务状态、Artifacts 和取消。
|
|
275
|
+
首选传输可设为 `auto`、`jsonrpc` 或 `http-json`;可配置无认证、Bearer 或自定义 Header。私有网段
|
|
276
|
+
和局域网 URL 不会被禁止。
|
|
145
277
|
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"protocol": "a2a",
|
|
281
|
+
"name": "Research Agent",
|
|
282
|
+
"agentCardUrl": "http://192.168.1.20:8080/.well-known/agent-card.json",
|
|
283
|
+
"preferredTransport": "auto",
|
|
284
|
+
"auth": {
|
|
285
|
+
"type": "bearer",
|
|
286
|
+
"value": "env:RESEARCH_AGENT_TOKEN"
|
|
287
|
+
},
|
|
288
|
+
"timeoutMs": 60000
|
|
289
|
+
}
|
|
154
290
|
```
|
|
155
291
|
|
|
156
|
-
|
|
292
|
+
旧配置中的 `agentUrl` 仍按“服务根地址 + `/.well-known/agent-card.json`”方式发现 Card,无需手工
|
|
293
|
+
迁移;在 WebUI 中保存一次后会写入新的 `agentCardUrl` 字段。
|
|
157
294
|
|
|
158
|
-
|
|
159
|
-
Authorization: Bearer TOKEN
|
|
160
|
-
```
|
|
295
|
+
## 配置
|
|
161
296
|
|
|
162
|
-
|
|
297
|
+
推荐从首次启动生成的待初始化配置开始。完整示例见
|
|
298
|
+
[`nexus-agentd.example.json`](./nexus-agentd.example.json)。数值和数组字段会严格校验,错误配置
|
|
299
|
+
会在启动或原子热重载前被拒绝,不再静默截断或忽略错误类型。
|
|
300
|
+
|
|
301
|
+
常用资源限制:
|
|
163
302
|
|
|
164
303
|
```json
|
|
165
304
|
{
|
|
166
|
-
"
|
|
167
|
-
"
|
|
305
|
+
"maxRequestBytes": 1048576,
|
|
306
|
+
"maxAttachmentBytes": 33554432,
|
|
307
|
+
"artifactStoragePath": "./artifacts",
|
|
308
|
+
"maxArtifactBytes": 536870912,
|
|
309
|
+
"maxArtifactStorageBytes": 4294967296,
|
|
310
|
+
"maxPublishedArtifacts": 4096,
|
|
311
|
+
"maxConcurrentArtifactPublishes": 4,
|
|
312
|
+
"artifactTtlMs": 86400000,
|
|
313
|
+
"requestTimeoutMs": 30000,
|
|
314
|
+
"promptTimeoutMs": 1800000,
|
|
315
|
+
"cleanupIntervalMs": 60000,
|
|
316
|
+
"maxSessions": 64,
|
|
317
|
+
"maxSseConnections": 128,
|
|
318
|
+
"maxConnections": 256,
|
|
319
|
+
"sessionTtlMs": 86400000
|
|
168
320
|
}
|
|
169
321
|
```
|
|
170
322
|
|
|
171
|
-
|
|
323
|
+
输入附件通过 Session 临时保存,默认单个文件最多 16 MiB、单个 Session 最多 32 MiB、最多 16 个文件;
|
|
324
|
+
HTTP 上传总上限由 `maxAttachmentBytes` 控制,默认 32 MiB,允许调整到 64 MiB。Session 释放时附件也会
|
|
325
|
+
一起清理。ACP 会优先使用 Agent 声明支持的 image/audio/embeddedContext 能力,否则为 Agent 提供受限的
|
|
326
|
+
`file://` resource link;A2A 则以带文件名和媒体类型的二进制 Part 发送。
|
|
172
327
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
```
|
|
328
|
+
输出文件发布由 Gateway 自己的 `artifactStoragePath` 管理,默认单文件上限 512 MiB、链接有效期
|
|
329
|
+
24 小时。上传和复制均使用流,不把文件编码进 JSON;公开 URL 使用 256 位随机 token,过期文件由
|
|
330
|
+
后台清理。ACP/A2A 返回的内联二进制 Artifact 也会先落入该仓库,再在 Session 响应中改为 URL。
|
|
178
331
|
|
|
179
|
-
|
|
332
|
+
API Key 与 A2A 认证值支持 `env:VAR`。Console Password 哈希由 WebUI 管理,不要手工生成或把
|
|
333
|
+
旧 `authToken` 复制到该字段。
|
|
180
334
|
|
|
181
|
-
|
|
335
|
+
运行记录保存在配置文件同目录的 `nexus-agentd-runs.json` sidecar 中,默认最多保留 1000 条。
|
|
336
|
+
记录文件使用 `0600` 权限和原子替换;进行中的任务若遇到 Gateway 重启,会在下次启动时标记为
|
|
337
|
+
“已中断/失败”,而不会一直显示为运行中。
|
|
182
338
|
|
|
183
|
-
|
|
184
|
-
会续接同一 ACP Session;每轮输出单独保存,不与上一轮文本拼接。
|
|
339
|
+
## API
|
|
185
340
|
|
|
186
|
-
|
|
341
|
+
匿名端点:
|
|
187
342
|
|
|
188
343
|
```text
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
canceled
|
|
344
|
+
GET /health
|
|
345
|
+
GET /v1/bootstrap/status
|
|
346
|
+
POST /v1/bootstrap/initialize
|
|
347
|
+
GET /v1/admin/auth/status
|
|
348
|
+
POST /v1/admin/auth/login
|
|
349
|
+
POST /v1/admin/auth/logout
|
|
196
350
|
```
|
|
197
351
|
|
|
198
|
-
|
|
352
|
+
管理员 Cookie 端点:
|
|
199
353
|
|
|
200
354
|
```text
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
355
|
+
GET /v1/admin/overview
|
|
356
|
+
GET /v1/admin/config
|
|
357
|
+
GET /v1/admin/agents
|
|
358
|
+
GET /v1/admin/runs
|
|
359
|
+
GET /v1/admin/runs/:id
|
|
360
|
+
PUT /v1/admin/agents/:id
|
|
361
|
+
DELETE /v1/admin/agents/:id
|
|
362
|
+
PUT /v1/admin/config/workspace-roots
|
|
363
|
+
PUT /v1/admin/config/runtime
|
|
364
|
+
PUT /v1/admin/password
|
|
365
|
+
GET /v1/admin/api-keys
|
|
366
|
+
POST /v1/admin/api-keys
|
|
367
|
+
PATCH /v1/admin/api-keys/:id
|
|
368
|
+
DELETE /v1/admin/api-keys/:id
|
|
369
|
+
POST /v1/admin/api-keys/:id/reveal
|
|
370
|
+
POST /v1/admin/api-keys/:id/regenerate
|
|
371
|
+
GET /v1/admin/files/roots
|
|
372
|
+
GET /v1/admin/files
|
|
373
|
+
GET /v1/admin/files/content
|
|
374
|
+
PUT /v1/admin/files/content
|
|
375
|
+
DELETE /v1/admin/files/content
|
|
376
|
+
POST /v1/admin/files/directory
|
|
377
|
+
POST /v1/admin/files/move
|
|
378
|
+
POST /v1/admin/files/publish
|
|
214
379
|
```
|
|
215
380
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
Session 当前保存在内存中。agentd 重启会终止 ACP 子进程,旧 Gateway Session 不可恢复。
|
|
219
|
-
|
|
220
|
-
## 权限与输入
|
|
221
|
-
|
|
222
|
-
`permissionPolicy=ask` 时,ACP permission request 会进入 `permission_required`,Session 响应
|
|
223
|
-
包含问题和选项。AgentNexus 通过 `message` 返回:
|
|
224
|
-
|
|
225
|
-
- 选项序号,例如 `1`
|
|
226
|
-
- option ID
|
|
227
|
-
- option name
|
|
228
|
-
- `deny`、`cancel`、`拒绝` 或 `取消`
|
|
229
|
-
|
|
230
|
-
ACP elicitation 会进入 `input_required`。简单单字段表单可直接回复文本、数字、布尔值或列表;
|
|
231
|
-
多字段结构化输入使用 JSON object。
|
|
381
|
+
Bearer API Key 数据面:
|
|
232
382
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
383
|
+
```text
|
|
384
|
+
GET /v1/agents
|
|
385
|
+
POST /v1/sessions
|
|
386
|
+
GET /v1/sessions/:id
|
|
387
|
+
POST /v1/sessions/:id/attachments
|
|
388
|
+
POST /v1/sessions/:id/message
|
|
389
|
+
POST /v1/sessions/:id/cancel
|
|
390
|
+
GET /v1/sessions/:id/events
|
|
391
|
+
GET /v1/sessions/:id/files
|
|
392
|
+
GET /v1/sessions/:id/files/content
|
|
393
|
+
POST /v1/sessions/:id/files/publish
|
|
394
|
+
```
|
|
242
395
|
|
|
243
|
-
|
|
396
|
+
`GET /v1/artifacts/:token/:expiresAt/:name` 是匿名下载端点;它只接受发布操作生成的不可猜测 token,并在 TTL
|
|
397
|
+
到期后返回 404。该端点不支持目录列举,也不能据此访问原工作区。
|
|
244
398
|
|
|
245
|
-
|
|
399
|
+
API Key 的 Agent scope 在 Agent inventory、Session 创建和后续 Session 操作上都会检查;Session
|
|
400
|
+
还绑定创建它的 Key,其他 Key 即使拥有同一 Agent scope 也不能读取或控制该 Session。
|
|
401
|
+
运行记录接口仅接受管理员 Cookie,数据面 API Key 无权读取。
|
|
246
402
|
|
|
247
|
-
|
|
248
|
-
- LAN 监听时使用强随机 Token 和主机防火墙限制 Koishi 来源 IP。
|
|
249
|
-
- 不要直接暴露到公网;需要跨网络时在前面部署 HTTPS/mTLS 反向代理。
|
|
250
|
-
- 使用权限受限的专用系统账号运行 agentd。
|
|
403
|
+
## 局域网安全
|
|
251
404
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
405
|
+
- 默认仍只监听 localhost;需要 LAN 时显式使用 `--host 0.0.0.0`,并用主机防火墙限制来源。
|
|
406
|
+
- LAN 上的纯 HTTP 为兼容 Cookie 默认不设置 `Secure`;跨不可信网络应放在 HTTPS/mTLS 反向代理
|
|
407
|
+
或可信隧道后,并将 `secureAdminCookies` 设为 `true`。
|
|
408
|
+
- 管理写操作要求同源 `Origin`,Cookie 使用 `SameSite=Strict`;登录和无效 API Key 有失败限速。
|
|
409
|
+
- File Browser 的所有路径都在 realpath 后重新校验工作区边界;Session 发布还同时校验 API Key
|
|
410
|
+
scope 与 Session 所有权。公开链接应只发送给预期接收者。
|
|
411
|
+
- 不直接暴露公网。使用专用低权限系统账号运行 Gateway。
|
|
412
|
+
- 配置更新使用 `0600` 临时文件校验后原子替换;Secret 不进入普通响应和结构化错误日志。
|
|
255
413
|
|
|
256
414
|
## 验证
|
|
257
415
|
|
|
@@ -261,3 +419,7 @@ npm run typecheck
|
|
|
261
419
|
npm run build
|
|
262
420
|
npm pack --dry-run --json
|
|
263
421
|
```
|
|
422
|
+
|
|
423
|
+
## License
|
|
424
|
+
|
|
425
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentSessionRuntime, AgentSessionSink } from '../session-contract.js';
|
|
2
|
+
import type { AgentdA2AConfig, AgentdAgentView, AgentdInputAttachment } from '../types.js';
|
|
3
|
+
export declare function probeA2AAgent(id: string, config: AgentdA2AConfig): Promise<AgentdAgentView>;
|
|
4
|
+
export declare class A2AClientRuntime implements AgentSessionRuntime {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly sink;
|
|
7
|
+
private readonly promptTimeoutMs;
|
|
8
|
+
private client?;
|
|
9
|
+
private card?;
|
|
10
|
+
private taskId;
|
|
11
|
+
private contextId;
|
|
12
|
+
private prompting;
|
|
13
|
+
private disposed;
|
|
14
|
+
private activeController?;
|
|
15
|
+
private readonly artifactCache;
|
|
16
|
+
private readonly emittedMessages;
|
|
17
|
+
constructor(config: AgentdA2AConfig, sink: AgentSessionSink, promptTimeoutMs: number);
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
prompt(message: string, attachments?: AgentdInputAttachment[]): Promise<void>;
|
|
20
|
+
respondPending(message: string, attachments?: AgentdInputAttachment[]): Promise<void>;
|
|
21
|
+
cancel(): Promise<void>;
|
|
22
|
+
dispose(): Promise<void>;
|
|
23
|
+
private messageRequest;
|
|
24
|
+
private processResponse;
|
|
25
|
+
private processTask;
|
|
26
|
+
private processMessage;
|
|
27
|
+
private processStatus;
|
|
28
|
+
private processArtifact;
|
|
29
|
+
private captureIds;
|
|
30
|
+
}
|