qwen-audio-agent 1.1.1 → 1.3.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.
Files changed (47) hide show
  1. package/PRIVACY.md +5 -0
  2. package/README.md +89 -14
  3. package/README_EN.md +100 -21
  4. package/cli/bin/qwenaudio.mjs +21 -0
  5. package/cli/package.json +1 -1
  6. package/cli/src/gateway-service.mjs +4 -2
  7. package/cli/src/launcher.mjs +20 -0
  8. package/cli/src/runtime.mjs +88 -15
  9. package/docs/architecture.md +1 -1
  10. package/docs/configuration.md +42 -0
  11. package/package.json +3 -2
  12. package/scripts/audit-dependencies.mjs +4 -10
  13. package/scripts/verify-package.mjs +167 -96
  14. package/server/package.json +2 -2
  15. package/server/src/agent/acp-process-client.mjs +27 -9
  16. package/server/src/agent/acp-session-registry.mjs +2 -1
  17. package/server/src/app/bootstrap.mjs +48 -2
  18. package/server/src/core/config.mjs +23 -19
  19. package/server/src/core/logger.mjs +16 -0
  20. package/server/src/index.mjs +45 -7
  21. package/server/src/process/managed-backend.mjs +15 -1
  22. package/server/src/task/task-manager.mjs +25 -0
  23. package/server/src/voice/active-voice-clients.mjs +7 -1
  24. package/server/src/voice/frontend-tools.mjs +184 -0
  25. package/server/src/voice/providers/dashscope.mjs +99 -0
  26. package/server/src/voice/providers/ga-protocol.mjs +114 -0
  27. package/server/src/voice/providers/openai-compatible-protocol.mjs +66 -0
  28. package/server/src/voice/providers/registry.mjs +141 -0
  29. package/server/src/voice/providers/s2s.mjs +140 -0
  30. package/server/src/voice/realtime-gateway.mjs +363 -108
  31. package/server/src/voice/realtime-provider.mjs +254 -351
  32. package/server/src/voice/response-context.mjs +37 -0
  33. package/server/src/voice/response-lifecycle.mjs +41 -0
  34. package/server/src/voice/turn-correlation.mjs +9 -3
  35. package/shared/backend-setup.mjs +17 -3
  36. package/shared/gateway-instance-lock.mjs +184 -0
  37. package/shared/logger.mjs +301 -0
  38. package/shared/realtime-events.mjs +1 -0
  39. package/shared/realtime-provider-catalog.mjs +130 -0
  40. package/shared/runtime-environment.mjs +16 -0
  41. package/tui/package.json +1 -1
  42. package/tui/src/index.mjs +34 -5
  43. package/web/dist/assets/index-BVUqEVa4.js +38 -0
  44. package/web/dist/assets/index-DNCByEc_.css +1 -0
  45. package/web/dist/index.html +2 -2
  46. package/web/dist/assets/index-BuB0EFih.css +0 -1
  47. package/web/dist/assets/index-DfCChshH.js +0 -38
package/PRIVACY.md CHANGED
@@ -21,6 +21,11 @@ qwen-audio-agent 是本地运行的语音前台,不包含内置遥测、广告
21
21
  `~/.config/qwaudio/`。API Key 等凭据不应写入仓库、对话或用户档案。卸载应用不会
22
22
  自动删除该目录,避免意外丢失用户数据。
23
23
 
24
+ 运行日志默认保存在 `~/.config/qwaudio/logs/`,不会自动上传。日志系统会脱敏常见
25
+ 凭据字段和 Bearer/API Key 文本,并且默认不记录音频、转写正文、模型回复正文、
26
+ 任务目标或任务结果。诊断日志仍可能包含本机路径、所选 Agent/模型、Session/Task
27
+ 标识和错误信息;分享日志前请再次检查,卸载应用也不会自动删除这些日志。
28
+
24
29
  ## 远程部署
25
30
 
26
31
  Gateway 默认仅供本机使用。通过反向代理开放远程访问时,部署者负责启用 HTTPS、
