qwen-audio-agent 0.10.0 → 0.11.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 +41 -12
- package/README_EN.md +48 -12
- package/cli/package.json +1 -1
- package/cli/src/arguments.mjs +22 -18
- package/cli/src/launcher.mjs +25 -8
- package/cli/src/runtime.mjs +9 -16
- package/docs/architecture.md +5 -4
- package/docs/configuration.md +82 -66
- package/package.json +1 -1
- package/scripts/claude-code-acp +10 -0
- package/scripts/codex-acp +10 -1
- package/scripts/openclaw +80 -39
- package/scripts/opencode-server +23 -8
- package/scripts/prepare-openclaw-config.mjs +11 -0
- package/scripts/release-check +2 -2
- package/scripts/sync-openclaw-gateway-token.mjs +9 -0
- package/scripts/verify-package.mjs +0 -1
- package/server/package.json +1 -1
- package/server/src/agent/acp-backend-adapter.mjs +307 -29
- package/server/src/agent/acp-backend-session-utils.mjs +36 -23
- package/server/src/agent/acp-process-client.mjs +55 -6
- package/server/src/agent/agent-client.mjs +4 -0
- package/server/src/agent/backends/claude.mjs +5 -2
- package/server/src/agent/backends/codex.mjs +2 -1
- package/server/src/agent/backends/hermes.mjs +1 -1
- package/server/src/agent/backends/openclaw.mjs +37 -2
- package/server/src/agent/backends/opencode.mjs +25 -0
- package/server/src/agent/backends/qoder.mjs +1 -8
- package/server/src/agent/coordinator.mjs +6 -15
- package/server/src/agent/openclaw-adapter.mjs +40 -3
- package/server/src/core/config.mjs +46 -39
- package/server/src/index.mjs +9 -2
- package/server/src/process/backend-drivers/openclaw-auth.mjs +94 -0
- package/server/src/process/managed-backend.mjs +22 -11
- package/server/src/voice/realtime-gateway.mjs +30 -5
- package/server/src/voice/tools/tool-call-handler.mjs +24 -23
- package/shared/backend-catalog.mjs +0 -1
- package/shared/backend-setup.mjs +479 -0
- package/shared/runtime-environment.mjs +44 -19
- package/tui/package.json +1 -1
- package/web/dist/assets/{index-BeamDvsE.js → index-DfCChshH.js} +28 -28
- package/web/dist/index.html +1 -1
package/README.md
CHANGED
|
@@ -52,13 +52,13 @@ Agent 也应该始终在场。
|
|
|
52
52
|
|
|
53
53
|
| 后台 Agent | 接入方式 | 接入准备 | 推荐指数 |
|
|
54
54
|
| --- | --- | --- | --- |
|
|
55
|
-
| OpenCode | 原生 ACP |
|
|
56
|
-
| OpenClaw | 内置 ACP 桥接 |
|
|
57
|
-
| Qoder | 原生 ACP |
|
|
58
|
-
| Hermes | 原生 ACP |
|
|
59
|
-
| CodeBuddy | 原生 ACP |
|
|
60
|
-
| Codex | 外部 ACP 适配 |
|
|
61
|
-
| Claude Code | 外部 ACP 适配 |
|
|
55
|
+
| OpenCode | 原生 ACP | 支持自动安装和百炼配置 | ★★★★★ |
|
|
56
|
+
| OpenClaw | 内置 ACP 桥接 | 支持自动安装和百炼配置 | ★★★★★ |
|
|
57
|
+
| Qoder | 原生 ACP | 用户自行安装和配置 | ★★★★★ |
|
|
58
|
+
| Hermes | 原生 ACP | 用户自行安装和配置 | ★★★★☆ |
|
|
59
|
+
| CodeBuddy | 原生 ACP | 用户自行安装和配置 | ★★★★☆ |
|
|
60
|
+
| Codex | 外部 ACP 适配 | 用户自行安装和配置 | ★★★★☆ |
|
|
61
|
+
| Claude Code | 外部 ACP 适配 | 用户自行安装和配置 | ★★★★☆ |
|
|
62
62
|
|
|
63
63
|
推荐指数综合反映当前集成完整度、兼容性和实际验证程度:五星表示已经过充分测试的
|
|
64
64
|
推荐集成,四星表示正在开发或尚未完成同等范围验证。
|
|
@@ -126,15 +126,30 @@ qwenaudio config
|
|
|
126
126
|
```dotenv
|
|
127
127
|
DASHSCOPE_API_KEY=your-key
|
|
128
128
|
AGENT_PROTOCOL=openclaw
|
|
129
|
+
QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
3.
|
|
132
|
+
3. 只读检查后台 Agent 是否已经准备好:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
qwenaudio setup
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
该命令不会安装 Agent、触发登录或修改配置。也可以只检查一个后台,或输出供
|
|
139
|
+
桌面版和脚本使用的结构化结果:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
qwenaudio setup --backend openclaw
|
|
143
|
+
qwenaudio setup --json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
4. 在一个终端中启动 Gateway:
|
|
132
147
|
|
|
133
148
|
```bash
|
|
134
149
|
qwenaudio
|
|
135
150
|
```
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
5. 另开一个终端,启动 TUI:
|
|
138
153
|
|
|
139
154
|
```bash
|
|
140
155
|
qwenaudio tui
|
|
@@ -201,7 +216,10 @@ qwenaudio gateway uninstall
|
|
|
201
216
|
|
|
202
217
|
## 选择后台 Agent
|
|
203
218
|
|
|
204
|
-
通过 `AGENT_PROTOCOL` 选择后台 Agent
|
|
219
|
+
通过 `AGENT_PROTOCOL` 选择后台 Agent(必填,没有默认值)。OpenCode 和 OpenClaw
|
|
220
|
+
支持自动下载;配置 `DASHSCOPE_API_KEY` 和 `QWEN_AUDIO_AGENT_BACKEND_MODEL`
|
|
221
|
+
后即可自动接入百炼模型。未指定后台模型且用户已经安装并配置对应 Agent 时,则
|
|
222
|
+
完整复用用户环境。使用 OpenClaw:
|
|
205
223
|
|
|
206
224
|
```dotenv
|
|
207
225
|
AGENT_PROTOCOL=openclaw
|
|
@@ -217,7 +235,6 @@ AGENT_PROTOCOL=opencode
|
|
|
217
235
|
|
|
218
236
|
```dotenv
|
|
219
237
|
AGENT_PROTOCOL=qoder
|
|
220
|
-
QODER_MODEL=auto
|
|
221
238
|
```
|
|
222
239
|
|
|
223
240
|
Hermes、CodeBuddy、Codex 和 Claude Code 也可直接选择:
|
|
@@ -227,6 +244,9 @@ AGENT_PROTOCOL=hermes
|
|
|
227
244
|
# 或 codebuddy、codex、claude
|
|
228
245
|
```
|
|
229
246
|
|
|
247
|
+
以上其他后台暂时需要用户自行安装并完成原生配置;qwen-audio-agent 会复用其
|
|
248
|
+
用户级模型、工具、MCP、Skill 和认证。
|
|
249
|
+
|
|
230
250
|
使用其他支持 ACP stdio 的 Agent:
|
|
231
251
|
|
|
232
252
|
```dotenv
|
|
@@ -235,7 +255,16 @@ ACP_COMMAND=your-agent
|
|
|
235
255
|
ACP_ARGS=["--acp"]
|
|
236
256
|
```
|
|
237
257
|
|
|
238
|
-
通用 ACP 入口不需要修改 Gateway
|
|
258
|
+
通用 ACP 入口不需要修改 Gateway 代码。命令、参数、显示名称和工作目录可分别通过 `ACP_COMMAND`、`ACP_ARGS`、`ACP_LABEL` 和 `ACP_WORKSPACE` 配置。
|
|
259
|
+
|
|
260
|
+
后台模型遵循以下规则:
|
|
261
|
+
|
|
262
|
+
- 未指定模型:Gateway 不传模型、不调用 ACP 模型设置接口,也不猜测默认模型。
|
|
263
|
+
- 新建 Session:完全由所选 Agent 根据用户自己的配置选择模型。
|
|
264
|
+
- 恢复 Session:完全由所选 Agent 保留该 Session 原来的模型。
|
|
265
|
+
- 显式设置唯一的后台模型变量 `QWEN_AUDIO_AGENT_BACKEND_MODEL`:Gateway 才通过
|
|
266
|
+
ACP 强制覆盖 qwen-audio-agent 管理的 Session,并验证设置结果;不支持或无法
|
|
267
|
+
确认生效时会明确报错。
|
|
239
268
|
|
|
240
269
|
后台权限默认使用 `native`,由后台 Agent 在需要时询问。只有在可信项目中,并且
|
|
241
270
|
明确接受自动执行命令和修改文件时,才应启用:
|
package/README_EN.md
CHANGED
|
@@ -63,13 +63,13 @@ module walkthrough.
|
|
|
63
63
|
|
|
64
64
|
| Backend Agent | Integration | Setup | Rating |
|
|
65
65
|
| --- | --- | --- | --- |
|
|
66
|
-
| OpenCode | Native ACP | Automatic installation supported | ★★★★★ |
|
|
67
|
-
| OpenClaw | Built-in ACP Bridge | Automatic installation supported | ★★★★★ |
|
|
68
|
-
| Qoder | Native ACP |
|
|
69
|
-
| Hermes | Native ACP |
|
|
70
|
-
| CodeBuddy | Native ACP |
|
|
71
|
-
| Codex | External ACP Adapter |
|
|
72
|
-
| Claude Code | External ACP Adapter |
|
|
66
|
+
| OpenCode | Native ACP | Automatic installation and Bailian setup supported | ★★★★★ |
|
|
67
|
+
| OpenClaw | Built-in ACP Bridge | Automatic installation and Bailian setup supported | ★★★★★ |
|
|
68
|
+
| Qoder | Native ACP | User installation and configuration required | ★★★★★ |
|
|
69
|
+
| Hermes | Native ACP | User installation and configuration required | ★★★★☆ |
|
|
70
|
+
| CodeBuddy | Native ACP | User installation and configuration required | ★★★★☆ |
|
|
71
|
+
| Codex | External ACP Adapter | User installation and configuration required | ★★★★☆ |
|
|
72
|
+
| Claude Code | External ACP Adapter | User installation and configuration required | ★★★★☆ |
|
|
73
73
|
|
|
74
74
|
Ratings reflect the current integration completeness, compatibility, and
|
|
75
75
|
extent of real-world validation. Five stars identify recommended integrations
|
|
@@ -147,15 +147,31 @@ qwenaudio config
|
|
|
147
147
|
```dotenv
|
|
148
148
|
DASHSCOPE_API_KEY=your-key
|
|
149
149
|
AGENT_PROTOCOL=openclaw
|
|
150
|
+
QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
|
|
150
151
|
```
|
|
151
152
|
|
|
152
|
-
3.
|
|
153
|
+
3. Check that the backend Agent is ready without changing it:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
qwenaudio setup
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This command does not install an Agent, start authentication, or modify
|
|
160
|
+
configuration. You can inspect one backend or produce structured output for
|
|
161
|
+
the desktop app and scripts:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
qwenaudio setup --backend openclaw
|
|
165
|
+
qwenaudio setup --json
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
4. Start the Gateway in one terminal:
|
|
153
169
|
|
|
154
170
|
```bash
|
|
155
171
|
qwenaudio
|
|
156
172
|
```
|
|
157
173
|
|
|
158
|
-
|
|
174
|
+
5. Open another terminal and start the TUI:
|
|
159
175
|
|
|
160
176
|
```bash
|
|
161
177
|
qwenaudio tui
|
|
@@ -228,7 +244,11 @@ qwenaudio gateway uninstall
|
|
|
228
244
|
## Choose a Backend Agent
|
|
229
245
|
|
|
230
246
|
Select the backend Agent with `AGENT_PROTOCOL` (required, no default value).
|
|
231
|
-
|
|
247
|
+
OpenCode and OpenClaw can be downloaded automatically. Configure
|
|
248
|
+
`DASHSCOPE_API_KEY` and `QWEN_AUDIO_AGENT_BACKEND_MODEL` to connect them to a
|
|
249
|
+
Bailian model automatically. When no backend model is specified and the Agent
|
|
250
|
+
is already installed and configured, qwen-audio-agent fully reuses the user's
|
|
251
|
+
existing environment. Use OpenClaw:
|
|
232
252
|
|
|
233
253
|
```dotenv
|
|
234
254
|
AGENT_PROTOCOL=openclaw
|
|
@@ -244,7 +264,6 @@ Use Qoder:
|
|
|
244
264
|
|
|
245
265
|
```dotenv
|
|
246
266
|
AGENT_PROTOCOL=qoder
|
|
247
|
-
QODER_MODEL=auto
|
|
248
267
|
```
|
|
249
268
|
|
|
250
269
|
Hermes, CodeBuddy, Codex, and Claude Code can also be selected directly:
|
|
@@ -254,6 +273,10 @@ AGENT_PROTOCOL=hermes
|
|
|
254
273
|
# Or codebuddy, codex, or claude
|
|
255
274
|
```
|
|
256
275
|
|
|
276
|
+
These other backends currently require the user to install and configure the
|
|
277
|
+
native Agent first. qwen-audio-agent reuses its user-level model, tools, MCP
|
|
278
|
+
servers, Skills, and authentication.
|
|
279
|
+
|
|
257
280
|
Use another Agent that supports ACP over stdio:
|
|
258
281
|
|
|
259
282
|
```dotenv
|
|
@@ -262,7 +285,20 @@ ACP_COMMAND=your-agent
|
|
|
262
285
|
ACP_ARGS=["--acp"]
|
|
263
286
|
```
|
|
264
287
|
|
|
265
|
-
The generic ACP entry point requires no Gateway code changes. Configure its command, arguments, display label,
|
|
288
|
+
The generic ACP entry point requires no Gateway code changes. Configure its command, arguments, display label, and workspace with `ACP_COMMAND`, `ACP_ARGS`, `ACP_LABEL`, and `ACP_WORKSPACE`.
|
|
289
|
+
|
|
290
|
+
Backend model selection follows these rules:
|
|
291
|
+
|
|
292
|
+
- With no model configured, the Gateway sends no model, never calls the ACP
|
|
293
|
+
model-setting interface, and does not guess a default.
|
|
294
|
+
- For a new Session, the selected Agent chooses the model entirely from the
|
|
295
|
+
user's own configuration.
|
|
296
|
+
- For a resumed Session, the selected Agent preserves that Session's existing
|
|
297
|
+
model.
|
|
298
|
+
- Only the single backend model setting, `QWEN_AUDIO_AGENT_BACKEND_MODEL`,
|
|
299
|
+
makes the Gateway force the model for Sessions managed by qwen-audio-agent
|
|
300
|
+
and verify the result. A clear error is returned when the Agent does not
|
|
301
|
+
support the model or the override cannot be verified.
|
|
266
302
|
|
|
267
303
|
Backend permissions default to `native`, so the backend Agent asks when
|
|
268
304
|
permission is required. Enable the following option only in trusted projects
|
package/cli/package.json
CHANGED
package/cli/src/arguments.mjs
CHANGED
|
@@ -4,7 +4,14 @@ import {
|
|
|
4
4
|
backendNames,
|
|
5
5
|
} from '../../shared/backend-catalog.mjs'
|
|
6
6
|
|
|
7
|
-
const COMMANDS = new Set([
|
|
7
|
+
const COMMANDS = new Set([
|
|
8
|
+
'gateway',
|
|
9
|
+
'tui',
|
|
10
|
+
'webui',
|
|
11
|
+
'status',
|
|
12
|
+
'config',
|
|
13
|
+
'setup',
|
|
14
|
+
])
|
|
8
15
|
const GATEWAY_ACTIONS = new Set([
|
|
9
16
|
'run',
|
|
10
17
|
'install',
|
|
@@ -63,9 +70,6 @@ export function parseArguments(argv, env = process.env) {
|
|
|
63
70
|
env.QWEN_AUDIO_AGENT_TUI_AUDIO_MODE || 'half',
|
|
64
71
|
).toLowerCase(),
|
|
65
72
|
backend: String(env.AGENT_PROTOCOL || '').toLowerCase(),
|
|
66
|
-
attachOpenClaw: String(
|
|
67
|
-
env.OPENCLAW_ATTACH_EXISTING || '',
|
|
68
|
-
).toLowerCase() === 'true',
|
|
69
73
|
backendPermissionMode: String(
|
|
70
74
|
env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE || 'native',
|
|
71
75
|
).toLowerCase(),
|
|
@@ -75,6 +79,8 @@ export function parseArguments(argv, env = process.env) {
|
|
|
75
79
|
backendUrl: '',
|
|
76
80
|
openBrowser: true,
|
|
77
81
|
takeover: false,
|
|
82
|
+
json: false,
|
|
83
|
+
backendSpecified: false,
|
|
78
84
|
gatewayConfigurationSpecified: false,
|
|
79
85
|
}
|
|
80
86
|
let audioModeSpecified = false
|
|
@@ -86,9 +92,7 @@ export function parseArguments(argv, env = process.env) {
|
|
|
86
92
|
options.gatewayConfigurationSpecified = true
|
|
87
93
|
} else if (argument === '--backend') {
|
|
88
94
|
options.backend = nextValue(args, index++, '--backend').toLowerCase()
|
|
89
|
-
options.
|
|
90
|
-
} else if (argument === '--attach-openclaw') {
|
|
91
|
-
options.attachOpenClaw = true
|
|
95
|
+
options.backendSpecified = true
|
|
92
96
|
options.gatewayConfigurationSpecified = true
|
|
93
97
|
} else if (argument === '--backend-agent') {
|
|
94
98
|
options.backendAgent = nextValue(args, index++, '--backend-agent').trim()
|
|
@@ -110,6 +114,7 @@ export function parseArguments(argv, env = process.env) {
|
|
|
110
114
|
audioModeSpecified = true
|
|
111
115
|
} else if (argument === '--no-open') options.openBrowser = false
|
|
112
116
|
else if (argument === '--takeover') options.takeover = true
|
|
117
|
+
else if (argument === '--json') options.json = true
|
|
113
118
|
else if (argument === '--help' || argument === '-h') options.help = true
|
|
114
119
|
else throw new Error(`未知参数:${argument}`)
|
|
115
120
|
}
|
|
@@ -134,6 +139,9 @@ export function parseArguments(argv, env = process.env) {
|
|
|
134
139
|
if (!['tui', 'webui'].includes(command) && options.takeover) {
|
|
135
140
|
throw new Error('--takeover 只适用于 tui 或 webui')
|
|
136
141
|
}
|
|
142
|
+
if (command !== 'setup' && options.json) {
|
|
143
|
+
throw new Error('--json 只适用于 setup')
|
|
144
|
+
}
|
|
137
145
|
if (command !== 'tui' && audioModeSpecified) {
|
|
138
146
|
throw new Error('--audio-mode 只适用于 tui')
|
|
139
147
|
}
|
|
@@ -159,17 +167,9 @@ export function parseArguments(argv, env = process.env) {
|
|
|
159
167
|
options.backendUrl = definition?.baseUrlEnvironment
|
|
160
168
|
? cleanOrigin(options.backendUrl || configuredBackendUrl, '后台地址')
|
|
161
169
|
: ''
|
|
162
|
-
if (options.attachOpenClaw && options.backend !== 'openclaw') {
|
|
163
|
-
throw new Error('--attach-openclaw 只适用于 OpenClaw')
|
|
164
|
-
}
|
|
165
170
|
if (
|
|
166
|
-
|
|
167
|
-
&&
|
|
168
|
-
) {
|
|
169
|
-
throw new Error('最高权限模式只支持由 Gateway 启动的后台 Agent')
|
|
170
|
-
}
|
|
171
|
-
if (
|
|
172
|
-
definition
|
|
171
|
+
command !== 'setup'
|
|
172
|
+
&& definition
|
|
173
173
|
&& options.backendPermissionMode === 'full'
|
|
174
174
|
&& !definition.supportsFullPermission
|
|
175
175
|
) {
|
|
@@ -208,15 +208,19 @@ export function helpText() {
|
|
|
208
208
|
' qwenaudio webui [选项] 打开现有 Gateway 的 WebUI',
|
|
209
209
|
' qwenaudio status [选项] gateway status 的兼容别名',
|
|
210
210
|
' qwenaudio config 显示用户配置文件位置',
|
|
211
|
+
' qwenaudio setup [选项] 只读检查后台 Agent 接入准备情况',
|
|
211
212
|
'',
|
|
212
213
|
'Gateway 选项:',
|
|
213
214
|
' --url URL Gateway 地址(默认 http://127.0.0.1:3101)',
|
|
214
215
|
' --backend NAME 必填:openclaw、opencode、qoder、hermes、codebuddy、codex、claude 或 acp(也可在 config.env 设置 AGENT_PROTOCOL)',
|
|
215
|
-
' --attach-openclaw 连接用户已启动的 OpenClaw Gateway',
|
|
216
216
|
' --backend-permission-mode MODE native(默认)或 full(最高权限)',
|
|
217
217
|
' --backend-url URL 后台 Server 地址',
|
|
218
218
|
' --backend-agent ID 指定协调 Agent',
|
|
219
219
|
'',
|
|
220
|
+
'Setup 选项:',
|
|
221
|
+
' --backend NAME 只检查指定后台;默认检查全部后台',
|
|
222
|
+
' --json 输出供桌面版或脚本使用的 JSON',
|
|
223
|
+
'',
|
|
220
224
|
'界面选项:',
|
|
221
225
|
' --session ID 复用指定语音会话',
|
|
222
226
|
' --audio-mode MODE Linux / Windows 使用 half(默认)或 full',
|
package/cli/src/launcher.mjs
CHANGED
|
@@ -2,6 +2,10 @@ import { dirname, resolve } from 'node:path'
|
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
3
3
|
import { loadRuntimeEnvironment } from '../../shared/runtime-environment.mjs'
|
|
4
4
|
import { backendDefinition } from '../../shared/backend-catalog.mjs'
|
|
5
|
+
import {
|
|
6
|
+
formatBackendSetup,
|
|
7
|
+
inspectBackendSetups,
|
|
8
|
+
} from '../../shared/backend-setup.mjs'
|
|
5
9
|
import { helpText, parseArguments } from './arguments.mjs'
|
|
6
10
|
import {
|
|
7
11
|
ensureRuntime,
|
|
@@ -29,18 +33,13 @@ async function runMinimal(options) {
|
|
|
29
33
|
|
|
30
34
|
function applyGatewayOptions(env, options) {
|
|
31
35
|
env.AGENT_PROTOCOL = options.backend
|
|
32
|
-
|
|
33
|
-
env.OPENCLAW_ATTACH_EXISTING = 'true'
|
|
34
|
-
} else {
|
|
35
|
-
delete env.OPENCLAW_ATTACH_EXISTING
|
|
36
|
-
}
|
|
36
|
+
const definition = backendDefinition(options.backend)
|
|
37
37
|
env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE = options.backendPermissionMode
|
|
38
38
|
if (options.backendAgent) {
|
|
39
39
|
env.QWEN_AUDIO_AGENT_BACKEND_AGENT = options.backendAgent
|
|
40
40
|
} else {
|
|
41
41
|
delete env.QWEN_AUDIO_AGENT_BACKEND_AGENT
|
|
42
42
|
}
|
|
43
|
-
const definition = backendDefinition(options.backend)
|
|
44
43
|
if (definition?.baseUrlEnvironment) {
|
|
45
44
|
env[definition.baseUrlEnvironment] = options.backendUrl
|
|
46
45
|
}
|
|
@@ -72,7 +71,15 @@ export async function main(argv, {
|
|
|
72
71
|
env = process.env,
|
|
73
72
|
stdout = process.stdout,
|
|
74
73
|
signalSource = process,
|
|
75
|
-
prepareEnvironment = () => loadRuntimeEnvironment({
|
|
74
|
+
prepareEnvironment = ({ readOnly = false } = {}) => loadRuntimeEnvironment({
|
|
75
|
+
root,
|
|
76
|
+
env,
|
|
77
|
+
readOnly,
|
|
78
|
+
}),
|
|
79
|
+
inspectSetups = options => inspectBackendSetups({
|
|
80
|
+
env,
|
|
81
|
+
backend: options.backendSpecified ? options.backend : '',
|
|
82
|
+
}),
|
|
76
83
|
runMinimalTui = runMinimal,
|
|
77
84
|
prepareRuntime = options => ensureRuntime(options, { root, env }),
|
|
78
85
|
inspectGateway = url => readGatewayHealth(url),
|
|
@@ -82,7 +89,8 @@ export async function main(argv, {
|
|
|
82
89
|
runWebUi = options => launchWebUi(options),
|
|
83
90
|
acquireInstance = directory => acquireCliInstance(directory),
|
|
84
91
|
} = {}) {
|
|
85
|
-
const
|
|
92
|
+
const setupCommand = argv[0] === 'setup'
|
|
93
|
+
const environment = prepareEnvironment({ readOnly: setupCommand })
|
|
86
94
|
const options = parseArguments(argv, env)
|
|
87
95
|
if (options.help) {
|
|
88
96
|
stdout.write(`${helpText()}\n`)
|
|
@@ -93,6 +101,15 @@ export async function main(argv, {
|
|
|
93
101
|
|| resolve(environment.configDirectory, 'config.env')}\n`)
|
|
94
102
|
return 0
|
|
95
103
|
}
|
|
104
|
+
if (options.command === 'setup') {
|
|
105
|
+
const report = inspectSetups(options)
|
|
106
|
+
stdout.write(options.json
|
|
107
|
+
? `${JSON.stringify(report, null, 2)}\n`
|
|
108
|
+
: `${formatBackendSetup(report)}\n`)
|
|
109
|
+
const selected = report.backends.find(item => item.selected)
|
|
110
|
+
|| (options.backendSpecified ? report.backends[0] : null)
|
|
111
|
+
return selected && !selected.ready ? 1 : 0
|
|
112
|
+
}
|
|
96
113
|
|
|
97
114
|
if (
|
|
98
115
|
(options.command === 'gateway' && options.gatewayAction !== 'run')
|
package/cli/src/runtime.mjs
CHANGED
|
@@ -38,14 +38,7 @@ export function resolveBackend(options = {}, env = process.env) {
|
|
|
38
38
|
if (!definition) throw new Error(
|
|
39
39
|
`不支持的后台 Agent:${protocol}(可选 ${backendNames().join('、')})`,
|
|
40
40
|
)
|
|
41
|
-
const
|
|
42
|
-
options.attachOpenClaw === true
|
|
43
|
-
|| String(env.OPENCLAW_ATTACH_EXISTING || '').toLowerCase() === 'true'
|
|
44
|
-
)
|
|
45
|
-
if (attachOpenClaw && protocol !== 'openclaw') {
|
|
46
|
-
throw new Error('连接已有 OpenClaw Gateway 只适用于 OpenClaw')
|
|
47
|
-
}
|
|
48
|
-
const ownership = attachOpenClaw ? 'external' : 'owned'
|
|
41
|
+
const ownership = 'owned'
|
|
49
42
|
const permissionMode = String(
|
|
50
43
|
options.backendPermissionMode
|
|
51
44
|
|| env.QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE
|
|
@@ -66,7 +59,6 @@ export function resolveBackend(options = {}, env = process.env) {
|
|
|
66
59
|
return {
|
|
67
60
|
protocol,
|
|
68
61
|
ownership,
|
|
69
|
-
attachOpenClaw,
|
|
70
62
|
permissionMode,
|
|
71
63
|
agentId: String(
|
|
72
64
|
options.backendAgent || env.QWEN_AUDIO_AGENT_BACKEND_AGENT || '',
|
|
@@ -177,18 +169,15 @@ function waitForReadiness(child, readiness, label) {
|
|
|
177
169
|
}
|
|
178
170
|
|
|
179
171
|
function backendEnvironment(env, backend) {
|
|
172
|
+
const definition = backendDefinition(backend.protocol)
|
|
180
173
|
const next = {
|
|
181
174
|
...env,
|
|
182
175
|
AGENT_PROTOCOL: backend.protocol,
|
|
183
|
-
...(backend.attachOpenClaw
|
|
184
|
-
? { OPENCLAW_ATTACH_EXISTING: 'true' }
|
|
185
|
-
: {}),
|
|
186
176
|
QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE: backend.permissionMode,
|
|
187
177
|
...(backend.agentId
|
|
188
178
|
? { QWEN_AUDIO_AGENT_BACKEND_AGENT: backend.agentId }
|
|
189
179
|
: {}),
|
|
190
180
|
}
|
|
191
|
-
const definition = backendDefinition(backend.protocol)
|
|
192
181
|
if (!definition?.baseUrlEnvironment) return next
|
|
193
182
|
const target = new URL(backend.baseUrl)
|
|
194
183
|
next[definition.baseUrlEnvironment] = backend.baseUrl
|
|
@@ -218,7 +207,9 @@ function gatewaySpawn(root, platform, env, target, options) {
|
|
|
218
207
|
PORT: String(options.listenPort || target.port || '80'),
|
|
219
208
|
},
|
|
220
209
|
detached: platform !== 'win32',
|
|
221
|
-
|
|
210
|
+
// Keep a private IPC channel so the Gateway can detect an npm/CLI
|
|
211
|
+
// launcher that disappears before its JavaScript signal handlers run.
|
|
212
|
+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
222
213
|
},
|
|
223
214
|
}
|
|
224
215
|
}
|
|
@@ -243,7 +234,7 @@ export class ManagedRuntime {
|
|
|
243
234
|
if (this.platform !== 'win32' && Number.isInteger(child.pid)) {
|
|
244
235
|
try {
|
|
245
236
|
// Managed services are spawned as process-group leaders. Signalling
|
|
246
|
-
// the group also stops
|
|
237
|
+
// the group also stops package-manager and backend descendants.
|
|
247
238
|
this.killImpl(-child.pid, signal)
|
|
248
239
|
continue
|
|
249
240
|
} catch {
|
|
@@ -294,6 +285,8 @@ export async function ensureRuntime(options, {
|
|
|
294
285
|
const runtime = new ManagedRuntime([], { platform })
|
|
295
286
|
const local = isLocalGateway(options.url)
|
|
296
287
|
const backend = resolveBackend(options, env)
|
|
288
|
+
const backendLabel = backendDefinition(backend.protocol)?.label
|
|
289
|
+
|| backend.protocol
|
|
297
290
|
let health = await readGatewayHealth(options.url, fetchImpl)
|
|
298
291
|
const existingGateway = Boolean(health)
|
|
299
292
|
|
|
@@ -350,7 +343,7 @@ export async function ensureRuntime(options, {
|
|
|
350
343
|
if (health.backend?.ok !== true && options.waitForBackend !== false) {
|
|
351
344
|
throw new Error(
|
|
352
345
|
backend.ownership === 'external'
|
|
353
|
-
? `未连接到已有
|
|
346
|
+
? `未连接到已有 ${backendLabel} 后台服务,请先启动并检查 ${backend.baseUrl}`
|
|
354
347
|
: `Gateway 启动的后台 Agent 未就绪:${health.backend?.baseUrl || backend.baseUrl}`,
|
|
355
348
|
)
|
|
356
349
|
}
|
package/docs/architecture.md
CHANGED
|
@@ -299,10 +299,11 @@ own labels and interaction patterns.
|
|
|
299
299
|
The Gateway is the only core product service. The shared adapter owns one ACP
|
|
300
300
|
stdio child and stops it with the Gateway. OpenCode and Qoder run directly as
|
|
301
301
|
ACP agents; OpenCode may additionally expose its native local Session UI.
|
|
302
|
-
OpenClaw uses a small ACP bridge.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
OpenClaw uses a small ACP bridge. Its adapter always starts and owns a dedicated
|
|
303
|
+
OpenClaw Gateway with isolated runtime and Session state. It may reuse the
|
|
304
|
+
user's model and capability configuration, but it never attaches to or shares
|
|
305
|
+
Session storage with a user-running OpenClaw Gateway, and it does not activate
|
|
306
|
+
the user's external message channels.
|
|
306
307
|
|
|
307
308
|
Desktop, TUI and WebUI are replaceable Gateway clients. They must never spawn,
|
|
308
309
|
restart or stop the Gateway or a backend. Closing a UI therefore cannot affect
|