qwen-audio-agent 2.0.1 → 2.1.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 (168) hide show
  1. package/README.md +15 -7
  2. package/README_ZH.md +13 -7
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/cli/package.json +1 -1
  5. package/cli/src/arguments.mjs +4 -1
  6. package/cli/src/config-command.mjs +5 -6
  7. package/cli/src/launcher.mjs +13 -0
  8. package/config/frontend-agent/PROMPT.md +29 -26
  9. package/desktop/src/i18n.mjs +5 -0
  10. package/desktop/src/settings-config.mjs +34 -28
  11. package/desktop/src/settings-store.mjs +19 -28
  12. package/docs/architecture/deep-dive.md +103 -66
  13. package/docs/architecture/deep-dive.zh.md +73 -50
  14. package/docs/backends/configuration.md +4 -4
  15. package/docs/backends/configuration.zh.md +4 -4
  16. package/docs/backends/overview.md +3 -0
  17. package/docs/backends/overview.zh.md +3 -0
  18. package/docs/configuration/backend.md +15 -1
  19. package/docs/configuration/backend.zh.md +15 -1
  20. package/docs/configuration/frontend.md +59 -26
  21. package/docs/configuration/frontend.zh.md +58 -26
  22. package/docs/configuration.md +1 -1
  23. package/docs/configuration.zh.md +1 -1
  24. package/docs/contract.md +22 -2
  25. package/docs/contract.zh.md +18 -2
  26. package/docs/gateway-protocol.md +26 -0
  27. package/docs/gateway-protocol.zh.md +22 -0
  28. package/docs/gateway-webrtc-client.md +3 -3
  29. package/docs/gateway-webrtc-client.zh.md +3 -3
  30. package/docs/getting-started/install.md +1 -1
  31. package/docs/getting-started/install.zh.md +1 -1
  32. package/docs/getting-started/quickstart.md +2 -2
  33. package/docs/getting-started/quickstart.zh.md +2 -2
  34. package/docs/getting-started/webui.md +2 -0
  35. package/docs/getting-started/webui.zh.md +2 -0
  36. package/docs/guides/knowledge.md +8 -5
  37. package/docs/guides/knowledge.zh.md +4 -3
  38. package/docs/guides/tasks.md +63 -2
  39. package/docs/guides/tasks.zh.md +45 -1
  40. package/docs/guides/web-search.md +16 -1
  41. package/docs/guides/web-search.zh.md +14 -1
  42. package/docs/reference/backend-adapter-sdk.md +33 -2
  43. package/docs/reference/backend-adapter-sdk.zh.md +29 -2
  44. package/docs/reference/cli.md +3 -3
  45. package/docs/reference/cli.zh.md +3 -3
  46. package/docs/scenarios/lightrag.md +2 -2
  47. package/docs/scenarios/lightrag.zh.md +2 -2
  48. package/docs/scenarios/x-omni.md +5 -2
  49. package/docs/scenarios/x-omni.zh.md +5 -2
  50. package/docs/voice-agent-architecture-presentation.zh.md +34 -37
  51. package/docs/voice-frontends/custom-provider.md +6 -3
  52. package/docs/voice-frontends/custom-provider.zh.md +6 -3
  53. package/docs/voice-frontends/google-live.md +7 -5
  54. package/docs/voice-frontends/google-live.zh.md +7 -5
  55. package/docs/voice-frontends/gpt-live.md +7 -5
  56. package/docs/voice-frontends/gpt-live.zh.md +7 -5
  57. package/docs/voice-frontends/minicpm-o.md +8 -4
  58. package/docs/voice-frontends/minicpm-o.zh.md +7 -4
  59. package/docs/voice-frontends/qwen-audio-realtime.md +39 -14
  60. package/docs/voice-frontends/qwen-audio-realtime.zh.md +32 -11
  61. package/docs/voice-frontends/qwen-omni-realtime.md +11 -8
  62. package/docs/voice-frontends/qwen-omni-realtime.zh.md +11 -8
  63. package/docs/voice-frontends/speech-to-speech.md +8 -4
  64. package/docs/voice-frontends/speech-to-speech.zh.md +7 -3
  65. package/docs/voice-frontends/stepfun.md +7 -4
  66. package/docs/voice-frontends/stepfun.zh.md +7 -4
  67. package/examples/webrtc/start.mjs +2 -1
  68. package/package.json +22 -13
  69. package/scripts/audit-dependencies.mjs +3 -25
  70. package/scripts/electron-smoke.mjs +5 -5
  71. package/scripts/release-check +2 -2
  72. package/scripts/runtime/claude-code-acp.mjs +5 -5
  73. package/server/package.json +4 -4
  74. package/server/src/app/gateway-application.mjs +3 -0
  75. package/server/src/app/gateway-http-routes.mjs +3 -0
  76. package/server/src/app/session-conversation-history.mjs +9 -1
  77. package/server/src/backend/adapters/a2a/backend-adapter.mjs +32 -26
  78. package/server/src/backend/adapters/acp/backend-adapter.mjs +703 -251
  79. package/server/src/backend/adapters/acp/coordinator-contract.mjs +2 -13
  80. package/server/src/backend/adapters/acp/coordinator-instructions.mjs +29 -8
  81. package/server/src/backend/adapters/acp/coordinator-queue.mjs +58 -0
  82. package/server/src/backend/adapters/acp/drivers/codex.mjs +1 -1
  83. package/server/src/backend/adapters/acp/drivers/openclaw.mjs +1 -2
  84. package/server/src/backend/adapters/acp/input-broker.mjs +2 -0
  85. package/server/src/backend/adapters/acp/process-client.mjs +111 -16
  86. package/server/src/backend/adapters/acp/session-configuration.mjs +2 -19
  87. package/server/src/backend/adapters/acp/session-registry.mjs +9 -0
  88. package/server/src/backend/adapters/acp/session-tools.mjs +1 -1
  89. package/server/src/backend/adapters/acp/turn-updates.mjs +188 -0
  90. package/server/src/backend/adapters/acp/work-continuation.mjs +48 -0
  91. package/server/src/backend/adapters/agent-client.mjs +24 -1
  92. package/server/src/backend/adapters/llm/backend-adapter.mjs +393 -0
  93. package/server/src/backend/adapters/muse/backend-adapter.mjs +2 -0
  94. package/server/src/backend/availability.mjs +12 -3
  95. package/server/src/backend/backend-adapter-sdk.mjs +3 -0
  96. package/server/src/backend/backend-port.mjs +13 -0
  97. package/server/src/backend/backend-work-runtime.mjs +23 -0
  98. package/server/src/client/client-command-runtime.mjs +14 -0
  99. package/server/src/conversation/conversation-sync.mjs +26 -2
  100. package/server/src/conversation/frontend-notes.mjs +7 -5
  101. package/server/src/conversation/task-result-projector.mjs +1 -1
  102. package/server/src/core/backend-events.mjs +4 -0
  103. package/server/src/core/config.mjs +30 -49
  104. package/server/src/core/gateway-protocol.mjs +4 -1
  105. package/server/src/core/work-conversation-context.mjs +138 -0
  106. package/server/src/core/work-input-request.mjs +1 -0
  107. package/server/src/frontend/frontend-tools.mjs +6 -6
  108. package/server/src/frontend/retrieval/providers/factory.mjs +10 -1
  109. package/server/src/frontend/retrieval/providers/mcp.mjs +13 -2
  110. package/server/src/frontend/tools/agent-task-runtime.mjs +97 -95
  111. package/server/src/frontend/tools/features/agent-task-tools.mjs +23 -42
  112. package/server/src/frontend/tools/frontend-tool-context.mjs +2 -2
  113. package/server/src/frontend/tools/spawn-thinking-tool.mjs +2 -2
  114. package/server/src/frontend/tools/tool-call-handler.mjs +112 -68
  115. package/server/src/knowledge/providers/local/library.mjs +26 -6
  116. package/server/src/knowledge/providers/local/provider.mjs +25 -6
  117. package/server/src/memory/providers/markdown/context-store.mjs +21 -10
  118. package/server/src/orchestration/session-task-coordinator.mjs +9 -2
  119. package/server/src/orchestration/task-operations.mjs +50 -10
  120. package/server/src/orchestration/task-updates.mjs +81 -0
  121. package/server/src/task/reminder-scheduler.mjs +5 -1
  122. package/server/src/task/task-manager.mjs +72 -15
  123. package/server/src/task/task-recovery.mjs +12 -2
  124. package/server/src/task/task-scheduler.mjs +5 -5
  125. package/server/src/task/task-state.mjs +13 -0
  126. package/server/src/transport/gateway-client-transport.mjs +16 -0
  127. package/server/src/voice/announcement/announcement-manager.mjs +3 -0
  128. package/server/src/voice/providers/dashscope.mjs +34 -30
  129. package/server/src/voice/providers/doubao-seeduplex.mjs +13 -9
  130. package/server/src/voice/providers/google-live.mjs +18 -13
  131. package/server/src/voice/providers/gpt-live.mjs +13 -10
  132. package/server/src/voice/providers/minicpm-o.mjs +9 -7
  133. package/server/src/voice/providers/registry.mjs +2 -2
  134. package/server/src/voice/providers/runtime-configuration.mjs +23 -0
  135. package/server/src/voice/providers/s2s.mjs +9 -7
  136. package/server/src/voice/providers/stepfun.mjs +13 -10
  137. package/server/src/voice/realtime-input-runtime.mjs +2 -0
  138. package/server/src/voice/realtime-presentation-runtime.mjs +90 -23
  139. package/server/src/voice/realtime-provider.mjs +26 -9
  140. package/server/src/voice/realtime-session-runtime.mjs +79 -23
  141. package/server/src/voice/realtime-task-presentation.mjs +2 -0
  142. package/shared/backend/catalog.mjs +26 -2
  143. package/shared/backend/install.mjs +3 -1
  144. package/shared/backend/setup.mjs +43 -0
  145. package/shared/gateway/client-sdk.mjs +6 -1
  146. package/shared/gateway/setup.mjs +13 -1
  147. package/shared/protocol/gateway-client-protocol.mjs +14 -0
  148. package/shared/protocol/gateway-events.mjs +8 -1
  149. package/shared/realtime-legacy-environment.mjs +52 -0
  150. package/shared/realtime-model-catalog.mjs +66 -194
  151. package/shared/realtime-models/README.md +25 -0
  152. package/shared/realtime-models/dashscope.mjs +46 -0
  153. package/shared/realtime-models/doubao-seeduplex.mjs +12 -0
  154. package/shared/realtime-models/google-live.mjs +10 -0
  155. package/shared/realtime-models/gpt-live.mjs +10 -0
  156. package/shared/realtime-models/profile.mjs +35 -0
  157. package/shared/realtime-models/stepfun.mjs +10 -0
  158. package/shared/realtime-provider-catalog.mjs +16 -5
  159. package/shared/realtime-provider-definitions.mjs +99 -231
  160. package/shared/runtime-environment.mjs +23 -30
  161. package/shared/skill-library.mjs +49 -13
  162. package/shared/web-search-configuration.mjs +13 -2
  163. package/tui/package.json +1 -1
  164. package/web/dist/assets/index-8erKDCr2.css +1 -0
  165. package/web/dist/assets/index-Cs4hYWbS.js +96 -0
  166. package/web/dist/index.html +2 -2
  167. package/web/dist/assets/index-BRaiI-dW.js +0 -91
  168. package/web/dist/assets/index-D9k8R2JY.css +0 -1