package/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  [![npm](https://img.shields.io/npm/v/qwen-audio-agent)](https://www.npmjs.com/package/qwen-audio-agent)
7
7
  [![node](https://img.shields.io/badge/node-%E2%89%A522.22.2-brightgreen)](https://nodejs.org/)
8
8
  [![license](https://img.shields.io/github/license/QwenAudio/qwen-audio-agent)](LICENSE)
9
+ [![WeChat](https://img.shields.io/badge/WeChat-%E5%8A%A0%E5%85%A5%E8%AE%A8%E8%AE%BA-07C160?logo=wechat&logoColor=white)](#交流与分享)
9
10
 
10
11
  ## Agent,始终在场
11
12
 
@@ -19,6 +20,12 @@
19
20
 
20
21
  ## News
21
22
 
23
+ - **2026-08-03 · [v1.3.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.3.0)**
24
+ 🎙️ 新增 [🤗 speech-to-speech](https://github.com/huggingface/speech-to-speech) 前台接入,支持本地部署 VAD、STT、LLM 与 TTS 全链路。
25
+ - **2026-08-01 · [v1.2.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.2.0)**
26
+ ⚡ 桌面版新增自动更新,优化启动速度与后台 Agent 检测。
27
+ - **2026-07-31 · [v1.1.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.1.0)**
28
+ 🤝 新增 Kimi Code CLI 后台,原生 ACP 接入。
22
29
  - **2026-07-30 · [v1.0.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.0.0)**
23
30
  🚀 正式版发布,推出内置 Gateway 的 macOS 桌面版。
24
31
  - **2026-07-28 · [v0.9.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v0.9.0)**
@@ -33,9 +40,10 @@ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
33
40
  ### 核心特色
34
41
 
35
42
  - 全双工实时语音交互、自然打断和持续多轮对话
36
- - 一键连接你喜欢的各种 Agent,使用已有的模型、工具、MCP、Skill
37
- - 对话与后台任务并行,可随时查询进度或取消任务
38
- - 任务结果自动回到当前上下文,支持继续追问和修改
43
+ - 一键选择你喜欢的办事 Agent,复用已有的工具、MCP、Skill
44
+ - 前台对话与后台任务并驾齐驱,可随时追问任务进度或取消任务
45
+ - 支持创建多个独立任务,由后台 Agent 异步执行,并持续追踪任务状态
46
+ - 任务结果自动回到当前对话,支持继续追问和修改
39
47
  - 支持 WebUI、终端 TUI 和 macOS 桌面悬浮球
40
48
  - 支持本地用户档案与跨会话个人记忆
41
49
 
@@ -75,7 +83,8 @@ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
75
83
 
76
84
  ## 安装
77
85
 
78
- 需要 Node.js 22.22.2+ 或 24.15.0+、npm 10+ 和 DashScope API Key。
86
+ 需要 Node.js 22.22.2+ 或 24.15.0+、npm 10+。使用默认的 DashScope
87
+ 实时语音前台时,还需要 DashScope API Key。
79
88
  仓库提供 `.nvmrc` 和 `.node-version`;使用 nvm 时可直接运行 `nvm use`。
80
89
 
81
90
  一键安装(推荐,从 npm 安装):
@@ -162,6 +171,55 @@ qwenaudio tui
162
171
  qwenaudio webui
163
172
  ```
164
173
 
174
+ ### 使用 Hugging Face speech-to-speech 前台
175
+
176
+ qwen-audio-agent 也可以连接用户自行运行的
177
+ [Hugging Face speech-to-speech](https://github.com/huggingface/speech-to-speech)。
178
+ 它将 VAD、STT、LLM 和 TTS 组合成 OpenAI Realtime 兼容服务,整条语音链路既可以
179
+ 完全运行在本地,也可以按需替换其中的模型或服务。
180
+
181
+ 1. 安装 speech-to-speech:
182
+
183
+ ```bash
184
+ pip install "speech-to-speech[paraformer]"
185
+ ```
186
+
187
+ 2. 启动全本地服务:
188
+
189
+ Linux / Windows(NVIDIA GPU):
190
+
191
+ ```bash
192
+ speech-to-speech \
193
+ --stt paraformer \
194
+ --llm_backend transformers \
195
+ --device cuda
196
+ ```
197
+
198
+ Apple Silicon:
199
+
200
+ ```bash
201
+ speech-to-speech \
202
+ --stt paraformer \
203
+ --llm_backend mlx-lm \
204
+ --device mps
205
+ ```
206
+
207
+ 没有 NVIDIA GPU 时,也可以选择适合 CPU 的更小本地模型;还可以
208
+ 将 LLM 指向本机运行的 vLLM / llama.cpp。服务默认运行在
209
+ `ws://127.0.0.1:8765/v1/realtime`。
210
+
211
+ 3. 在 qwen-audio-agent 的 `config.env` 中设置:
212
+
213
+ ```dotenv
214
+ QWEN_AUDIO_REALTIME_PROVIDER=speech-to-speech
215
+ SPEECH_TO_SPEECH_REALTIME_URL=ws://127.0.0.1:8765/v1/realtime
216
+ ```
217
+
218
+ 然后正常启动 `qwenaudio`。在全本地模式下无需云端 API Key。Gateway 只连接 Realtime
219
+ 接口,不会修改 speech-to-speech 的 STT、LLM、TTS 或音色配置。
220
+ 如果 Realtime 接口位于需要 Bearer 认证的代理后方,可设置
221
+ `SPEECH_TO_SPEECH_AUTH_TOKEN`。
222
+
165
223
  ### TUI 使用注意
166
224
 
167
225
  | 平台 | 默认模式 | 打断方式 |
@@ -178,9 +236,10 @@ qwenaudio tui --audio-mode full
178
236
 
179
237
  ## macOS 桌面版
180
238
 
181
- 桌面版提供常驻桌面的语音悬浮球,并内置和自动管理 Gateway,无需事先启动服务。
182
- 首次运行时,应用会创建配置文件,并引导你在设置页填写 DashScope API Key、选择
183
- 后台 Agent(也可以使用仅前台模式)。
239
+ 桌面版提供常驻桌面的语音悬浮球,并内置 Gateway,无需事先启动服务。同一用户配置
240
+ 目录已有兼容的本地 Gateway 时会直接复用,否则由桌面版自动启动和管理。首次运行时,
241
+ 应用会创建配置文件,并引导你在设置页填写 DashScope API Key、选择后台 Agent
242
+ (也可以使用仅前台模式)。
184
243
 
185
244
  桌面版支持流光声波球和液态渐变球两种外观。下面分别展示它们在思考 / 呼吸状态
186
245
  下的原始动态效果:
@@ -250,15 +309,18 @@ AGENT_PROTOCOL=opencode
250
309
  AGENT_PROTOCOL=qoder
251
310
  ```
252
311
 
253
- Kimi Code、Hermes、CodeBuddy、Codex 和 Claude Code 也可直接选择:
312
+ 后台 Agent 需要用户自行安装并完成原生配置;qwen-audio-agent 会复用其
313
+ 用户级模型、工具、MCP、Skill 和认证。
254
314
 
255
- ```dotenv
256
- AGENT_PROTOCOL=kimi
257
- # 或 hermes、codebuddy、codex、claude
315
+ 其中部分 Agent 通过外部 ACP 适配器接入,除本体外,还需要全局安装对应的适配器。
316
+ 以 Codex 为例:
317
+
318
+ ```bash
319
+ npm install -g @agentclientprotocol/codex-acp
258
320
  ```
259
321
 
260
- 以上其他后台暂时需要用户自行安装并完成原生配置;qwen-audio-agent 会复用其
261
- 用户级模型、工具、MCP、Skill 和认证。
322
+ CLI 模式缺少适配器时会尝试通过 npx 按需启动;桌面版为保证启动可靠,仅使用已安装的
323
+ 组件,请提前安装。
262
324
 
263
325
  使用其他支持 ACP stdio 的 Agent:
264
326
 
@@ -286,6 +348,7 @@ QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE=full
286
348
  - `USER.md`:称呼、所在地、偏好和常用项目
287
349
  - `frontend-memory.json`:用户明确要求长期记住的信息
288
350
  - `tasks.json`:任务结果和待通知状态
351
+ - `logs/`:经过凭据脱敏并自动轮转的本地运行日志
289
352
 
290
353
  这些文件只保存在本机,不会写入源码仓库。可以直接编辑 `USER.md`,也可以在对话中
291
354
  要求助理记住或忘记信息。
@@ -293,7 +356,8 @@ QWEN_AUDIO_AGENT_BACKEND_PERMISSION_MODE=full
293
356
  ## 使用注意事项
294
357
 
295
358
  - 不要在用户档案或对话中保存密码、API Key、验证码和访问令牌。
296
- - 麦克风音频与实时对话会发送到配置的 Qwen Audio Realtime 服务。
359
+ - 麦克风音频与实时对话会发送到配置的 Realtime 前台服务(DashScope 或
360
+ speech-to-speech)。
297
361
  - 后台任务可能调用所选 Agent 的模型、工具、MCP 和外部服务。
298
362
  - `full` 权限允许后台执行命令和修改文件,只应在可信项目中使用。
299
363
  - Gateway 默认仅供本机访问;不要直接暴露到局域网或公网。
@@ -317,6 +381,17 @@ npm run desktop # macOS 桌面悬浮球
317
381
 
318
382
  更多构建、测试和发布说明见 [CONTRIBUTING.md](CONTRIBUTING.md)。
319
383
 
384
+ ## 交流与分享
385
+
386
+ 你可以直接在 [GitHub Issues](https://github.com/QwenAudio/qwen-audio-agent/issues) 发起讨论。
387
+
388
+ 对中国用户,也可以扫描左侧二维码加入微信交流群;如果群二维码已满或过期,
389
+ 扫描右侧任一维护者的个人二维码,维护者会邀请你进群。
390
+
391
+ | 微信交流群 | 个人微信 | 个人微信 |
392
+ | :---: | :---: | :---: |
393
+ | <img src="docs/wechat-group-qr.png" width="240" alt="微信交流群二维码"> | <img src="docs/wechat-contact-qr.png" width="240" alt="李旭个人微信二维码"> | <img src="docs/wechat-pigeon-dan-qr.png" width="240" alt="Pigeon.Dan 个人微信二维码"> |
394
+
320
395
  ## 参与贡献与安全
321
396
 
322
397
  - 开发与提交说明:[CONTRIBUTING.md](CONTRIBUTING.md)
package/README_EN.md CHANGED
@@ -25,6 +25,12 @@ tells you:
25
25
 
26
26
  ## News
27
27
 
28
+ - **2026-08-03 · [v1.3.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.3.0)**
29
+ 🎙️ Adds a [🤗 speech-to-speech](https://github.com/huggingface/speech-to-speech) frontend for a locally deployed VAD–STT–LLM–TTS pipeline.
30
+ - **2026-08-01 · [v1.2.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.2.0)**
31
+ ⚡ Desktop auto-update, faster startup, and smarter backend Agent detection.
32
+ - **2026-07-31 · [v1.1.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.1.0)**
33
+ 🤝 Adds Kimi Code CLI backend with native ACP support.
28
34
  - **2026-07-30 · [v1.0.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.0.0)**
29
35
  🚀 First stable release with a macOS desktop app and integrated Gateway.
30
36
  - **2026-07-28 · [v0.9.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v0.9.0)**
@@ -41,12 +47,14 @@ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
41
47
 
42
48
  - Full-duplex realtime voice interaction, natural interruption, and continuous
43
49
  multi-turn conversation
44
- - One-click connection to the Agents you prefer, reusing their existing
45
- models, tools, MCP servers, and Skills
46
- - Voice conversation and backend tasks run in parallel, with progress queries
47
- and cancellation available at any time
48
- - Task results return automatically to the current context for follow-up and
49
- revision
50
+ - Choose your preferred Agent with one click, reusing its existing tools, MCP
51
+ servers, and Skills
52
+ - Foreground conversation and background tasks move forward in parallel, with
53
+ progress checks and cancellation available at any time
54
+ - Create multiple independent tasks for asynchronous execution by backend
55
+ Agents, with continuous status tracking
56
+ - Task results return automatically to the current conversation for follow-up
57
+ and revision
50
58
  - WebUI, terminal TUI, and a macOS desktop orb
51
59
  - Local user profile and personal memory across sessions
52
60
 
@@ -93,7 +101,8 @@ boundaries.
93
101
  ## Installation
94
102
 
95
103
  You need Node.js 22.22.2+ or 24.15.0+, npm 10+, and a
96
- DashScope API Key. The repository includes `.nvmrc` and `.node-version`; if you
104
+ DashScope API Key when using the default DashScope realtime frontend. The
105
+ repository includes `.nvmrc` and `.node-version`; if you
97
106
  use nvm, run `nvm use`.
98
107
 
99
108
  One-line install (recommended, from npm):
@@ -183,6 +192,57 @@ You can use the browser interface instead:
183
192
  qwenaudio webui
184
193
  ```
185
194
 
195
+ ### Use a Hugging Face speech-to-speech frontend
196
+
197
+ qwen-audio-agent can also connect to a user-managed
198
+ [Hugging Face speech-to-speech](https://github.com/huggingface/speech-to-speech)
199
+ server. It combines VAD, STT, LLM, and TTS behind an OpenAI Realtime-compatible
200
+ API. The entire voice pipeline can run locally, or you can replace individual
201
+ models and services as needed.
202
+
203
+ 1. Install speech-to-speech:
204
+
205
+ ```bash
206
+ pip install "speech-to-speech[paraformer]"
207
+ ```
208
+
209
+ 2. Start a fully local service:
210
+
211
+ Linux / Windows with an NVIDIA GPU:
212
+
213
+ ```bash
214
+ speech-to-speech \
215
+ --stt paraformer \
216
+ --llm_backend transformers \
217
+ --device cuda
218
+ ```
219
+
220
+ Apple Silicon:
221
+
222
+ ```bash
223
+ speech-to-speech \
224
+ --stt paraformer \
225
+ --llm_backend mlx-lm \
226
+ --device mps
227
+ ```
228
+
229
+ Without an NVIDIA GPU, you can choose a smaller local model suitable for CPU
230
+ inference, or point the LLM backend at a local vLLM / llama.cpp server. The service listens on
231
+ `ws://127.0.0.1:8765/v1/realtime` by default.
232
+
233
+ 3. Add the following to the qwen-audio-agent `config.env` file:
234
+
235
+ ```dotenv
236
+ QWEN_AUDIO_REALTIME_PROVIDER=speech-to-speech
237
+ SPEECH_TO_SPEECH_REALTIME_URL=ws://127.0.0.1:8765/v1/realtime
238
+ ```
239
+
240
+ Then start `qwenaudio` as usual. Fully local mode requires no cloud API Key. The
241
+ Gateway only connects to the Realtime endpoint and does not alter the STT, LLM,
242
+ TTS, or voice configured in speech-to-speech. Set
243
+ `SPEECH_TO_SPEECH_AUTH_TOKEN` only when the Realtime endpoint is behind a proxy
244
+ that requires Bearer authentication.
245
+
186
246
  ### TUI Notes
187
247
 
188
248
  | Platform | Default mode | How to interrupt |
@@ -201,10 +261,12 @@ qwenaudio tui --audio-mode full
201
261
 
202
262
  ## macOS Desktop App
203
263
 
204
- The desktop app provides a persistent voice orb and embeds and manages its own
205
- Gateway, so no service needs to be started in advance. On first launch, the app
206
- creates its configuration file and guides you to enter a DashScope API Key and
207
- choose a backend Agent (or frontend-only mode) in Settings.
264
+ The desktop app provides a persistent voice orb and includes the Gateway, so no
265
+ service needs to be started in advance. It reuses a compatible local Gateway
266
+ already running for the same user configuration directory; otherwise, it
267
+ starts and manages one automatically. On first launch, the app creates its
268
+ configuration file and guides you to enter a DashScope API Key and choose a
269
+ backend Agent (or frontend-only mode) in Settings.
208
270
 
209
271
  The desktop app includes a streaming wave orb and a liquid gradient orb. Their
210
272
  original animated thinking / breathing states are shown below:
@@ -281,17 +343,20 @@ Use Qoder:
281
343
  AGENT_PROTOCOL=qoder
282
344
  ```
283
345
 
284
- Kimi Code, Hermes, CodeBuddy, Codex, and Claude Code can also be selected
285
- directly:
346
+ Backend Agents require the user to install and configure the native Agent
347
+ first. qwen-audio-agent reuses its user-level model, tools, MCP servers,
348
+ Skills, and authentication.
286
349
 
287
- ```dotenv
288
- AGENT_PROTOCOL=kimi
289
- # Or hermes, codebuddy, codex, or claude
350
+ Some Agents connect through external ACP adapters. Besides the Agent itself,
351
+ install the matching adapter globally. For example, for Codex:
352
+
353
+ ```bash
354
+ npm install -g @agentclientprotocol/codex-acp
290
355
  ```
291
356
 
292
- These other backends currently require the user to install and configure the
293
- native Agent first. qwen-audio-agent reuses its user-level model, tools, MCP
294
- servers, Skills, and authentication.
357
+ The CLI falls back to starting a missing adapter on demand with npx; the
358
+ desktop app only uses installed components for reliable startup, so install
359
+ the adapter up front.
295
360
 
296
361
  Use another Agent that supports ACP over stdio:
297
362
 
@@ -323,6 +388,7 @@ User data is stored in `~/.config/qwaudio/`:
323
388
  - `frontend-memory.json`: information you explicitly ask the assistant to
324
389
  remember long term
325
390
  - `tasks.json`: task results and pending notification state
391
+ - `logs/`: credential-redacted, automatically rotated local runtime logs
326
392
 
327
393
  These files remain on your computer and are never written to the source
328
394
  repository. You can edit `USER.md` directly or ask the assistant to remember or
@@ -332,8 +398,8 @@ forget information during a conversation.
332
398
 
333
399
  - Do not store passwords, API Keys, verification codes, or access tokens in
334
400
  your user profile or conversations.
335
- - Microphone audio and realtime conversations are sent to the configured Qwen
336
- Audio Realtime service.
401
+ - Microphone audio and realtime conversations are sent to the configured
402
+ Realtime frontend (DashScope or speech-to-speech).
337
403
  - Backend tasks may call models, tools, MCP servers, and external services
338
404
  configured for the selected Agent.
339
405
  - `full` permission allows command execution and file changes. Use it only in
@@ -363,6 +429,19 @@ npm run desktop # macOS desktop orb
363
429
  See [CONTRIBUTING.md](CONTRIBUTING.md) for more about building, testing, and
364
430
  releasing.
365
431
 
432
+ ## Discussion & Sharing
433
+
434
+ You can start a discussion directly in
435
+ [GitHub Issues](https://github.com/QwenAudio/qwen-audio-agent/issues).
436
+
437
+ For users in China, you can also scan the QR code on the left to join our
438
+ WeChat group. If the group code is full or expired, scan either maintainer's
439
+ personal QR code on the right and they will invite you to the group.
440
+
441
+ | WeChat Group | Personal WeChat | Personal WeChat |
442
+ | :---: | :---: | :---: |
443
+ | <img src="docs/wechat-group-qr.png" width="240" alt="WeChat group QR code"> | <img src="docs/wechat-contact-qr.png" width="240" alt="Li Xu's personal WeChat QR code"> | <img src="docs/wechat-pigeon-dan-qr.png" width="240" alt="Pigeon.Dan's personal WeChat QR code"> |
444
+
366
445
  ## Contributing and Security
367
446
 
368
447
  - Development and contribution guide: [CONTRIBUTING.md](CONTRIBUTING.md)
@@ -1,10 +1,31 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { main } from '../src/launcher.mjs'
4
+ import { createLogger } from '../../shared/logger.mjs'
5
+
6
+ const logger = createLogger({
7
+ component: 'cli',
8
+ fileName: 'cli.log',
9
+ consoleEnabled: false,
10
+ })
11
+ const startedAt = Date.now()
12
+ logger.info('cli.started', {
13
+ command: process.argv[2] || 'gateway',
14
+ })
4
15
 
5
16
  main(process.argv.slice(2)).then(code => {
6
17
  if (Number.isInteger(code)) process.exitCode = code
18
+ logger.info('cli.completed', {
19
+ command: process.argv[2] || 'gateway',
20
+ exitCode: Number.isInteger(code) ? code : 0,
21
+ durationMs: Date.now() - startedAt,
22
+ })
7
23
  }).catch(error => {
24
+ logger.error('cli.failed', {
25
+ command: process.argv[2] || 'gateway',
26
+ durationMs: Date.now() - startedAt,
27
+ error,
28
+ })
8
29
  process.stderr.write(`qwenaudio: ${error.message}\n`)
9
30
  process.exitCode = 1
10
31
  })
package/cli/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/cli",
3
3
  "private": true,
4
- "version": "1.1.1",
4
+ "version": "1.3.0",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "qwenaudio": "./bin/qwenaudio.mjs"
@@ -61,6 +61,8 @@ export function gatewayServiceDefinition({
61
61
  const workingDirectory = dirname(gatewayPath)
62
62
  const environment = {
63
63
  QWAUDIO_CONFIG_DIR: configDirectory,
64
+ QWEN_AUDIO_GATEWAY_OWNER: 'service',
65
+ QWEN_AUDIO_LOG_CONSOLE: '0',
64
66
  PATH: pathEnvironment,
65
67
  ...serviceEnvironment,
66
68
  }
@@ -98,9 +100,9 @@ ${Object.entries(environment).map(([key, value]) => (
98
100
  <key>ProcessType</key>
99
101
  <string>Background</string>
100
102
  <key>StandardOutPath</key>
101
- <string>${xml(resolve(logsDirectory, 'gateway.log'))}</string>
103
+ <string>${xml(resolve(logsDirectory, 'gateway-console.log'))}</string>
102
104
  <key>StandardErrorPath</key>
103
- <string>${xml(resolve(logsDirectory, 'gateway.log'))}</string>
105
+ <string>${xml(resolve(logsDirectory, 'gateway-console.log'))}</string>
104
106
  </dict>
105
107
  </plist>
106
108
  `
@@ -9,6 +9,7 @@ import {
9
9
  import { helpText, parseArguments } from './arguments.mjs'
10
10
  import {
11
11
  ensureRuntime,
12
+ isLocalGateway,
12
13
  readGatewayHealth,
13
14
  waitForGateway,
14
15
  } from './runtime.mjs'
@@ -62,6 +63,17 @@ function gatewaySummary(health) {
62
63
  return `${label} ${state}`
63
64
  }
64
65
 
66
+ function gatewayServiceEnvironment(url) {
67
+ const target = new URL(url)
68
+ if (target.protocol !== 'http:' || !isLocalGateway(url)) {
69
+ throw new Error('Gateway 后台服务只支持本机 HTTP 地址')
70
+ }
71
+ return {
72
+ HOST: target.hostname.replace(/^\[(.*)\]$/, '$1'),
73
+ PORT: target.port || '80',
74
+ }
75
+ }
76
+
65
77
  async function waitForGatewayStop(url, {
66
78
  inspectGateway = readGatewayHealth,
67
79
  timeoutMs = 15_000,
@@ -124,9 +136,17 @@ export async function main(argv, {
124
136
  (options.command === 'gateway' && options.gatewayAction !== 'run')
125
137
  || options.command === 'status'
126
138
  ) {
139
+ const serviceEnvironment = [
140
+ 'install',
141
+ 'start',
142
+ 'restart',
143
+ ].includes(options.gatewayAction)
144
+ ? gatewayServiceEnvironment(options.url)
145
+ : {}
127
146
  const serviceOptions = {
128
147
  configDirectory: environment.configDirectory,
129
148
  gatewayPath,
149
+ serviceEnvironment,
130
150
  serviceMetadata: {
131
151
  url: options.url,
132
152
  },
@@ -7,11 +7,18 @@ import {
7
7
  } from '../../shared/backend-catalog.mjs'
8
8
  import {
9
9
  loadRuntimeEnvironment,
10
- requireDashScopeCredential,
10
+ requireRealtimeFrontendConfiguration,
11
11
  } from '../../shared/runtime-environment.mjs'
12
+ import {
13
+ normalizeRealtimeProvider,
14
+ resolveRealtimeFrontendConfiguration,
15
+ } from '../../shared/realtime-provider-catalog.mjs'
12
16
  import {
13
17
  readGatewayHealth,
14
18
  } from '../../shared/gateway-client.mjs'
19
+ import {
20
+ findRunningGateway,
21
+ } from '../../shared/gateway-instance-lock.mjs'
15
22
 
16
23
  export {
17
24
  readGatewayHealth,
@@ -132,6 +139,41 @@ export function assertGatewayCompatibility(health, backend) {
132
139
  }
133
140
  }
134
141
 
142
+ export function assertRealtimeGatewayCompatibility(health, env = process.env) {
143
+ const expected = resolveRealtimeFrontendConfiguration(env)
144
+ if (!String(health?.realtimeProvider || '').trim()) {
145
+ throw new Error(
146
+ '现有 Gateway 未报告完整的 Realtime 前台配置,无法安全复用',
147
+ )
148
+ }
149
+ let actualProvider
150
+ try {
151
+ actualProvider = normalizeRealtimeProvider(health?.realtimeProvider)
152
+ } catch {
153
+ throw new Error(
154
+ '现有 Gateway 未报告完整的 Realtime 前台配置,无法安全复用',
155
+ )
156
+ }
157
+ const actualSignature = String(
158
+ health?.realtimeConfigurationSignature || '',
159
+ ).trim()
160
+ if (!actualSignature) {
161
+ throw new Error(
162
+ '现有 Gateway 未报告完整的 Realtime 前台配置,无法安全复用',
163
+ )
164
+ }
165
+ if (
166
+ actualProvider !== expected.provider
167
+ || actualSignature !== expected.signature
168
+ ) {
169
+ const mismatch = actualProvider !== expected.provider
170
+ ? `现有 Gateway 使用 ${actualProvider} Realtime 前台,与当前配置 ${expected.provider} 不一致`
171
+ : `现有 Gateway 的 ${expected.provider} Realtime 前台参数与当前配置不一致`
172
+ throw new Error(`${mismatch};请关闭旧 Gateway 后重试`)
173
+ }
174
+ return expected
175
+ }
176
+
135
177
  export async function waitForGateway(baseUrl, {
136
178
  fetchImpl = fetch,
137
179
  requireBackend = false,
@@ -306,9 +348,9 @@ export async function ensureRuntime(options, {
306
348
  spawnImpl = spawn,
307
349
  platform = process.platform,
308
350
  loadEnvironment = () => loadRuntimeEnvironment({ root, env }),
309
- requireCredential = () => requireDashScopeCredential(env),
351
+ requireCredential = () => requireRealtimeFrontendConfiguration(env),
310
352
  } = {}) {
311
- loadEnvironment()
353
+ const runtimeEnvironment = loadEnvironment()
312
354
  const runtime = new ManagedRuntime([], { platform })
313
355
  const local = isLocalGateway(options.url)
314
356
  const backend = resolveBackend(options, env)
@@ -316,7 +358,19 @@ export async function ensureRuntime(options, {
316
358
  ? backendDefinition(backend.protocol)?.label || backend.protocol
317
359
  : '后台 Agent'
318
360
  let health = await readGatewayHealth(options.url, fetchImpl)
319
- const existingGateway = Boolean(health)
361
+ if (!health && local && runtimeEnvironment?.configDirectory) {
362
+ const active = await findRunningGateway(
363
+ runtimeEnvironment.configDirectory,
364
+ {
365
+ readHealth: origin => readGatewayHealth(origin, fetchImpl),
366
+ },
367
+ )
368
+ if (active) {
369
+ options.url = active.origin
370
+ health = active.health
371
+ }
372
+ }
373
+ let existingGateway = Boolean(health)
320
374
 
321
375
  try {
322
376
  if (!health) {
@@ -336,16 +390,30 @@ export async function ensureRuntime(options, {
336
390
  )
337
391
  const gateway = spawnImpl(spec.command, spec.args, spec.options)
338
392
  runtime.children.push(gateway)
339
- health = await waitForReadiness(
340
- gateway,
341
- waitForGateway(options.url, {
342
- fetchImpl,
343
- requireBackend: Boolean(
344
- backend.protocol && options.waitForBackend !== false
345
- ),
346
- }),
347
- 'Gateway',
348
- )
393
+ try {
394
+ health = await waitForReadiness(
395
+ gateway,
396
+ waitForGateway(options.url, {
397
+ fetchImpl,
398
+ requireBackend: Boolean(
399
+ backend.protocol && options.waitForBackend !== false
400
+ ),
401
+ }),
402
+ 'Gateway',
403
+ )
404
+ } catch (startupError) {
405
+ const winner = runtimeEnvironment?.configDirectory
406
+ ? await findRunningGateway(runtimeEnvironment.configDirectory, {
407
+ readHealth: origin => readGatewayHealth(origin, fetchImpl),
408
+ timeoutMs: 3000,
409
+ })
410
+ : null
411
+ if (!winner) throw startupError
412
+ runtime.children = runtime.children.filter(child => child !== gateway)
413
+ options.url = winner.origin
414
+ health = winner.health
415
+ existingGateway = true
416
+ }
349
417
  }
350
418
 
351
419
  // An owned Gateway may move its private backend to a free local port.
@@ -367,12 +435,17 @@ export async function ensureRuntime(options, {
367
435
  )
368
436
  }
369
437
  }
438
+ const realtime = local
439
+ ? assertRealtimeGatewayCompatibility(health, env)
440
+ : null
370
441
  if (
371
442
  health.voiceConfigured === false
372
443
  && options.allowMissingCredential !== true
373
444
  ) {
374
445
  throw new Error(
375
- '现有 Gateway 未配置 DashScope 凭据;请修正配置后重启该 Gateway',
446
+ realtime
447
+ ? `现有 Gateway 的 ${realtime.label} Realtime 前台未配置完整;请修正配置后重启该 Gateway`
448
+ : '远程 Gateway 的 Realtime 前台未配置完整',
376
449
  )
377
450
  }
378
451
 
@@ -150,7 +150,7 @@ Queue position is an internal scheduling detail and does not change the user's
150
150
  duplex conversation.
151
151
 
152
152
  Active Work cannot be safely resumed after a Gateway restart, so
153
- they become failed with an explicit restart reason. Completed results and
153
+ it becomes failed with an explicit restart reason. Completed results and
154
154
  notification delivery state are persisted.
155
155
 
156
156
  ## 6. Progress animation