@1agents/acp-service 0.5.3 → 0.6.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/README.md +131 -0
- package/dist/bin/a2a.d.ts +1 -0
- package/dist/bin/a2a.js +50 -0
- package/dist/bin/acp-service.js +20 -2
- package/dist/src/a2a/executor.d.ts +29 -0
- package/dist/src/a2a/executor.js +144 -0
- package/dist/src/a2a/gateway.d.ts +136 -0
- package/dist/src/a2a/gateway.js +426 -0
- package/dist/src/a2a/index.d.ts +7 -0
- package/dist/src/a2a/index.js +4 -0
- package/dist/src/a2a/server.d.ts +22 -0
- package/dist/src/a2a/server.js +339 -0
- package/dist/src/a2a/store.d.ts +34 -0
- package/dist/src/a2a/store.js +468 -0
- package/dist/src/a2a/types.d.ts +26 -0
- package/dist/src/a2a/types.js +1 -0
- package/package.json +15 -8
- package/skills/acp-service/SKILL.md +90 -0
- package/skills/acp-service/agents/openai.yaml +3 -0
- package/skills/acp-service/references/a2a.md +183 -0
- package/skills/acp-service/references/acp.md +104 -0
- package/skills/acp-service/references/dsh.md +61 -0
- package/vendor/dsh/README.md +5 -3
- package/vendor/dsh/a2a-executor.d.ts +26 -0
- package/vendor/dsh/a2a-executor.js +169 -0
- package/vendor/dsh/a2a.d.ts +15 -0
- package/vendor/dsh/a2a.js +32 -0
- package/vendor/dsh/adapter.js +4 -2
- package/vendor/dsh/client.js +198 -56
- package/vendor/dsh/index.d.ts +5 -1
- package/vendor/dsh/index.js +3 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# A2A 调度、查询与完成通知
|
|
2
|
+
|
|
3
|
+
## 链路与入口
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
主 Agent / CLI → 本机 a2a-gateway → 远端 DSH /a2a SendMessage
|
|
7
|
+
→ 解析远端 cwd 与 preset → 创建或恢复 DSH 会话 → 返回 taskId
|
|
8
|
+
→ 独立执行 → GetTask / SSE / webhook → gateway 持久收件箱 → 主会话处理并 ack
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
当前为 **A2A 1.0 JSON-RPC**,SDK `@a2a-js/sdk@1.3.0`。执行端挂载于 DSH web server;`acp-service serve` 提供 ACP,不会自动开放 DSH A2A。`a2a gateway` 是调用端工具和收件箱,不是另一个 DSH 执行器。
|
|
12
|
+
|
|
13
|
+
## 远端 DSH 启用 A2A
|
|
14
|
+
|
|
15
|
+
在现有 `oneagents-acp` 配置行的 `config` 中添加:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
a2a:
|
|
19
|
+
enabled: true
|
|
20
|
+
tokenEnv: DSH_A2A_TOKEN
|
|
21
|
+
publicUrl: http://dsh-host:3080
|
|
22
|
+
defaultCwd: /home/scott
|
|
23
|
+
defaultAgentPreset: standard
|
|
24
|
+
workspaces:
|
|
25
|
+
demo: /home/scott/projects/demo
|
|
26
|
+
# 仅需要 webhook 时设置接收端实际 origin
|
|
27
|
+
pushNotificationOrigins:
|
|
28
|
+
- http://caller-host:36815
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
目录和主机为示例,应替换为实际部署值。通过 DSH 进程的受保护环境配置 `DSH_A2A_TOKEN`,然后重启 DSH。不要把真实 token 放在技能文档或对话中;DSH UI 登录凭据不是 A2A bearer token。未配置 A2A 时默认关闭,缺少 token 会拒绝激活。
|
|
32
|
+
|
|
33
|
+
- 公开发现:`GET /.well-known/agent-card.json`。
|
|
34
|
+
- 认证调用:`POST /a2a`,`Authorization: Bearer <A2A-token>`、`A2A-Version: 1.0`、`Content-Type: application/json`。
|
|
35
|
+
- `publicUrl` 必须是调用端能访问的 DSH origin;`path` 可自定义 RPC 路由。
|
|
36
|
+
- `a2a.stateDirectory` 可覆盖默认 `<DSH_HOME>/plugins/1agents-acp/a2a`。
|
|
37
|
+
|
|
38
|
+
## 调用端 gateway
|
|
39
|
+
|
|
40
|
+
先复用已有 gateway。新部署时创建受保护的 JSON 配置,例如:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"stateDirectory": "/absolute/private/a2a-gateway-state",
|
|
45
|
+
"port": 36814,
|
|
46
|
+
"remotes": {
|
|
47
|
+
"wsl-dsh": { "url": "http://dsh-host:3080", "token": "replace-with-protected-A2A-token" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
chmod 600 /absolute/private/gateway.json
|
|
54
|
+
acp-service a2a gateway --config /absolute/private/gateway.json
|
|
55
|
+
curl http://127.0.0.1:36814/health
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Unix 上 CLI 校验配置权限。gateway 工具端口固定监听 `127.0.0.1`,默认 `36814`;省略 `--no-report` 会向本机 DreamMate node 注册 `a2a-gateway`。不用 DreamMate 时加 `--no-report`,通过 CLI 使用。凭据仅保存在配置中,不传入任务参数。
|
|
59
|
+
|
|
60
|
+
callback 可选;不配置也会由后台 GetTask 查询补齐状态。需要 push 时增加:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"callback": {
|
|
65
|
+
"host": "caller-bind-IP",
|
|
66
|
+
"port": 36815,
|
|
67
|
+
"url": "http://caller-host:36815/a2a-events",
|
|
68
|
+
"token": "replace-with-separate-callback-token"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
替换可绑定的 IP 与 DSH 可达的 URL,并将 URL 的精确 origin 加入远端 `pushNotificationOrigins`。回调监听器只开放配置的事件路径,不开放工具 `/invoke`;本地工具端口拒绝浏览器 Origin 调用。`originSessionId` 是可信本地调用端使用的通知路由 ID,不是认证凭据。
|
|
74
|
+
|
|
75
|
+
## 七个调度工具
|
|
76
|
+
|
|
77
|
+
DreamMate 调用参数为 `service_id: "a2a-gateway"`、`method: 方法名`、`params: 参数对象`;先查询服务和方法契约。CLI 则从 stdin 读取同一参数 JSON:
|
|
78
|
+
|
|
79
|
+
| 方法 | 参数与用途 |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `remote_agent_spawn` | 必填 `remote, originSessionId, cwd, prompt`;可选 `agentPreset, title, notificationTarget`;新建远端任务/上下文/DSH 会话 |
|
|
82
|
+
| `remote_agent_get` | `remote, originSessionId, taskId`;当前状态、结果;离线返回缓存与 stale |
|
|
83
|
+
| `remote_agent_message` | 上述任务定位字段加 `prompt`;复用远端会话,创建新 taskId |
|
|
84
|
+
| `remote_agent_cancel` | 任务定位字段;取消这项任务自己的执行 |
|
|
85
|
+
| `remote_agent_list` | `originSessionId`;列出该主会话派发的任务 |
|
|
86
|
+
| `remote_agent_inbox` | `originSessionId`;读取未确认的完成/需要输入通知 |
|
|
87
|
+
| `remote_agent_ack` | `originSessionId, noticeId`;确认已处理,重复确认安全 |
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
acp-service a2a invoke remote_agent_spawn <<'JSON'
|
|
91
|
+
{
|
|
92
|
+
"remote": "wsl-dsh",
|
|
93
|
+
"originSessionId": "actual-parent-session-id",
|
|
94
|
+
"cwd": "/home/scott",
|
|
95
|
+
"agentPreset": "standard",
|
|
96
|
+
"title": "只读系统健康巡检",
|
|
97
|
+
"prompt": "实际采集 CPU、内存、磁盘、服务状态并总结。仅只读;不安装、不修改、不重启、不读取凭据。"
|
|
98
|
+
}
|
|
99
|
+
JSON
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
CLI 和 DreamMate 都返回业务结果对象;spawn 的 `taskId`、`contextId`、`sessionId`、实际 cwd/preset 位于该对象中,`result` 字段是任务报告文本。受理返回 `TASK_STATE_SUBMITTED` 不等于完成。
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
acp-service a2a invoke remote_agent_get <<'JSON'
|
|
106
|
+
{"remote":"wsl-dsh","originSessionId":"actual-parent-session-id","taskId":"returned-task-id"}
|
|
107
|
+
JSON
|
|
108
|
+
acp-service a2a invoke remote_agent_inbox <<'JSON'
|
|
109
|
+
{"originSessionId":"actual-parent-session-id"}
|
|
110
|
+
JSON
|
|
111
|
+
# 处理通知结果后:
|
|
112
|
+
acp-service a2a invoke remote_agent_ack <<'JSON'
|
|
113
|
+
{"originSessionId":"actual-parent-session-id","noticeId":"returned-notice-id"}
|
|
114
|
+
JSON
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
每次 spawn 都创建新会话,即使 cwd 相同。message 复用原 context/cwd/preset,创建新任务;可排队,但不是对当前轮的原生 interrupt/steer。当前 gateway 没有 `modelId`、`modeId` 或显式恢复任意 DSH session ID 的参数。
|
|
118
|
+
|
|
119
|
+
## 直接使用标准 A2A
|
|
120
|
+
|
|
121
|
+
请求体示例,认证与版本放在 HTTP headers 中:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"jsonrpc": "2.0",
|
|
126
|
+
"id": "submit-1",
|
|
127
|
+
"method": "SendMessage",
|
|
128
|
+
"params": {
|
|
129
|
+
"message": {
|
|
130
|
+
"messageId": "unique-message-id",
|
|
131
|
+
"role": "ROLE_USER",
|
|
132
|
+
"parts": [{ "text": "只读检查项目 README 并总结", "mediaType": "text/plain" }]
|
|
133
|
+
},
|
|
134
|
+
"configuration": { "returnImmediately": true },
|
|
135
|
+
"metadata": { "1agents": { "workspace": "demo", "agentPreset": "standard" } }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
响应在 `result.task`,包含 `id`、`contextId`、`metadata.1agents.sessionId/cwd/agentPreset`。`returnImmediately: true` 等待会话准备后返回任务 ID;省略则默认等待终态或需要输入状态。
|
|
141
|
+
|
|
142
|
+
`metadata.1agents` 只接受 `cwd`、`workspace`、`agentPreset`;cwd 和 workspace 不可同时传,cwd 为远端现有绝对目录,workspace 为配置别名。省略位置与预设时按远端 A2A 默认值处理。
|
|
143
|
+
|
|
144
|
+
同一会话的新任务在 `message.contextId` 传已保存 context ID;保存的 cwd/preset 不能改变。已完成 task 不可重新打开。原 task 为 input-required 时可传 `message.taskId`,配合新的 `messageId` 继续;活跃 task 上的 follow-up 被拒绝。
|
|
145
|
+
|
|
146
|
+
| 标准方法 | 用法 |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| `GetTask` | `params: { "id": "task-id" }`;查询任务状态/历史/结果 |
|
|
149
|
+
| `ListTasks` | 按协议做作用域过滤与分页 |
|
|
150
|
+
| `SubscribeToTask` | `params: { "id": "task-id" }`;SSE,从当前任务快照开始;终态任务直接查询 |
|
|
151
|
+
| `SendStreamingMessage` | 提交并 SSE 观察;客户端断开不会取消独立执行 |
|
|
152
|
+
| `CancelTask` | `params: { "id": "task-id" }`;取消任务自己的排队或运行 |
|
|
153
|
+
| `Create/Get/DeleteTaskPushNotificationConfig`、`ListTaskPushNotificationConfigs` | webhook 配置生命周期 |
|
|
154
|
+
|
|
155
|
+
支持文本 prompt;不要发送附件或旧 v0.3 消息结构。终态包括 completed、failed、canceled、rejected;input-required/auth-required 需要继续处理,不是成功完成。
|
|
156
|
+
|
|
157
|
+
## 通知、持久化与恢复
|
|
158
|
+
|
|
159
|
+
发送配置里可加入标准 `taskPushNotificationConfig`(URL 的 origin 须被允许):
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"returnImmediately": true,
|
|
164
|
+
"taskPushNotificationConfig": {
|
|
165
|
+
"url": "http://caller-host:36815/a2a-events",
|
|
166
|
+
"authentication": { "scheme": "Bearer", "credentials": "protected-callback-token" }
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
DSH webhook 发送 A2A `StreamResponse`(`application/a2a+json`),含 task/artifactUpdate/statusUpdate。它按任务排序、超时 5 秒、拒绝重定向,尽力投递且不重试。回调提示不能替代可信的 GetTask 查询。
|
|
172
|
+
|
|
173
|
+
gateway 将状态、任务归属和通知原子落盘;通知有稳定 `noticeId`,读取不会确认。默认每 3 秒后台核对任务,丢失 webhook 或 gateway 重启后仍能补齐。主机离线只导致 `stale`,不会伪造远端 failed。
|
|
174
|
+
|
|
175
|
+
若要通知主 Agent 宿主,在 gateway 配置中增加 `notificationTargets` 名称映射,每项为 `{ "url": "http://host/notice", "token": "protected-token" }`,spawn 时传 `notificationTarget` 名称。这里接收的是 gateway notice(含 originSessionId/taskId/contextId/state/result),不是原始 A2A StreamResponse。
|
|
176
|
+
|
|
177
|
+
宿主通知使用 Bearer 与稳定 `Idempotency-Key`;失败或 gateway 重启后重试,直到接收端接受或通知被 ack。宿主须先持久化/去重,再注入对应主会话并触发模型执行。HTTP 成功只代表接收,不证明主模型已运行;当前包没有自动唤醒 Codex 下一轮的宿主适配器。
|
|
178
|
+
|
|
179
|
+
执行端和 gateway 状态目录各由单个活跃实例拥有,不应手工删除运行中实例的 lock。gateway 重启不取消远端任务;DSH 重启会将中断任务标为 failed,保留已完成结果和 context 映射,新任务可用 context 恢复 DSH 会话,不自动重放中断工作。
|
|
180
|
+
|
|
181
|
+
## 共享实现
|
|
182
|
+
|
|
183
|
+
`@1agents/acp-service/a2a` 导出 `createA2AServer`、`FileA2AStore`、`RemoteAgentGateway`、`serveA2AGateway` 及类型。server 接收 `A2ABackend`,核心不依赖 DSH,工厂本身不创建网络 listener;DSH 通过公开 session-controller API 提供 backend 并挂载路由,独立入口可复用这套实现。
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# ACP CLI 与常驻服务
|
|
2
|
+
|
|
3
|
+
## 能力与前提
|
|
4
|
+
|
|
5
|
+
统一 CLI 可运行注册的原生 Agent,支持持久命名会话、一次性执行、排队、取消、历史回放、导出/导入、模型/模式控制、结构化输出和 typed flows。注册 Agent 不代表可执行文件与登录已经就绪;先检查实际安装与认证。
|
|
6
|
+
|
|
7
|
+
常驻服务为这些 Agent 提供 ACP v1 JSON-RPC 2.0 over WebSocket。WebSocket 是本包的自定义 ACP 传输,原生 adapter 仍由内嵌 runtime 管理。支持哪些内容块、模式和配置取决于 Agent。
|
|
8
|
+
|
|
9
|
+
## 本地 CLI
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
# 一次性任务
|
|
13
|
+
acp-service --cwd /absolute/project codex exec '阅读 README 并总结项目,不修改文件'
|
|
14
|
+
|
|
15
|
+
# 命名持久会话:先确保存在,再发送消息
|
|
16
|
+
acp-service --cwd /absolute/project codex sessions ensure --name review
|
|
17
|
+
acp-service --cwd /absolute/project codex -s review '调查测试失败原因,先不要修改'
|
|
18
|
+
acp-service --cwd /absolute/project codex -s review '根据刚才的证据给出修复方案'
|
|
19
|
+
|
|
20
|
+
# 排队后立即返回;不是等待任务完成
|
|
21
|
+
acp-service --cwd /absolute/project codex -s review --no-wait '完成后列出结论'
|
|
22
|
+
acp-service --cwd /absolute/project codex status -s review
|
|
23
|
+
acp-service --cwd /absolute/project codex sessions history review --limit 20
|
|
24
|
+
acp-service --cwd /absolute/project codex cancel -s review
|
|
25
|
+
|
|
26
|
+
# 结构化事件或最终文本
|
|
27
|
+
acp-service --cwd /absolute/project --format json codex exec '说明项目用途'
|
|
28
|
+
acp-service --cwd /absolute/project --format quiet claude exec '说明项目用途'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
持久 CLI 会话按 Agent 命令、绝对 cwd、可选会话名确定作用域;改变 cwd 会改变会话查找。`prompt` 需要该作用域的会话存在,`exec` 是一次性会话。默认权限模式为 `approve-reads`,非交互场景中仍受权限策略约束。
|
|
32
|
+
|
|
33
|
+
原生 Agent 提供对应选项时,CLI 可以指定模型或调整已存在会话的配置:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# 用实际公布的模型、配置键和值替换尖括号内容
|
|
37
|
+
acp-service --cwd /absolute/project --model <advertised-model-id> codex exec '任务说明'
|
|
38
|
+
acp-service --cwd /absolute/project codex set-mode <advertised-mode-id> -s review
|
|
39
|
+
acp-service --cwd /absolute/project codex set <config-key> <advertised-value> -s review
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
这些 CLI 模型/模式选项不等于 A2A spawn 支持同名参数。超时的设置操作可能已经生效,核对后再重试。
|
|
43
|
+
|
|
44
|
+
更多 runtime 选项以 `acp-service <agent> --help`、`acp-service --skill show acpx` 为准;阅读内嵌 `acpx` 技能中的示例时,此统一包使用 `acp-service` 命令和 `@1agents/acp-service/runtime`、`/flows` 导入路径。
|
|
45
|
+
|
|
46
|
+
## 常驻 HTTP/WebSocket 服务
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
acp-service serve --host 127.0.0.1 --port 36812 --no-report
|
|
50
|
+
curl http://127.0.0.1:36812/health
|
|
51
|
+
curl http://127.0.0.1:36812/agents
|
|
52
|
+
curl http://127.0.0.1:36812/manifest
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
默认端口 `36812`。CLI 未传 host 时默认监听 `0.0.0.0`,本地使用显式选择 `127.0.0.1`。服务当前没有连接认证;需要远程开放时由部署网络或认证代理限制访问。省略 `--no-report` 会向本机 DreamMate node 报备。
|
|
56
|
+
|
|
57
|
+
`GET /agents` 返回服务主机上的 Agent 清单与 `chat_ready`;发现过程不执行 Agent、不下载 adapter,也不验证登录或模型访问。`/manifest` 描述服务契约,不是认证成功证明。`ACP_STATE_DIR` 可覆盖默认 `~/.1agents/acpx-state`。
|
|
58
|
+
|
|
59
|
+
连接 `ws://127.0.0.1:36812/agents/codex`,或使用清单里的 `/agents/<agent-id>`。每帧是一个 JSON-RPC 对象;客户端要实现通知、工具权限请求和所声明的文件/终端能力。
|
|
60
|
+
|
|
61
|
+
依次发送:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{}}}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{"jsonrpc":"2.0","id":2,"method":"session/new","params":{"cwd":"/absolute/project","mcpServers":[]}}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{"jsonrpc":"2.0","id":3,"method":"session/prompt","params":{"sessionId":"returned-service-session-id","prompt":[{"type":"text","text":"阅读 README,总结项目用途"}]}}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`session/prompt` 返回时该轮才结束,输出通过 `session/update` 流式到达。`session/request_permission` 是服务向客户端发送的请求,要返回本次公布的 option ID 或取消结果,不能杜撰永久授权。
|
|
76
|
+
|
|
77
|
+
| ACP 方法 | 用途 |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `session/new` | 创建服务会话;cwd 是服务执行主机上的绝对目录 |
|
|
80
|
+
| `session/load` | 恢复同一服务会话,并回放记录的 ACP 历史 |
|
|
81
|
+
| `session/resume` | 恢复但不回放历史 |
|
|
82
|
+
| `session/prompt` | 执行一轮;普通重叠请求会被拒绝为 busy |
|
|
83
|
+
| `session/cancel` | 取消当前轮的通知,无 RPC 响应;原 prompt 会结束 |
|
|
84
|
+
| `session/close` | 释放执行资源,保留持久历史 |
|
|
85
|
+
| `session/list` | 查询当前 Agent endpoint 的可恢复会话,可按 cwd 过滤 |
|
|
86
|
+
| `session/delete` | 关闭并使服务会话不可恢复/列出 |
|
|
87
|
+
| `session/set_mode` / `session/set_config_option` | 切换 Agent 实际公布的模式或配置 |
|
|
88
|
+
|
|
89
|
+
后续请求使用 `session/new` 返回的 **服务 session ID**。`_meta.1agents.agentSessionId` 可能是原生 ID,不能混用。传输断开后的恢复应使用已有身份;不明确的已受理 prompt 不应自动重发。
|
|
90
|
+
|
|
91
|
+
## 编程入口与流程
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { serveAcpService } from '@1agents/acp-service/service';
|
|
95
|
+
const service = await serveAcpService({ host: '127.0.0.1', port: 36812, report: false });
|
|
96
|
+
// 结束时:await service.close();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- `@1agents/acp-service/runtime`:内嵌 runtime API。
|
|
100
|
+
- `@1agents/acp-service/agent-registry`:Agent registry API。
|
|
101
|
+
- `@1agents/acp-service/flows`:`defineFlow`、`acp`、`decision`、`action`、`compute`、`checkpoint` 等流程 API。
|
|
102
|
+
- `acp-service flow run ./task.flow.ts --input-file ./input.json`:运行流程;流程中的动作按用户任务授权执行。
|
|
103
|
+
|
|
104
|
+
导入包本身不会启动服务。完整协议、配置和恢复说明见随 npm 包分发的顶层 `README.md`。
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# DSH 插件使用
|
|
2
|
+
|
|
3
|
+
## 安装与服务生命周期
|
|
4
|
+
|
|
5
|
+
在兼容当前插件公开 API 的 DSH checkout 中执行:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm dsh plugin --profile web add @1agents/acp-service
|
|
9
|
+
# 本地构建也可使用绝对包目录或构建好的 tgz
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
安装后按该部署的方式重启 DSH。若使用已安装的 `dsh` 可执行文件,省略 `pnpm`。同一个包还提供 CLI,无需独立安装旧 `@1agents/dsh-acp` 或 runtime 包。
|
|
13
|
+
|
|
14
|
+
已有旧 bundle 时先停止 DSH,移除旧 bundle,再安装统一包;保留自定义配置和绑定文件。使用 profile 的 `cordis.patch.yml` 配置插件,不修改 DSH 源码或默认 profile。
|
|
15
|
+
|
|
16
|
+
默认 `serviceMode: auto`:插件复用健康的本地 ACP 服务,未运行时在 `127.0.0.1:36812` 启动内嵌服务。卸载/停止插件时,只关闭自己拥有的服务;远端 URL 或 `serviceMode: external` 不管理服务进程。
|
|
17
|
+
|
|
18
|
+
## 选择执行 Agent
|
|
19
|
+
|
|
20
|
+
新建会话时选择工作区与预设:
|
|
21
|
+
|
|
22
|
+
| 预设 | 执行者 | 模型来源 |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| `standard` | DSH 标准 Agent,使用该部署的工具和模型路由 | DSH 默认 provider/model 或会话模型选择 |
|
|
25
|
+
| `oneagents-acp-codex` | 外部 Codex Agent | Codex 原生配置和公布的模型选项 |
|
|
26
|
+
| `oneagents-acp-<agent-id>` | 对应外部 ACP Agent | 对应 Agent 原生配置 |
|
|
27
|
+
|
|
28
|
+
插件按 `/agents` 中 `chat_ready` 的条目注册 `ACP · Agent` 预设。显式配置 `agents` 可限制范围;`agents: []` 不注册 ACP 预设,但不会把普通 `standard` 预设变成 ACP。
|
|
29
|
+
|
|
30
|
+
ACP 会话的 prompt 直接交给原生 Agent。原生 Agent 拥有其模型、工具、项目指令与历史;DSH 提供界面、权限/问题交互和本地会话记录。DSH 显示外部工具进度,不会再次执行那些工具。
|
|
31
|
+
|
|
32
|
+
会话开始后保留工作目录和 Agent;切换执行 Agent 或工作区应新建会话。`standard` 不是 ACP 的 `modeId`:它是 DSH 预设 ID。
|
|
33
|
+
|
|
34
|
+
## 模型、模式与交互
|
|
35
|
+
|
|
36
|
+
ACP 会话里的 `/model`、模式与“ACP 设置”使用 Agent 公布的选项:模型/思考强度走 `session/set_config_option`,模式走 `session/set_mode`。缺失的选项不会自动生成;执行中拒绝修改配置。
|
|
37
|
+
|
|
38
|
+
普通 DSH 会话仍选择 DSH provider/model。检查实际模型时,以模型目录和会话请求记录为准;例如部署默认 MiniMax 时标准预设会使用它,换部署不能假定仍是 MiniMax。
|
|
39
|
+
|
|
40
|
+
需要工具审批、问题回答时,使用 DSH 的现有交互 UI。浏览器刷新不取消 Host 请求;停止 DSH 当前轮会发送 ACP 取消。当前插件接入支持文本 prompt,不能承诺 DSH 附件也已转发给外部 Agent。
|
|
41
|
+
|
|
42
|
+
## 配置与状态
|
|
43
|
+
|
|
44
|
+
在已有 `oneagents-acp` 配置行里设置,例如:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
config:
|
|
48
|
+
serviceMode: auto
|
|
49
|
+
serviceUrl: http://127.0.0.1:36812
|
|
50
|
+
agents: [codex]
|
|
51
|
+
reconnectAttempts: 5
|
|
52
|
+
reconnectDelayMs: 1000
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
删除 `agents` 字段可恢复自动发现。`stateDirectory` 设置 ACP 绑定目录;默认 `<DSH_HOME>/plugins/1agents-acp/sessions`。A2A 的 `a2a.stateDirectory` 是另一份状态,见 [A2A](a2a.md)。
|
|
56
|
+
|
|
57
|
+
原生 Agent 可执行文件和凭据必须能被服务进程读取。`auto` 子服务继承 DSH 环境,既有外部服务则使用自己的启动环境。安装 CLI 或看见预设都不等于认证成功。
|
|
58
|
+
|
|
59
|
+
安装配套 `@1agents/session-reader` 后,可在支持的 Claude/Codex/Grok 历史中选择“在 DSH 中继续原会话”。它恢复原生身份并导入历史,不重发旧 prompt;有活跃原生 writer 时保持只读,等待 writer 释放后恢复输入。
|
|
60
|
+
|
|
61
|
+
完整插件配置、恢复和导入 API 随包位于 `vendor/dsh/README.md`。
|
package/vendor/dsh/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# DSH plugin in @1agents/acp-service
|
|
2
2
|
|
|
3
|
-
An out-of-tree DeepSeek Harness plugin for persistent external ACP Agent sessions. It requires the local DSH plugin and preset APIs available in 0.1.7-rc.2 and is embedded with the runtime and service in the single public `@1agents/acp-service`
|
|
3
|
+
An out-of-tree DeepSeek Harness plugin for persistent external ACP Agent sessions. It requires the local DSH plugin and preset APIs available in 0.1.7-rc.2 and is embedded with the runtime and service in the single public `@1agents/acp-service` package. This directory is a private source module, not a separately installable npm package. No DSH source files are modified.
|
|
4
|
+
|
|
5
|
+
The same host also supports opt-in A2A 1.0 delegation: remote text messages create or restore DSH sessions, return task IDs, and continue execution independently of HTTP clients. Configure `a2a` on the existing plugin row, set the host's `DSH_A2A_TOKEN`, and choose its public origin, default cwd and preset. Query and subscribe through the official A2A interfaces; allowed webhook origins enable completion callbacks. See the public service README's **DSH A2A** section for the full configuration, metadata and recovery behavior. The shared server is exported as `@1agents/acp-service/a2a` and remains independent of DSH imports.
|
|
4
6
|
|
|
5
7
|
## Use
|
|
6
8
|
|
|
@@ -19,14 +21,14 @@ The package declares `dsh.bundle.patch` and its browser entry, so installation s
|
|
|
19
21
|
The plugin starts its bundled ACP service on `127.0.0.1:36812` when no service is listening. An existing healthy ACP service is reused. Start DSH normally; no separate service command is needed. To manage the service yourself, set `serviceMode: external` and run:
|
|
20
22
|
|
|
21
23
|
```sh
|
|
22
|
-
npx --yes @1agents/acp-service@^0.
|
|
24
|
+
npx --yes @1agents/acp-service@^0.6.0 serve --host 127.0.0.1 --port 36812 --no-report
|
|
23
25
|
```
|
|
24
26
|
|
|
25
27
|
The service requires each native Agent’s CLI and credentials. Installing the package alone starts no process; activating the plugin starts the service. For local development, install the built checkout with `pnpm dsh plugin --profile web add /absolute/path/1acp/packages/service`.
|
|
26
28
|
|
|
27
29
|
Choose a discovered **ACP · Agent** in the new-session Agent preset picker, choose a workspace, then send a message. ACP routes are not listed as ordinary DSH models, and the adapter rejects requests from ordinary presets, including previously saved ACP routes. Before the first turn, switching the Agent preset replaces the discovery connection and its native commands. Once a turn starts, the session keeps its remote Agent and workspace; start a new session to change Agent. Native Agent binaries and authentication belong to acp-service.
|
|
28
30
|
|
|
29
|
-
The bundle registers an ACP adapter through DSH's public streaming extension and routes the ACP presets to it. It sends newly admitted messages whose source is `user` to `session/prompt`, not to `subagent-acp`; there is no coordinating DeepSeek model call. DSH-generated workspace instructions and runtime-context messages are excluded. The external Agent owns its model, prompt, tools and native history, including any project instructions it discovers itself. DSH owns its UI and local user/assistant transcript. External tool progress is preserved as display metadata on empty text blocks in DSH's existing assistant stream records and projected onto
|
|
31
|
+
The bundle registers an ACP adapter through DSH's public streaming extension and routes the ACP presets to it. It sends newly admitted messages whose source is `user` to `session/prompt`, not to `subagent-acp`; there is no coordinating DeepSeek model call. DSH-generated workspace instructions and runtime-context messages are excluded. The external Agent owns its model, prompt, tools and native history, including any project instructions it discovers itself. DSH owns its UI and local user/assistant transcript. External tool progress is preserved as display metadata on empty text blocks in DSH's existing assistant stream records and projected onto collapsed groups of peer tool cards, separated by native prose and reasoning. ACP updates retain previously supplied fields, and replay is deduplicated by the managed turn sequence. These snapshots contain no visible text and never dispatch local tools; they use the existing persisted session format so conversations can reopen normally. Only Agent thought chunks enter the thinking stream.
|
|
30
32
|
|
|
31
33
|
## Continue imported native sessions
|
|
32
34
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { A2ABackend, A2APrepareInput, A2ARunResult, A2ATarget } from '@1agents/acp-service/a2a';
|
|
3
|
+
/** Uses public session-controller and inbox events to account for one A2A prompt's exact DSH turn. */
|
|
4
|
+
export declare class DshA2ABackend implements A2ABackend {
|
|
5
|
+
private readonly ctx;
|
|
6
|
+
private readonly executions;
|
|
7
|
+
/** @param ctx DSH plugin context that owns session-controller and execution event registrations. */
|
|
8
|
+
constructor(ctx: Context);
|
|
9
|
+
/** Create a new session or restore an explicitly addressed session without changing its workspace or preset.
|
|
10
|
+
* @param input Remote host directory, preset, and optional existing DSH session identity.
|
|
11
|
+
* @returns The resolved DSH session and its durable workspace and preset.
|
|
12
|
+
*/
|
|
13
|
+
prepare(input: A2APrepareInput): Promise<A2ATarget>;
|
|
14
|
+
/** Admit one identified queued prompt and wait only for its own turn, independent of the HTTP connection.
|
|
15
|
+
* @param target Previously prepared DSH session.
|
|
16
|
+
* @param prompt Plain-text A2A message content.
|
|
17
|
+
* @param options Task-owned request identity and cancellation signal.
|
|
18
|
+
* @returns The exact turn's ending and its final assistant text.
|
|
19
|
+
*/
|
|
20
|
+
run(target: A2ATarget, prompt: string, options: {
|
|
21
|
+
requestId: string;
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
}): Promise<A2ARunResult>;
|
|
24
|
+
private execute;
|
|
25
|
+
private agent;
|
|
26
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/** DSH session execution behind the shared A2A service's transport-independent backend. */
|
|
2
|
+
import { realpath, stat } from 'node:fs/promises';
|
|
3
|
+
import { isAbsolute } from 'node:path';
|
|
4
|
+
function resultOf(reason, text) {
|
|
5
|
+
switch (reason.kind) {
|
|
6
|
+
case 'completed': return { outcome: 'completed', text };
|
|
7
|
+
case 'blocked': return { outcome: 'input-required', text, detail: 'DSH blocked the task before its next model step' };
|
|
8
|
+
case 'error': return { outcome: 'failed', text, detail: reason.error.message };
|
|
9
|
+
case 'max-tokens': return { outcome: 'failed', text, detail: 'DSH reached the model output token limit' };
|
|
10
|
+
case 'aborted': return { outcome: 'failed', text, detail: 'DSH task execution was canceled' };
|
|
11
|
+
case 'interrupted': return { outcome: 'failed', text, detail: 'DSH task execution was interrupted' };
|
|
12
|
+
case 'forked': return { outcome: 'failed', text, detail: 'DSH task turn was closed by a session fork' };
|
|
13
|
+
// DSH's turn reasons are merge-extensible; an unknown ending cannot report success.
|
|
14
|
+
default: return { outcome: 'failed', text, detail: 'DSH returned an unsupported turn ending' };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Uses public session-controller and inbox events to account for one A2A prompt's exact DSH turn. */
|
|
18
|
+
export class DshA2ABackend {
|
|
19
|
+
ctx;
|
|
20
|
+
executions = new Map();
|
|
21
|
+
/** @param ctx DSH plugin context that owns session-controller and execution event registrations. */
|
|
22
|
+
constructor(ctx) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
}
|
|
25
|
+
/** Create a new session or restore an explicitly addressed session without changing its workspace or preset.
|
|
26
|
+
* @param input Remote host directory, preset, and optional existing DSH session identity.
|
|
27
|
+
* @returns The resolved DSH session and its durable workspace and preset.
|
|
28
|
+
*/
|
|
29
|
+
async prepare(input) {
|
|
30
|
+
const previous = input.sessionId === undefined
|
|
31
|
+
? undefined
|
|
32
|
+
: await this.ctx.sessionController.inspect(input.sessionId);
|
|
33
|
+
const requestedCwd = input.cwd ?? previous?.meta.cwd ?? process.cwd();
|
|
34
|
+
if (!isAbsolute(requestedCwd))
|
|
35
|
+
throw new Error('A2A cwd must be an absolute directory on the DSH host');
|
|
36
|
+
const cwd = await realpath(requestedCwd);
|
|
37
|
+
if (!(await stat(cwd)).isDirectory())
|
|
38
|
+
throw new Error('A2A cwd must point to a directory on the DSH host');
|
|
39
|
+
const agentPreset = input.agentPreset ?? previous?.meta.agentPreset;
|
|
40
|
+
const created = await this.ctx.sessionController.create({
|
|
41
|
+
cwd,
|
|
42
|
+
...(input.sessionId === undefined ? {} : { sessionId: input.sessionId }),
|
|
43
|
+
...(agentPreset === undefined ? {} : { agentPreset }),
|
|
44
|
+
});
|
|
45
|
+
const agent = await this.agent(created.sessionId);
|
|
46
|
+
return {
|
|
47
|
+
sessionId: created.sessionId,
|
|
48
|
+
cwd: agent.session.header.cwd ?? cwd,
|
|
49
|
+
...(created.agentPreset === undefined ? {} : { agentPreset: created.agentPreset }),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Admit one identified queued prompt and wait only for its own turn, independent of the HTTP connection.
|
|
53
|
+
* @param target Previously prepared DSH session.
|
|
54
|
+
* @param prompt Plain-text A2A message content.
|
|
55
|
+
* @param options Task-owned request identity and cancellation signal.
|
|
56
|
+
* @returns The exact turn's ending and its final assistant text.
|
|
57
|
+
*/
|
|
58
|
+
async run(target, prompt, options) {
|
|
59
|
+
options.signal.throwIfAborted();
|
|
60
|
+
const queuedAbort = Promise.withResolvers();
|
|
61
|
+
const abort = () => { queuedAbort.reject(options.signal.reason); };
|
|
62
|
+
options.signal.addEventListener('abort', abort, { once: true });
|
|
63
|
+
const operation = (this.executions.get(target.sessionId) ?? Promise.resolve()).then(() => {
|
|
64
|
+
options.signal.removeEventListener('abort', abort);
|
|
65
|
+
options.signal.throwIfAborted();
|
|
66
|
+
return this.execute(target, prompt, options);
|
|
67
|
+
});
|
|
68
|
+
const tail = operation.then(() => undefined, () => undefined);
|
|
69
|
+
this.executions.set(target.sessionId, tail);
|
|
70
|
+
void tail.then(() => { if (this.executions.get(target.sessionId) === tail)
|
|
71
|
+
this.executions.delete(target.sessionId); });
|
|
72
|
+
try {
|
|
73
|
+
return await Promise.race([operation, queuedAbort.promise]);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
options.signal.removeEventListener('abort', abort);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async execute(target, prompt, options) {
|
|
80
|
+
const agent = await this.agent(target.sessionId);
|
|
81
|
+
options.signal.throwIfAborted();
|
|
82
|
+
const completion = Promise.withResolvers();
|
|
83
|
+
const listeners = [];
|
|
84
|
+
let messageId;
|
|
85
|
+
let turn;
|
|
86
|
+
let text = '';
|
|
87
|
+
let settled = false;
|
|
88
|
+
const owns = (message) => message.source.kind === 'user'
|
|
89
|
+
&& 'rpcId' in message.source && message.source.rpcId === options.requestId;
|
|
90
|
+
const settle = (result) => {
|
|
91
|
+
if (settled)
|
|
92
|
+
return;
|
|
93
|
+
settled = true;
|
|
94
|
+
options.signal.removeEventListener('abort', cancel);
|
|
95
|
+
completion.resolve(result);
|
|
96
|
+
};
|
|
97
|
+
const cancel = () => {
|
|
98
|
+
if (settled)
|
|
99
|
+
return;
|
|
100
|
+
if (turn !== undefined)
|
|
101
|
+
agent.cancel({ kind: 'user' }, { keepInbox: true });
|
|
102
|
+
else if (messageId !== undefined)
|
|
103
|
+
agent.inbox.remove(messageId);
|
|
104
|
+
};
|
|
105
|
+
// The session owns these temporary listeners until its turn settles. Plugin
|
|
106
|
+
// unloading removes plugin effects concurrently with the server's cancel/drain.
|
|
107
|
+
listeners.push(agent.ctx.on('agent/inbox/inserted', event => {
|
|
108
|
+
if (event.agent !== agent || !owns(event.message))
|
|
109
|
+
return;
|
|
110
|
+
messageId = event.message.id;
|
|
111
|
+
if (options.signal.aborted)
|
|
112
|
+
cancel();
|
|
113
|
+
}));
|
|
114
|
+
listeners.push(agent.ctx.on('agent/inbox/claimed', event => {
|
|
115
|
+
if (event.agent !== agent || !owns(event.message))
|
|
116
|
+
return;
|
|
117
|
+
messageId = undefined;
|
|
118
|
+
turn = event.turn;
|
|
119
|
+
if (options.signal.aborted)
|
|
120
|
+
cancel();
|
|
121
|
+
}));
|
|
122
|
+
listeners.push(agent.ctx.on('agent/inbox/discarded', event => {
|
|
123
|
+
if (event.agent === agent && owns(event.message)) {
|
|
124
|
+
settle({ outcome: 'failed', text, detail: 'DSH discarded the queued task before execution' });
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
listeners.push(agent.ctx.on('agent/disposed', event => {
|
|
128
|
+
if (event.agent === agent)
|
|
129
|
+
settle({ outcome: 'failed', text, detail: 'DSH session was disposed before the task finished' });
|
|
130
|
+
}));
|
|
131
|
+
listeners.push(agent.ctx.on('session/event', (session, event) => {
|
|
132
|
+
if (session !== agent.session || turn === undefined)
|
|
133
|
+
return;
|
|
134
|
+
if (event.type === 'assistant/message' && event.data.turn === turn) {
|
|
135
|
+
const next = event.data.message.content.filter(part => part.type === 'text').map(part => part.text).join('');
|
|
136
|
+
if (next.length > 0)
|
|
137
|
+
text = next;
|
|
138
|
+
}
|
|
139
|
+
else if (event.type === 'turn/end' && event.data.turn === turn) {
|
|
140
|
+
settle(resultOf(event.data.reason, text));
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
options.signal.addEventListener('abort', cancel, { once: true });
|
|
144
|
+
try {
|
|
145
|
+
// Recheck after event registration; cancellation can arrive during Agent restoration.
|
|
146
|
+
options.signal.throwIfAborted();
|
|
147
|
+
await this.ctx.sessionController.prompt({
|
|
148
|
+
requestId: options.requestId,
|
|
149
|
+
sessionId: agent.id,
|
|
150
|
+
mode: 'queue',
|
|
151
|
+
content: [{ type: 'text', text: prompt }],
|
|
152
|
+
}, options.signal);
|
|
153
|
+
if (options.signal.aborted)
|
|
154
|
+
cancel();
|
|
155
|
+
return await completion.promise;
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
options.signal.removeEventListener('abort', cancel);
|
|
159
|
+
for (const dispose of listeners.reverse())
|
|
160
|
+
dispose();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async agent(sessionId) {
|
|
164
|
+
const resolved = await this.ctx.sessionController.resolveAgent(sessionId);
|
|
165
|
+
if ('error' in resolved)
|
|
166
|
+
throw resolved.error;
|
|
167
|
+
return resolved.agent;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Mount the shared A2A implementation on the current DSH web host. */
|
|
2
|
+
import { type A2AServerOptions } from '@1agents/acp-service/a2a';
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
4
|
+
/** Optional host configuration; omitted configuration leaves A2A disabled. */
|
|
5
|
+
export interface DshA2AOptions extends Omit<A2AServerOptions, 'backend' | 'token' | 'stateDirectory' | 'publicUrl'> {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
token?: string;
|
|
8
|
+
/** Defaults to DSH_A2A_TOKEN; host credentials are never copied into tasks. */
|
|
9
|
+
tokenEnv?: string;
|
|
10
|
+
stateDirectory?: string;
|
|
11
|
+
/** Public DSH origin, for example its Tailscale URL. */
|
|
12
|
+
publicUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Routes and in-flight turns are released with the owning Cordis plugin. */
|
|
15
|
+
export declare function mountDshA2A(ctx: Context, options: DshA2AOptions, stateDirectory: string): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Mount the shared A2A implementation on the current DSH web host. */
|
|
2
|
+
import { createA2AServer } from '@1agents/acp-service/a2a';
|
|
3
|
+
import { DshA2ABackend } from './a2a-executor.js';
|
|
4
|
+
/** Routes and in-flight turns are released with the owning Cordis plugin. */
|
|
5
|
+
export async function mountDshA2A(ctx, options, stateDirectory) {
|
|
6
|
+
if (options.enabled === false)
|
|
7
|
+
return;
|
|
8
|
+
const token = options.token ?? process.env[options.tokenEnv ?? 'DSH_A2A_TOKEN'];
|
|
9
|
+
if (!token)
|
|
10
|
+
throw new Error('Set DSH_A2A_TOKEN or a2a.token before enabling DSH A2A');
|
|
11
|
+
await ctx.effect(async () => {
|
|
12
|
+
const server = await createA2AServer({ ...options, token, backend: new DshA2ABackend(ctx),
|
|
13
|
+
stateDirectory: options.stateDirectory ?? stateDirectory,
|
|
14
|
+
publicUrl: options.publicUrl ?? `http://127.0.0.1:${ctx.webServer.port}` });
|
|
15
|
+
const routes = [];
|
|
16
|
+
try {
|
|
17
|
+
routes.push(ctx.webServer.register({ kind: 'exact', path: '/.well-known/agent-card.json', handler: server.cardHandler }));
|
|
18
|
+
routes.push(ctx.webServer.register({ kind: 'exact', path: server.path, handler: server.handler }));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
for (const dispose of routes.reverse())
|
|
22
|
+
dispose();
|
|
23
|
+
await server.close();
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
return async () => {
|
|
27
|
+
for (const dispose of routes.reverse())
|
|
28
|
+
dispose();
|
|
29
|
+
await server.close();
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
package/vendor/dsh/adapter.js
CHANGED
|
@@ -384,6 +384,7 @@ export class AcpAdapter {
|
|
|
384
384
|
const turn = boundary?.lastTurn ?? 0;
|
|
385
385
|
const step = stepStart?.type === 'step/start' ? stepStart.data.step : 0;
|
|
386
386
|
let index = 0, current, content = '', answer = '';
|
|
387
|
+
const acpStream = { turn, step, requestId };
|
|
387
388
|
const endBlock = () => { if (current) {
|
|
388
389
|
queue.push({ type: 'block-end', index, block: { type: current, text: content } });
|
|
389
390
|
index++;
|
|
@@ -396,12 +397,13 @@ export class AcpAdapter {
|
|
|
396
397
|
if (current !== kind) {
|
|
397
398
|
endBlock();
|
|
398
399
|
current = kind;
|
|
399
|
-
queue.push({ type: 'block-start', index, blockType: kind });
|
|
400
|
+
queue.push({ type: 'block-start', index, blockType: kind, acpStream });
|
|
400
401
|
}
|
|
401
402
|
content += text;
|
|
402
403
|
if (kind === 'text')
|
|
403
404
|
answer += text;
|
|
404
|
-
|
|
405
|
+
const chunk = kind === 'text' ? { type: 'text-delta', index, text, acpStream } : { type: 'reasoning-delta', index, text, acpStream };
|
|
406
|
+
queue.push(chunk);
|
|
405
407
|
};
|
|
406
408
|
const update = (u) => {
|
|
407
409
|
const meta = u._meta?.['1agents'];
|