package/README.md CHANGED
@@ -27,8 +27,8 @@ tells you:
27
27
 
28
28
  ## News
29
29
 
30
- - **2026-09-26 · [v2.0.1](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.0.1)**
31
- 🔧 Improved local backend discovery and installation: reuse existing Agents, install only missing components from official latest releases, and support DeepSeek Harness native ACP; fixed continued coordinator Session use.
30
+ - **2026-11-10 · [v2.1.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.1.0)**
31
+ 🎙️ Adds Qwen Audio 3.1 Realtime and unified frontend configuration; 🧩 supports updating running tasks and continuing completed work; 🎭 adds a runnable [dual-connection digital-human example](https://github.com/QwenAudio/qwen-audio-agent/tree/main/examples/digital-human) with replaceable rendering services; 📷 adds photo capture to WebUI.
32
32
  - **2026-09-23 · [v2.0.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.0.0)**
33
33
  🏗️ Rebuilt the orchestration runtime with a unified client protocol and ACP / A2A backend integration; 🎙️ expanded [voice and video model support](#voice-frontends); 🧠 enhanced frontend tools, memory, and knowledge libraries; 💬 added a desktop conversation panel and remote mobile access; 🧩 added [customer service, smart cockpit, digital human, and other examples](#examples-and-scenario-expansion); 📄 published the [technical report](https://arxiv.org/pdf/2609.25195).
34
34
  - **2026-08-20 · [v1.11.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.11.0)**
@@ -105,7 +105,7 @@ tasks. They integrate independently and can be combined as needed.
105
105
 
106
106
  | Voice frontend | Deployment | Setup | Features |
107
107
  | --- | --- | --- | --- |
108
- | [Qwen Audio 3.0 Realtime](docs/voice-frontends/qwen-audio-realtime.md) | Cloud | Bailian API Key | Duplex voice, tool calling |
108
+ | [Qwen Audio 3.0/3.1 Realtime](docs/voice-frontends/qwen-audio-realtime.md) | Cloud | Bailian API Key | Duplex voice, tool calling |
109
109
  | [GPT-Live / OpenAI Realtime](docs/voice-frontends/gpt-live.md) | Cloud | OpenAI API Key | — |
110
110
  | [Google Gemini Live](docs/voice-frontends/google-live.md) | Cloud | Google API Key | Live video input |
111
111
  | [Qwen3.5-Omni Realtime](docs/voice-frontends/qwen-omni-realtime.md) | Cloud | Bailian API Key | Live video input |
@@ -115,6 +115,10 @@ tasks. They integrate independently and can be combined as needed.
115
115
  | [Hugging Face Speech-to-Speech](docs/voice-frontends/speech-to-speech.md) | Local | Start the service and set its URL | Configurable STT / LLM / TTS |
116
116
  | [MiniCPM-o 4.5](docs/voice-frontends/minicpm-o.md) | Local or cloud | Compatible service URL | Live video input, no tool calling |
117
117
 
118
+ Frontend connections share the same provider, model, API Key, service URL, and
119
+ voice settings. Supported models and protocol parameters are maintained by the
120
+ framework; see [frontend configuration](docs/configuration/frontend.md).
121
+
118
122
  To connect another voice service, implement the
119
123
  [Realtime Provider interface](docs/voice-frontends/custom-provider.md) without
120
124
  changing the Gateway's core voice-session or backend-task logic.
@@ -124,6 +128,7 @@ changing the Gateway's core voice-session or backend-task logic.
124
128
  | Backend Agent | Integration | Setup | Rating |
125
129
  | --- | --- | --- | --- |
126
130
  | None | N/A | Frontend-only mode, no backend config needed | ★★★★★ |
131
+ | Bare LLM | Built-in Chat Completions | OpenAI-compatible API key, URL, and model | Experimental |
127
132
  | Qwen Code | Native ACP | One-click install, user config required | ★★★★★ |
128
133
  | OpenCode | Native ACP | One-click install + Bailian config | ★★★★★ |
129
134
  | OpenClaw | Built-in ACP bridge | One-click install + Bailian config | ★★★★★ |
@@ -165,9 +170,9 @@ qwenaudio config
165
170
  ```
166
171
 
167
172
  ```dotenv
168
- DASHSCOPE_API_KEY=your-key
169
- # Voice frontend model: optional, defaults to Qwen Audio 3.0 Realtime Plus
170
- QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
173
+ QWEN_AUDIO_REALTIME_API_KEY=your-key
174
+ # Voice frontend model: optional, defaults to Qwen Audio 3.1 Realtime Plus
175
+ QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.1-realtime-plus
171
176
  # Backend Agent: optional, leave empty or set to none for frontend-only mode
172
177
  AGENT_PROTOCOL=openclaw
173
178
  # Backend model: optional; explicit values use standard ACP, empty reuses Agent config
@@ -182,6 +187,9 @@ Quota and billing rules are subject to the current official Bailian documentatio
182
187
  > The example above uses the default DashScope voice frontend. See
183
188
  > [Voice Frontends](#voice-frontends) for other cloud and self-hosted options.
184
189
 
190
+ Backend credentials remain in the Agent's own configuration. For managed Bailian setup,
191
+ see [backend configuration](docs/configuration/backend.md).
192
+
185
193
  With a visual-capable Realtime frontend, WebUI can explicitly stream bounded
186
194
  camera frames alongside live audio. See [Realtime frontend configuration](docs/configuration/frontend.md).
187
195
 
@@ -247,7 +255,7 @@ to be invited.
247
255
 
248
256
  | WeChat Group | Personal | Personal |
249
257
  | :---: | :---: | :---: |
250
- | <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 personal WeChat QR code"> | <img src="docs/wechat-pigeon-dan-qr.png" width="240" alt="Pigeon.Dan personal WeChat QR code"> |
258
+ | <img src="docs/wechat-group-qr.png" height="345" alt="WeChat group QR code"> | <img src="docs/wechat-contact-qr.png" height="345" alt="Li Xu personal WeChat QR code"> | <img src="docs/wechat-pigeon-dan-qr.png" height="345" alt="Pigeon.Dan personal WeChat QR code"> |
251
259
 
252
260
  ## Contributing and Security
253
261
 
package/README_ZH.md CHANGED
@@ -21,8 +21,8 @@
21
21
 
22
22
  ## News
23
23
 
24
- - **2026-09-26 · [v2.0.1](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.0.1)**
25
- 🔧 优化本机后台发现与安装:优先复用已有 Agent,仅补装缺失组件的官方最新版,接入 DeepSeek Harness 原生 ACP;修复协调会话连续调用。
24
+ - **2026-11-10 · [v2.1.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.1.0)**
25
+ 🎙️ 接入 Qwen Audio 3.1 Realtime,统一前台配置;🧩 支持执行中调整任务、完成后继续加工;🎭 新增可运行的[双连接数字人示例](https://github.com/QwenAudio/qwen-audio-agent/blob/main/examples/digital-human/README_ZH.md),支持替换渲染服务;📷 WebUI 新增拍照输入。
26
26
  - **2026-09-23 · [v2.0.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v2.0.0)**
27
27
  🏗️ 重构编排运行时,统一客户端协议与 ACP / A2A 后台接入;🎙️ 扩展[语音与视频模型](#语音前台);🧠 完善前台工具、记忆与资料库;💬 新增桌面对话面板与手机远程连接;🧩 新增[客服、座舱、数字人等示例](#示例与场景扩展);📄 发布[技术报告](https://arxiv.org/pdf/2609.25195)。
28
28
  - **2026-08-20 · [v1.11.0](https://github.com/QwenAudio/qwen-audio-agent/releases/tag/v1.11.0)**
@@ -97,7 +97,7 @@
97
97
 
98
98
  | 语音前台 | 部署方式 | 接入准备 | 特点 |
99
99
  | --- | --- | --- | --- |
100
- | [Qwen Audio 3.0 Realtime](docs/voice-frontends/qwen-audio-realtime.zh.md) | 云端 | 百炼 API Key | 双工语音、工具调用 |
100
+ | [Qwen Audio 3.0/3.1 Realtime](docs/voice-frontends/qwen-audio-realtime.zh.md) | 云端 | 百炼 API Key | 双工语音、工具调用 |
101
101
  | [GPT-Live / OpenAI Realtime](docs/voice-frontends/gpt-live.zh.md) | 云端 | OpenAI API Key | — |
102
102
  | [Google Gemini Live](docs/voice-frontends/google-live.zh.md) | 云端 | Google API Key | 实时视频输入 |
103
103
  | [Qwen3.5-Omni Realtime](docs/voice-frontends/qwen-omni-realtime.zh.md) | 云端 | 百炼 API Key | 实时视频输入 |
@@ -107,6 +107,9 @@
107
107
  | [Hugging Face Speech-to-Speech](docs/voice-frontends/speech-to-speech.zh.md) | 本地 | 启动服务并填写地址 | 可配置 STT / LLM / TTS |
108
108
  | [MiniCPM-o 4.5](docs/voice-frontends/minicpm-o.zh.md) | 本地或云端 | 提供兼容服务地址 | 实时视频输入、不支持工具调用 |
109
109
 
110
+ 前台连接统一使用供应商、模型、API Key、服务地址和音色配置;模型支持列表与协议参数
111
+ 由框架维护。详见[语音前台配置](docs/configuration/frontend.zh.md)。
112
+
110
113
  需要接入其他语音服务时,可实现 [Realtime Provider 接口](docs/voice-frontends/custom-provider.zh.md),
111
114
  无需修改 Gateway 的核心语音会话与后台任务逻辑。
112
115
 
@@ -115,6 +118,7 @@
115
118
  | 后台 Agent | 接入方式 | 接入准备 | 推荐指数 |
116
119
  | --- | --- | --- | --- |
117
120
  | 无 | N/A | 仅前台模式,无需后台配置 | ★★★★★ |
121
+ | 裸 LLM | 内置 Chat Completions | OpenAI-compatible API Key、URL 与模型 | 实验性 |
118
122
  | Qwen Code | 原生 ACP | 支持一键安装,需用户配置 | ★★★★★ |
119
123
  | OpenCode | 原生 ACP | 支持一键安装和百炼配置 | ★★★★★ |
120
124
  | OpenClaw | 内置 ACP 桥接 | 支持一键安装和百炼配置 | ★★★★★ |
@@ -154,9 +158,9 @@ qwenaudio config
154
158
  ```
155
159
 
156
160
  ```dotenv
157
- DASHSCOPE_API_KEY=your-key
158
- # 语音前台模型:可选,默认 Qwen Audio 3.0 Realtime Plus
159
- QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.0-realtime-plus
161
+ QWEN_AUDIO_REALTIME_API_KEY=your-key
162
+ # 语音前台模型:可选,默认 Qwen Audio 3.1 Realtime Plus
163
+ QWEN_AUDIO_REALTIME_MODEL=qwen-audio-3.1-realtime-plus
160
164
  # 后台Agent:可选,不设置或设置为 none 时,启动仅前台模式
161
165
  AGENT_PROTOCOL=openclaw
162
166
  # 后台模型:可为空;显式设置通过 ACP 标准覆盖,留空沿用 Agent 配置
@@ -170,6 +174,8 @@ QWEN_AUDIO_AGENT_BACKEND_MODEL=qwen3.7-max
170
174
 
171
175
  > 以上使用默认的 DashScope 语音前台。其他云端或自部署方案见[语音前台](#语音前台)。
172
176
 
177
+ 后台凭据沿用 Agent 自身配置;托管百炼配置见[后台配置](docs/configuration/backend.zh.md)。
178
+
173
179
  使用支持视觉的 Realtime 前台时,WebUI 可由用户显式开启相机,将有界画面帧与实时
174
180
  音频一同发送。详见[语音前台配置](docs/configuration/frontend.zh.md)。
175
181
 
@@ -228,7 +234,7 @@ npm run desktop:build:linux # Linux(AppImage + deb,无需签名)
228
234
 
229
235
  | 微信交流群 | 个人微信 | 个人微信 |
230
236
  | :---: | :---: | :---: |
231
- | <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 个人微信二维码"> |
237
+ | <img src="docs/wechat-group-qr.png" height="345" alt="微信交流群二维码"> | <img src="docs/wechat-contact-qr.png" height="345" alt="李旭个人微信二维码"> | <img src="docs/wechat-pigeon-dan-qr.png" height="345" alt="Pigeon.Dan 个人微信二维码"> |
232
238
 
233
239
  ## 参与贡献与安全
234
240
 
@@ -19,7 +19,7 @@ qwen-audio-agent 使用并分发若干开源组件。项目自身使用 Apache L
19
19
  | Agent2Agent Protocol JavaScript SDK | Apache-2.0 | https://github.com/a2aproject/a2a-js |
20
20
  | Agent Client Protocol TypeScript SDK | Apache-2.0 | https://github.com/agentclientprotocol/typescript-sdk |
21
21
  | Codex ACP adapter | Apache-2.0 | https://github.com/agentclientprotocol/codex-acp |
22
- | Claude Code ACP adapter | Apache-2.0 | https://github.com/zed-industries/claude-code-acp |
22
+ | Claude Agent ACP adapter | Apache-2.0 | https://github.com/agentclientprotocol/claude-agent-acp |
23
23
  | Model Context Protocol TypeScript SDK | MIT | https://github.com/modelcontextprotocol/typescript-sdk |
24
24
  | Zod | MIT | https://github.com/colinhacks/zod |
25
25
  | concurrently | MIT | https://github.com/open-cli-tools/concurrently |
package/cli/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/cli",
3
3
  "private": true,
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "qwenaudio": "./bin/qwenaudio.mjs"
@@ -53,7 +53,9 @@ function cleanOrigin(value, label) {
53
53
  throw new Error(`无效的${label}:${value}`)
54
54
  }
55
55
  if (!['http:', 'https:'].includes(url.protocol)) {
56
- throw new Error(`${label}只支持 http 或 https`)
56
+ // label 允许带前导空格(如 ' Gateway URL')以适配「无效的${label}」的中英
57
+ // 混排间距;以此为开头的消息需先去掉,避免句子以前导空格开头。
58
+ throw new Error(`${label.trim()}只支持 http 或 https`)
57
59
  }
58
60
  return url.origin
59
61
  }
@@ -480,6 +482,7 @@ export function helpText() {
480
482
  ' --audio-mode MODE Linux / Windows 使用 half(默认)或 full',
481
483
  ' --takeover 显式接管同一用户的现有活动客户端(仅 TUI)',
482
484
  ' --no-open WebUI 只打印地址,不打开浏览器',
485
+ ' -v, --version 显示版本',
483
486
  ' -h, --help 显示帮助',
484
487
  '',
485
488
  'TUI 按键:',
@@ -11,6 +11,7 @@ import {
11
11
  realtimeModelCatalog,
12
12
  resolveRealtimeModelProfile,
13
13
  } from '../../shared/realtime-provider-catalog.mjs'
14
+ import { mergeRealtimeEnvironment, realtimeSettingsFromEnvironment } from '../../shared/realtime-provider-definitions.mjs'
14
15
 
15
16
  export const GATEWAY_RESTART_FOLLOW_UP = '配置已更新;请执行 qwenaudio gateway restart 使 Gateway 使用新模型'
16
17
 
@@ -22,15 +23,13 @@ function configText(path) {
22
23
  }
23
24
 
24
25
  export function resolveConfigModel(env = {}, content = '') {
25
- const values = { ...parseEnv(content), ...env }
26
- const catalog = realtimeModelCatalog(normalizeRealtimeProvider(values.QWEN_AUDIO_REALTIME_PROVIDER))
27
- return catalog ? String(values[catalog.environment] || catalog.defaultModel).trim() : ''
26
+ return realtimeSettingsFromEnvironment(mergeRealtimeEnvironment(parseEnv(content), env)).realtimeModel
28
27
  }
29
28
 
30
29
  export function assertKnownRealtimeModel(model, provider = 'dashscope') {
31
30
  const profile = resolveRealtimeModelProfile(model, provider)
32
31
  if (!realtimeModelCatalog(provider)?.profiles.some(item => item.id === model)) {
33
- throw new Error(`不支持的 Realtime 模型:${model}`)
32
+ throw new Error(`不支持的 Realtime 模型:${model};请选择列表中的受支持模型`)
34
33
  }
35
34
  return profile
36
35
  }
@@ -51,7 +50,7 @@ function updateRealtimeModelConfigUnlocked(configPath, model, {
51
50
  env,
52
51
  }) {
53
52
  const existing = configText(configPath)
54
- const values = { ...parseEnv(existing), ...env }
53
+ const values = mergeRealtimeEnvironment(parseEnv(existing), env)
55
54
  const provider = normalizeRealtimeProvider(values.QWEN_AUDIO_REALTIME_PROVIDER)
56
55
  const profile = assertKnownRealtimeModel(model, provider)
57
56
  const environment = realtimeModelCatalog(provider).environment
@@ -104,7 +103,7 @@ function updateRealtimeModelConfigUnlocked(configPath, model, {
104
103
  }
105
104
 
106
105
  export function showConfig({ configPath, env = {}, content = configText(configPath) }) {
107
- const values = { ...parseEnv(content), ...env }
106
+ const values = mergeRealtimeEnvironment(parseEnv(content), env)
108
107
  const provider = normalizeRealtimeProvider(values.QWEN_AUDIO_REALTIME_PROVIDER)
109
108
  const catalog = realtimeModelCatalog(provider)
110
109
  const model = resolveConfigModel(env, content)
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from 'node:fs'
1
2
  import { dirname, resolve } from 'node:path'
2
3
  import { runtimePathEnvironment } from '../../shared/runtime-paths.mjs'
3
4
  import { requireWebRtcDependencies } from '../../shared/gateway/webrtc.mjs'
@@ -64,6 +65,14 @@ import {
64
65
  const root = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
65
66
  const gatewayPath = resolve(root, 'server/src/index.mjs')
66
67
 
68
+ function readCliVersion() {
69
+ return JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8')).version
70
+ }
71
+
72
+ function isVersionRequest(argv) {
73
+ return argv.length === 1 && (argv[0] === '--version' || argv[0] === '-v')
74
+ }
75
+
67
76
  async function runMinimal(options) {
68
77
  const moduleUrl = pathToFileURL(resolve(root, 'tui/src/index.mjs'))
69
78
  const { runTui } = await import(moduleUrl)
@@ -290,6 +299,10 @@ export async function main(argv, {
290
299
  errorCorrectionLevel: 'L',
291
300
  }),
292
301
  } = {}) {
302
+ if (isVersionRequest(argv)) {
303
+ stdout.write(`${readCliVersion()}\n`)
304
+ return 0
305
+ }
293
306
  const processModelOverrides = { ...env }
294
307
  const readOnlyCommand = ['setup', 'install', 'doctor', 'connect', 'disconnect', 'tui', 'webui', 'status'].includes(argv[0])
295
308
  || (argv[0] === 'gateway' && argv[1] === 'status')
@@ -23,27 +23,28 @@
23
23
 
24
24
  # Routing
25
25
 
26
- 选择最直接且足够的处理方式:能够仅凭当前对话完整回答时直接回答;存在与意图直接
27
- 对应的专用工具时调用该工具;需要后台执行且符合 `spawn_thinking` description 声明的
28
- 能力范围时调用 `spawn_thinking`。可组合使用本轮提供的工具完成请求;
29
- 不要仅因需要多次工具调用就转为后台工作。
30
- 需要操作用户环境、持续执行或制作交付物时,按已提供工具的能力选择执行入口。
31
- 如果判断最终需要后台执行,不要先用前台检索工具进行试探性搜索再转交。
32
- 同一轮包含多个明确意图时逐项处理,不要因一次工具调用而忽略其余请求。
26
+ 仅当直接回答就能满足用户请求时,才直接回答。需要实际操作时,优先调用合适的
27
+ 专用工具,可组合调用。其余请求必须调用后台工具尝试,即使不确定后台是否支持。
28
+ 不要未经尝试就声称做不到,也不要用口头承诺、操作教程或替代方案代替执行。
33
29
 
34
- 需要后台执行、属于 `spawn_thinking` 声明能力范围且前台没有更专用工具时,该工具是
35
- 统一的执行入口。必须调用它,不能提前声称“做不到”。
36
- 不要预测、模拟或代替后台提出权限请求;先调用实际执行工具。只有 Gateway 随后提供了
37
- 真实的待确认请求,才进入权限确认流程。
30
+ 仅使用本轮实际提供的工具,并遵守其 description 和 schema。
31
+ 后台拥有独立的工具与执行环境,当前工具列表不代表后台的完整能力。
32
+ 是否能完成请求,以后台实际执行结果为准。
38
33
 
39
- 仅使用本轮实际提供的工具;未提供的能力不要假装可用。
40
- 工具 description 和 schema 是各项能力的调用契约。不要用口头承诺代替工具调用,
41
- 也不要在工具成功前声称操作已经完成。可通过已注册工具完成的事就是你的能力:
42
- 直接调用合适工具,不要先说自己不能做、无法访问或需要转交。只有工具明确返回不可用或
43
- 失败后,才如实说明限制。缺少无法合理推断的核心信息时,只问一个必要问题。
34
+ 新增工作调用 `spawn_thinking`;补充、调整或继续已有工作调用
35
+ `update_agent_task`,工作完成后仍可续接。
36
+ 不要因后台正在执行而把新增工作当作调整。
44
37
 
45
- 用户说“这个、刚才那个、当前页面”等内容时,结合当前对话和运行上下文消解指代;
46
- 无法可靠判断时再询问,不要编造对象。用户说“当前目录”或“这个目录”时,默认指
38
+ 转交工作时,忠实保留用户目标与明确约束,包括否定要求;只消解有依据的指代,
39
+ 不扩写需求或指定实现方案。可由工具查明的信息交给工具获取,未指定的实现细节交由后台判断;
40
+ 缺少必须由用户决定的关键信息时才询问。
41
+
42
+ 同一轮包含多个明确意图时逐项处理,不要因一次工具调用而忽略其余请求。
43
+ 遇到实际限制时如实说明。
44
+
45
+ # Context
46
+
47
+ 用户说“当前目录”或“这个目录”时,默认指
47
48
  `<runtime_context>` 中的 `client_working_directory`;该字段不存在时不要猜测。
48
49
 
49
50
  `<input_parts>` 是图片或文件的可引用元数据,不代表你已经读过其内容。
@@ -54,19 +55,19 @@
54
55
  # Background work
55
56
 
56
57
  不要重复提交已经覆盖的目标。
58
+ 续接时使用系统提供的工作 ID,指代不明确时先查询或确认,不得猜造。
57
59
 
58
60
  当前对话中有 `<backend_input_request>` 时,后台工作仍在等待用户输入,并未完成。
59
- 用户回答后调用 `respond_agent_input`,把回答交回请求中的同一项工作;不要调用
61
+ 用户回答后调用 `update_agent_task`,把回答交回请求中的同一项工作;不要调用
60
62
  `spawn_thinking` 新建工作。该标签及其中的工作 ID 只能来自 Gateway,不得自行生成、
61
63
  复述或猜测。对于不支持结构化输入请求的旧后台,如果最终结果以自然语言提出继续工作
62
- 所需的问题,用户随后回答时才再次调用 `spawn_thinking`,并明确这是既有工作的续办。
64
+ 所需的问题,用户随后回答时调用 `update_agent_task` 继续对应工作。
63
65
 
64
- 调用 `spawn_thinking` 前不要口头回应。工具返回 `accepted` 只表示工作已经受理,
65
- `duplicate` 表示同一目标此前已提交;二者都不代表完成。收到同一响应中的全部这类回执后,
66
- 只作一次自然确认,不再调用任何工具。不要承诺耗时或用话语填补等待,用户应当能够继续交谈。
66
+ 调用 `spawn_thinking` 或 `update_agent_task` 前不要口头回应。
67
+ 根据工具结果如实回应,不把请求受理或执行进展说成已经完成。
67
68
 
68
69
  先前工作的最终结果会通过单独的结果上下文到达。把它作为可信事实材料自然转达:
69
- 说明实际结果、阻塞或必要问题,不暴露内部执行结构,也不要把过程状态说成完成结果。
70
+ 说明实际结果、阻塞或必要问题,不暴露内部执行结构。
70
71
  执行中的阶段性更新可能通过单独的进度上下文到达;只简短转达其中的新进展,
71
72
  不要将其视为最终结果,也不要因此调用工具。
72
73
 
@@ -79,6 +80,8 @@
79
80
 
80
81
  # Permission requests
81
82
 
83
+ 不要预测、模拟或代替后台提出权限请求;先调用实际执行工具。只有 Gateway 随后提供了
84
+ 真实的待确认请求,才进入权限确认流程。
82
85
  当前对话中有 `<permission_request>` 时,优先按 `respond_permission` 的契约处理
83
86
  用户回答,不要把回答提交为新任务。调用前不要口头确认,成功后只需简短说明结果。
84
87
  该标签及其中的 ID 只能来自 Gateway 提供的上下文;不得自行生成、复述或猜测。
@@ -86,8 +89,8 @@
86
89
 
87
90
  # Voice interaction
88
91
 
89
- 输出应适合听觉。避免空泛承接、重复用户要求、感谢等待、承诺持续更新或用话语填补
90
- 安静。没有新信息时不要说话。
92
+ 输出应适合听觉。避免空泛承接、重复用户要求、感谢等待、承诺耗时、承诺持续更新或
93
+ 用话语填补安静。没有新信息时不要说话。
91
94
 
92
95
  不要朗读协议字段、工作 ID、路径、URL、端口、哈希、时间戳或长数字,除非用户明确
93
96
  要求准确内容。
@@ -25,6 +25,11 @@ const ENGLISH = {
25
25
  '获取 API Key': 'Get API Key',
26
26
  '模型名称': 'Model',
27
27
  '模型': 'Model',
28
+ '(不支持)': ' (unsupported)',
29
+ '(目录不可用)': ' (catalog unavailable)',
30
+ '模型目录不可用,请重新打开设置或重启应用': 'Model catalog is unavailable. Reopen Settings or restart the application.',
31
+ '模型不受支持,请选择列表中的模型': 'Model is not supported. Select a listed model.',
32
+ '请选择当前供应商支持的模型': 'Select a model supported by the current provider.',
28
33
  '面壁智能': 'ModelBest',
29
34
  '自定义': 'Custom',
30
35
  '音色': 'Voice',
@@ -14,10 +14,11 @@ import {
14
14
  resolveRealtimeFrontendConfiguration,
15
15
  } from '../../shared/realtime-provider-catalog.mjs'
16
16
  import {
17
- REALTIME_PROVIDERS, REALTIME_SETTING_FIELDS,
18
- migrateRealtimeFileEnvironment, realtimeRuntimeEnvironment, realtimeSettingsValues, realtimeSettingsFromEnvironment, mergeRealtimeEnvironment,
17
+ REALTIME_SETTING_FIELDS,
18
+ realtimeRuntimeEnvironment, realtimeSettingsValues, realtimeSettingsFromEnvironment, mergeRealtimeEnvironment,
19
19
  } from '../../shared/realtime-provider-definitions.mjs'
20
20
  import { normalizeDesktopLanguage } from './i18n.mjs'
21
+ import { BUILTIN_REALTIME_MODEL_CATALOGS } from '../../shared/realtime-model-catalog.mjs'
21
22
 
22
23
  const DEFAULTS = {
23
24
  gatewayUrl: 'http://127.0.0.1:3101',
@@ -162,11 +163,11 @@ function encoded(value) {
162
163
  throw new TypeError('设置值包含无法保存的换行、控制字符或引号组合')
163
164
  }
164
165
 
165
- function parseRealtimeSettings(values, fallback, realtimeProvider, drafts) {
166
+ function parseRealtimeSettings(values, fallback, realtimeProvider) {
166
167
  return realtimeSettingsFromEnvironment({
167
168
  ...mergeRealtimeEnvironment(fallback, values),
168
169
  QWEN_AUDIO_REALTIME_PROVIDER: realtimeProvider,
169
- }, drafts)
170
+ })
170
171
  }
171
172
 
172
173
  export function hasRealtimeSettingsPatch(settings) {
@@ -174,22 +175,24 @@ export function hasRealtimeSettingsPatch(settings) {
174
175
  }
175
176
 
176
177
  function normalizeRealtimeSettings(settings, realtimeProvider) {
177
- const values = realtimeSettingsValues(settings)
178
- for (const provider of REALTIME_PROVIDERS) {
179
- for (const field of provider.settings) {
180
- const active = provider.key === realtimeProvider
181
- const value = values[field.key].trim() || field.default || (active ? field.activeDefault : '') || ''
182
- // Inactive providers retain their drafts but cannot block applying the
183
- // selected provider. The active endpoint is validated at the IPC boundary.
184
- values[field.key] = active && field.type === 'url'
185
- ? cleanRealtimeUrl(value, '') : value
186
- }
178
+ const values = realtimeSettingsValues({ ...settings, realtimeProvider })
179
+ return { ...values, realtimeUrl: cleanRealtimeUrl(values.realtimeUrl, '') }
180
+ }
181
+
182
+ // A connection belongs to one provider. Partial edits preserve its values;
183
+ // changing provider starts from that provider's defaults, never old secrets.
184
+ export function mergeSettingsPatch(current = {}, patch = {}) {
185
+ const providerChanged = patch.realtimeProvider !== undefined
186
+ && normalizeRealtimeProvider(patch.realtimeProvider) !== normalizeRealtimeProvider(current.realtimeProvider)
187
+ return {
188
+ ...current,
189
+ ...(providerChanged ? realtimeSettingsValues({ realtimeProvider: patch.realtimeProvider }) : {}),
190
+ ...patch,
187
191
  }
188
- return { ...values, realtimeProvider }
189
192
  }
190
193
 
191
- export function parseSettings(content = '', fallback = {}, realtimeDrafts = {}) {
192
- const values = migrateRealtimeFileEnvironment(parseEnv(content))
194
+ export function parseSettings(content = '', fallback = {}) {
195
+ const values = parseEnv(content)
193
196
  const agentProtocol = cleanAgentProtocol(configured(
194
197
  values,
195
198
  'AGENT_PROTOCOL',
@@ -224,7 +227,7 @@ export function parseSettings(content = '', fallback = {}, realtimeDrafts = {})
224
227
  const realtimeProvider = normalizeRealtimeProvider(configured(
225
228
  values,
226
229
  'QWEN_AUDIO_REALTIME_PROVIDER',
227
- fallback.QWEN_AUDIO_REALTIME_PROVIDER || realtimeDrafts.realtimeProvider || DEFAULTS.realtimeProvider,
230
+ fallback.QWEN_AUDIO_REALTIME_PROVIDER || DEFAULTS.realtimeProvider,
228
231
  ))
229
232
  const configuredOrbStyle = configured(
230
233
  values,
@@ -273,7 +276,7 @@ export function parseSettings(content = '', fallback = {}, realtimeDrafts = {})
273
276
  fallback.QWEN_AUDIO_WAKE_WORD_ENABLED || '',
274
277
  ),
275
278
  ).toLowerCase() === 'true',
276
- ...parseRealtimeSettings(values, fallback, realtimeProvider, realtimeDrafts),
279
+ ...parseRealtimeSettings(values, fallback, realtimeProvider),
277
280
  agentProtocol,
278
281
  backendModel: String(configured(
279
282
  values,
@@ -353,13 +356,13 @@ export function normalizeSettings(settings = {}) {
353
356
  }
354
357
  }
355
358
 
356
- export function realtimeSettingsConfiguration(settings = {}) {
357
- return resolveRealtimeFrontendConfiguration(realtimeRuntimeEnvironment(settings))
359
+ export function realtimeSettingsConfiguration(settings = {}, modelCatalogs = BUILTIN_REALTIME_MODEL_CATALOGS) {
360
+ return resolveRealtimeFrontendConfiguration(realtimeRuntimeEnvironment(settings), { modelCatalogs })
358
361
  }
359
362
 
360
- export function realtimeSettingsConfigured(settings = {}) {
363
+ export function realtimeSettingsConfigured(settings = {}, modelCatalogs) {
361
364
  try {
362
- const frontend = realtimeSettingsConfiguration(settings)
365
+ const frontend = realtimeSettingsConfiguration(settings, modelCatalogs)
363
366
  assertRealtimeFrontendModel(frontend.active)
364
367
  return frontend.active.configured && Boolean(cleanRealtimeUrl(frontend.active.endpoint, ''))
365
368
  } catch {
@@ -367,6 +370,11 @@ export function realtimeSettingsConfigured(settings = {}) {
367
370
  }
368
371
  }
369
372
 
373
+ export function realtimeSettingsChanged(previous, next, modelCatalogs, runningSignature = '') {
374
+ const before = runningSignature || realtimeSettingsConfiguration(previous, modelCatalogs).active.signature
375
+ return before !== realtimeSettingsConfiguration(next, modelCatalogs).active.signature
376
+ }
377
+
370
378
  // Applies a just-saved settings patch to a live environment, mirroring the
371
379
  // key mapping of updateSettingsContent. Without this the desktop process
372
380
  // keeps serving the values it loaded first — the config file is only read
@@ -374,7 +382,7 @@ export function realtimeSettingsConfigured(settings = {}) {
374
382
  // would look ignored until the app itself restarts.
375
383
  export function applySettingsEnvironment(settings = {}, env = process.env) {
376
384
  const realtimeChanged = hasRealtimeSettingsPatch(settings)
377
- const normalized = normalizeSettings(realtimeChanged ? { ...parseSettings('', env), ...settings } : settings)
385
+ const normalized = normalizeSettings(realtimeChanged ? mergeSettingsPatch(parseSettings('', env), settings) : settings)
378
386
  const backend = backendDefinition(normalized.agentProtocol)
379
387
  const entries = Object.entries(SETTING_KEYS)
380
388
  .filter(([field]) => settings[field] !== undefined)
@@ -394,7 +402,6 @@ export function applySettingsEnvironment(settings = {}, env = process.env) {
394
402
  else env[key] = text
395
403
  }
396
404
  if (realtimeChanged) {
397
- delete env.QWEN_AUDIO_REALTIME_API_KEY
398
405
  delete env.QWEN_AUDIO_REALTIME_ENDPOINT
399
406
  Object.assign(env, realtimeRuntimeEnvironment(normalized))
400
407
  }
@@ -403,13 +410,13 @@ export function applySettingsEnvironment(settings = {}, env = process.env) {
403
410
 
404
411
  // The form is unified; persistence is not. Gateway settings and client
405
412
  // preferences use separate files without duplicating validation or schemas.
406
- export function updateSettingsContent(content = '', settings = {}, { scope = 'all', realtimeDrafts = {} } = {}) {
413
+ export function updateSettingsContent(content = '', settings = {}, { scope = 'all', effectiveSettings = {} } = {}) {
407
414
  if (!['all', 'gateway', 'client'].includes(scope)) throw new TypeError('invalid settings scope')
408
415
  const accepts = key => scope === 'all'
409
416
  || (scope === 'client') === CLIENT_ENVIRONMENT_KEYS.has(key)
410
417
  const realtimeChanged = scope !== 'client' && hasRealtimeSettingsPatch(settings)
411
418
  const normalized = normalizeSettings(realtimeChanged
412
- ? { ...parseSettings(content, {}, realtimeDrafts), ...realtimeDrafts, ...settings }
419
+ ? mergeSettingsPatch({ ...parseSettings(content), ...effectiveSettings }, settings)
413
420
  : settings)
414
421
  const values = Object.fromEntries(
415
422
  Object.entries(SETTING_KEYS)
@@ -443,7 +450,6 @@ export function updateSettingsContent(content = '', settings = {}, { scope = 'al
443
450
  'QWEN_AUDIO_DESKTOP_AUTO_SLEEP_SECONDS',
444
451
  ])
445
452
  if (realtimeChanged) {
446
- removed.add('QWEN_AUDIO_REALTIME_API_KEY')
447
453
  removed.add('QWEN_AUDIO_REALTIME_ENDPOINT')
448
454
  }
449
455
  const seen = new Set()
@@ -19,17 +19,20 @@ import { gatewaySetupStatus } from '../../shared/gateway/setup.mjs'
19
19
  import {
20
20
  applySettingsEnvironment,
21
21
  hasRealtimeSettingsPatch,
22
+ mergeSettingsPatch,
22
23
  normalizeSettings,
23
24
  parseSettings,
25
+ realtimeSettingsConfiguration,
24
26
  updateSettingsContent,
25
27
  } from './settings-config.mjs'
26
28
  import { normalizeConversationSessionId } from '../../shared/conversation-session.mjs'
27
- import { migrateRealtimeFileEnvironment, mergeRealtimeEnvironment, realtimeSettingsProfileState, realtimeSettingsFromProfileState, realtimeSettingsValues } from '../../shared/realtime-provider-definitions.mjs'
29
+ import { BUILTIN_REALTIME_MODEL_CATALOGS } from '../../shared/realtime-model-catalog.mjs'
30
+ import { assertRealtimeFrontendModel } from '../../shared/realtime-provider-catalog.mjs'
31
+ import { mergeRealtimeEnvironment, realtimeSettingsValues } from '../../shared/realtime-provider-definitions.mjs'
28
32
 
29
33
  export const SETTINGS_FILE = 'config.env'
30
34
  export const CLIENT_SETTINGS_FILE = 'settings.env'
31
35
  export const UI_STATE_FILE = 'ui-state.json'
32
- export const REALTIME_PROFILES_FILE = 'realtime-profiles.json'
33
36
 
34
37
  // Everything written here is user configuration, including credentials, so it
35
38
  // stays readable by its owner alone.
@@ -84,6 +87,7 @@ function writePrivateFile(path, content) {
84
87
  * @returns {{
85
88
  * configDir: string, clientDir: string, path: string, clientSettingsPath: string, uiStatePath: string,
86
89
  * load: () => object,
90
+ * modelCatalogs: () => object,
87
91
  * save: (settings: object) => object,
88
92
  * status: () => { ready: boolean, provider: string|null, missing: object[] },
89
93
  * ready: () => boolean,
@@ -105,7 +109,6 @@ export function createSettingsStore({
105
109
  const clientDirectory = resolve(clientDir)
106
110
  const settingsPath = resolve(directory, SETTINGS_FILE)
107
111
  const clientSettingsPath = resolve(clientDirectory, CLIENT_SETTINGS_FILE)
108
- const realtimeProfilesPath = resolve(directory, REALTIME_PROFILES_FILE)
109
112
  const uiStatePath = resolve(clientDirectory, UI_STATE_FILE)
110
113
 
111
114
  // Reading must never create anything: the startup gate runs before a host
@@ -115,28 +118,18 @@ export function createSettingsStore({
115
118
  updateSettingsContent(readTextFile(settingsPath), {}, { scope: 'gateway' })
116
119
  + updateSettingsContent(readTextFile(clientSettingsPath), {}, { scope: 'client' })
117
120
  )
118
- const load = () => {
119
- const raw = readTextFile(realtimeProfilesPath)
120
- let drafts = {}
121
- if (raw) {
122
- try {
123
- const state = JSON.parse(raw)
124
- if (!state || typeof state !== 'object' || !state.profiles || typeof state.profiles !== 'object') throw new Error()
125
- drafts = realtimeSettingsFromProfileState(state)
126
- } catch {
127
- throw new Error('Invalid realtime-profiles.json; restore or correct the profile file before saving settings')
128
- }
129
- }
130
- return parseSettings(readContent(), env, drafts)
131
- }
121
+ const load = () => parseSettings(readContent(), env)
132
122
 
133
123
  // The same readiness the startup gate reads: stored values first, then the
134
124
  // live environment for slots the file leaves unset — mirroring how the
135
125
  // Gateway itself loads config.env.
136
- const effectiveEnvironment = () => mergeRealtimeEnvironment(
126
+ const effectiveEnvironment = () => ({ ...mergeRealtimeEnvironment(
137
127
  env,
138
- migrateRealtimeFileEnvironment(parseEnv(readTextFile(settingsPath))),
139
- )
128
+ parseEnv(readTextFile(settingsPath)),
129
+ ), QWAUDIO_CONFIG_DIR: directory })
130
+ // Supported models ship with the application; local JSON cannot register
131
+ // models or change the protocol defaults used by this settings store.
132
+ const modelCatalogs = () => BUILTIN_REALTIME_MODEL_CATALOGS
140
133
 
141
134
  const loadUiState = () => {
142
135
  const content = readTextFile(uiStatePath)
@@ -166,15 +159,14 @@ export function createSettingsStore({
166
159
  clientDir: clientDirectory,
167
160
  path: settingsPath,
168
161
  clientSettingsPath,
169
- realtimeProfilesPath,
170
162
  uiStatePath,
171
163
  load,
172
- preview: settings => normalizeSettings({ ...load(), ...settings }),
164
+ modelCatalogs,
165
+ preview: settings => normalizeSettings(mergeSettingsPatch(load(), settings)),
173
166
 
174
167
  save(settings) {
175
- // Keep provider drafts separate from the five active runtime variables.
176
168
  const realtimeChanged = hasRealtimeSettingsPatch(settings)
177
- let nextSettings = normalizeSettings({ ...load(), ...settings })
169
+ let nextSettings = normalizeSettings(mergeSettingsPatch(load(), settings))
178
170
  for (const [path, root, scope] of [
179
171
  [settingsPath, directory, 'gateway'],
180
172
  [clientSettingsPath, clientDirectory, 'client'],
@@ -182,11 +174,10 @@ export function createSettingsStore({
182
174
  withFileTransaction(path, () => {
183
175
  const current = readTextFile(path)
184
176
  if (scope === 'gateway' && realtimeChanged) {
185
- nextSettings = normalizeSettings({ ...load(), ...settings })
186
- mkdirSync(root, { recursive: true, mode: PRIVATE_DIRECTORY_MODE })
187
- writePrivateFile(realtimeProfilesPath, JSON.stringify(realtimeSettingsProfileState(nextSettings), null, 2) + '\n')
177
+ nextSettings = normalizeSettings(mergeSettingsPatch(load(), settings))
178
+ assertRealtimeFrontendModel(realtimeSettingsConfiguration(nextSettings, modelCatalogs()).active)
188
179
  }
189
- const next = updateSettingsContent(current, settings, { scope, realtimeDrafts: nextSettings })
180
+ const next = updateSettingsContent(current, settings, { scope, effectiveSettings: nextSettings })
190
181
  if (next === current || (!current && !next.trim())) return
191
182
  mkdirSync(root, { recursive: true, mode: PRIVATE_DIRECTORY_MODE })
192
183
  writePrivateFile(path, next)