qwen-audio-agent 2.0.1 → 2.2.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 (208) hide show
  1. package/README.md +21 -10
  2. package/README_ZH.md +19 -10
  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 +36 -6
  7. package/cli/src/gateway-service.mjs +7 -1
  8. package/cli/src/launcher.mjs +13 -0
  9. package/config/frontend-agent/LIVE_PROMPT.md +64 -0
  10. package/config/frontend-agent/PROMPT.md +29 -26
  11. package/desktop/src/i18n.mjs +6 -1
  12. package/desktop/src/settings-config.mjs +32 -40
  13. package/desktop/src/settings-store.mjs +19 -28
  14. package/docs/architecture/deep-dive.md +103 -66
  15. package/docs/architecture/deep-dive.zh.md +73 -50
  16. package/docs/backends/configuration.md +4 -4
  17. package/docs/backends/configuration.zh.md +4 -4
  18. package/docs/backends/overview.md +3 -0
  19. package/docs/backends/overview.zh.md +3 -0
  20. package/docs/configuration/backend.md +15 -1
  21. package/docs/configuration/backend.zh.md +15 -1
  22. package/docs/configuration/frontend.md +78 -28
  23. package/docs/configuration/frontend.zh.md +76 -28
  24. package/docs/configuration.md +1 -1
  25. package/docs/configuration.zh.md +1 -1
  26. package/docs/contract.md +24 -2
  27. package/docs/contract.zh.md +20 -2
  28. package/docs/extensions.md +14 -0
  29. package/docs/extensions.zh.md +11 -0
  30. package/docs/gateway-protocol.md +26 -0
  31. package/docs/gateway-protocol.zh.md +22 -0
  32. package/docs/gateway-webrtc-client.md +3 -3
  33. package/docs/gateway-webrtc-client.zh.md +3 -3
  34. package/docs/getting-started/install.md +4 -1
  35. package/docs/getting-started/install.zh.md +4 -1
  36. package/docs/getting-started/mobile.md +8 -2
  37. package/docs/getting-started/mobile.zh.md +5 -0
  38. package/docs/getting-started/quickstart.md +2 -2
  39. package/docs/getting-started/quickstart.zh.md +2 -2
  40. package/docs/getting-started/webui.md +2 -0
  41. package/docs/getting-started/webui.zh.md +2 -0
  42. package/docs/guides/knowledge.md +8 -5
  43. package/docs/guides/knowledge.zh.md +4 -3
  44. package/docs/guides/tasks.md +63 -2
  45. package/docs/guides/tasks.zh.md +45 -1
  46. package/docs/guides/web-search.md +32 -1
  47. package/docs/guides/web-search.zh.md +28 -1
  48. package/docs/operations/troubleshooting.md +30 -0
  49. package/docs/operations/troubleshooting.zh.md +26 -0
  50. package/docs/reference/backend-adapter-sdk.md +33 -2
  51. package/docs/reference/backend-adapter-sdk.zh.md +29 -2
  52. package/docs/reference/cli.md +3 -3
  53. package/docs/reference/cli.zh.md +3 -3
  54. package/docs/scenarios/lightrag.md +2 -2
  55. package/docs/scenarios/lightrag.zh.md +2 -2
  56. package/docs/scenarios/x-omni.md +5 -2
  57. package/docs/scenarios/x-omni.zh.md +5 -2
  58. package/docs/voice-agent-architecture-presentation.zh.md +34 -37
  59. package/docs/voice-frontends/custom-provider.md +22 -4
  60. package/docs/voice-frontends/custom-provider.zh.md +22 -4
  61. package/docs/voice-frontends/google-live.md +14 -8
  62. package/docs/voice-frontends/google-live.zh.md +13 -8
  63. package/docs/voice-frontends/gpt-live-1.md +149 -0
  64. package/docs/voice-frontends/gpt-live-1.zh.md +114 -0
  65. package/docs/voice-frontends/minicpm-o.md +8 -4
  66. package/docs/voice-frontends/minicpm-o.zh.md +7 -4
  67. package/docs/voice-frontends/{gpt-live.md → openai-realtime.md} +19 -10
  68. package/docs/voice-frontends/{gpt-live.zh.md → openai-realtime.zh.md} +18 -10
  69. package/docs/voice-frontends/qwen-audio-live.md +164 -0
  70. package/docs/voice-frontends/qwen-audio-live.zh.md +122 -0
  71. package/docs/voice-frontends/qwen-audio-realtime.md +41 -15
  72. package/docs/voice-frontends/qwen-audio-realtime.zh.md +34 -12
  73. package/docs/voice-frontends/qwen-omni-realtime.md +12 -9
  74. package/docs/voice-frontends/qwen-omni-realtime.zh.md +12 -9
  75. package/docs/voice-frontends/speech-to-speech.md +8 -4
  76. package/docs/voice-frontends/speech-to-speech.zh.md +7 -3
  77. package/docs/voice-frontends/stepfun.md +7 -4
  78. package/docs/voice-frontends/stepfun.zh.md +7 -4
  79. package/examples/webrtc/start.mjs +2 -1
  80. package/package.json +34 -16
  81. package/scripts/audit-dependencies.mjs +3 -25
  82. package/scripts/electron-smoke.mjs +5 -5
  83. package/scripts/patch-build-node-gyp.mjs +63 -0
  84. package/scripts/prepare-build.mjs +2 -0
  85. package/scripts/release-check +2 -2
  86. package/scripts/runtime/claude-code-acp.mjs +5 -5
  87. package/scripts/verify-package.mjs +3 -0
  88. package/server/package.json +5 -5
  89. package/server/src/app/gateway-application.mjs +3 -0
  90. package/server/src/app/gateway-http-routes.mjs +3 -0
  91. package/server/src/app/session-conversation-history.mjs +9 -1
  92. package/server/src/backend/adapters/a2a/backend-adapter.mjs +32 -26
  93. package/server/src/backend/adapters/acp/backend-adapter.mjs +703 -251
  94. package/server/src/backend/adapters/acp/coordinator-contract.mjs +2 -13
  95. package/server/src/backend/adapters/acp/coordinator-instructions.mjs +29 -8
  96. package/server/src/backend/adapters/acp/coordinator-queue.mjs +58 -0
  97. package/server/src/backend/adapters/acp/drivers/codex.mjs +1 -1
  98. package/server/src/backend/adapters/acp/drivers/openclaw.mjs +1 -2
  99. package/server/src/backend/adapters/acp/input-broker.mjs +2 -0
  100. package/server/src/backend/adapters/acp/process-client.mjs +111 -16
  101. package/server/src/backend/adapters/acp/session-configuration.mjs +2 -19
  102. package/server/src/backend/adapters/acp/session-registry.mjs +9 -0
  103. package/server/src/backend/adapters/acp/session-tools.mjs +1 -1
  104. package/server/src/backend/adapters/acp/turn-updates.mjs +188 -0
  105. package/server/src/backend/adapters/acp/work-continuation.mjs +48 -0
  106. package/server/src/backend/adapters/agent-client.mjs +24 -1
  107. package/server/src/backend/adapters/llm/backend-adapter.mjs +393 -0
  108. package/server/src/backend/adapters/muse/backend-adapter.mjs +2 -0
  109. package/server/src/backend/availability.mjs +12 -3
  110. package/server/src/backend/backend-adapter-sdk.mjs +3 -0
  111. package/server/src/backend/backend-port.mjs +13 -0
  112. package/server/src/backend/backend-work-runtime.mjs +23 -0
  113. package/server/src/client/client-command-runtime.mjs +14 -0
  114. package/server/src/conversation/conversation-sync.mjs +26 -2
  115. package/server/src/conversation/frontend-agent-context.mjs +18 -5
  116. package/server/src/conversation/frontend-notes.mjs +7 -5
  117. package/server/src/conversation/task-result-projector.mjs +1 -1
  118. package/server/src/core/backend-events.mjs +4 -0
  119. package/server/src/core/citation.mjs +8 -2
  120. package/server/src/core/config.mjs +46 -54
  121. package/server/src/core/gateway-protocol.mjs +4 -1
  122. package/server/src/core/request-security.mjs +7 -1
  123. package/server/src/core/work-conversation-context.mjs +138 -0
  124. package/server/src/core/work-input-request.mjs +1 -0
  125. package/server/src/frontend/frontend-tools.mjs +20 -7
  126. package/server/src/frontend/retrieval/providers/bing.mjs +23 -12
  127. package/server/src/frontend/retrieval/providers/factory.mjs +18 -1
  128. package/server/src/frontend/retrieval/providers/mcp.mjs +30 -11
  129. package/server/src/frontend/retrieval/providers/so360.mjs +23 -12
  130. package/server/src/frontend/tools/agent-task-runtime.mjs +119 -99
  131. package/server/src/frontend/tools/features/agent-task-tools.mjs +23 -42
  132. package/server/src/frontend/tools/frontend-tool-context.mjs +2 -2
  133. package/server/src/frontend/tools/spawn-thinking-tool.mjs +2 -2
  134. package/server/src/frontend/tools/tool-call-handler.mjs +166 -86
  135. package/server/src/knowledge/providers/local/library.mjs +26 -6
  136. package/server/src/knowledge/providers/local/provider.mjs +25 -6
  137. package/server/src/memory/providers/markdown/context-store.mjs +24 -11
  138. package/server/src/orchestration/session-task-coordinator.mjs +13 -3
  139. package/server/src/orchestration/task-operations.mjs +54 -12
  140. package/server/src/orchestration/task-updates.mjs +82 -0
  141. package/server/src/task/reminder-scheduler.mjs +5 -1
  142. package/server/src/task/task-manager.mjs +72 -15
  143. package/server/src/task/task-recovery.mjs +12 -2
  144. package/server/src/task/task-scheduler.mjs +5 -5
  145. package/server/src/task/task-state.mjs +13 -0
  146. package/server/src/transport/gateway-client-transport.mjs +35 -0
  147. package/server/src/transport/webrtc/protocol.mjs +1 -1
  148. package/server/src/voice/announcement/announcement-manager.mjs +3 -0
  149. package/server/src/voice/audio-stream-diagnostics.mjs +139 -0
  150. package/server/src/voice/native-delegation-runtime.mjs +360 -0
  151. package/server/src/voice/providers/dashscope-live.mjs +93 -0
  152. package/server/src/voice/providers/dashscope.mjs +45 -33
  153. package/server/src/voice/providers/doubao-seeduplex-protocol.mjs +54 -0
  154. package/server/src/voice/providers/doubao-seeduplex.mjs +16 -11
  155. package/server/src/voice/providers/ga-protocol.mjs +7 -2
  156. package/server/src/voice/providers/google-live-protocol.mjs +124 -34
  157. package/server/src/voice/providers/google-live.mjs +20 -14
  158. package/server/src/voice/providers/gpt-live-1-protocol.mjs +597 -0
  159. package/server/src/voice/providers/gpt-live-1.mjs +3 -0
  160. package/server/src/voice/providers/gpt-live-client-context.mjs +182 -0
  161. package/server/src/voice/providers/minicpm-o.mjs +9 -7
  162. package/server/src/voice/providers/openai-live.mjs +150 -0
  163. package/server/src/voice/providers/{gpt-live.mjs → openai-realtime.mjs} +23 -19
  164. package/server/src/voice/providers/provider-registry.mjs +11 -1
  165. package/server/src/voice/providers/qwen-live-protocol.mjs +399 -0
  166. package/server/src/voice/providers/registry.mjs +47 -12
  167. package/server/src/voice/providers/runtime-configuration.mjs +34 -0
  168. package/server/src/voice/providers/s2s.mjs +9 -7
  169. package/server/src/voice/providers/stepfun.mjs +14 -11
  170. package/server/src/voice/realtime-input-runtime.mjs +58 -20
  171. package/server/src/voice/realtime-presentation-runtime.mjs +111 -27
  172. package/server/src/voice/realtime-provider-session.mjs +59 -14
  173. package/server/src/voice/realtime-provider.mjs +358 -45
  174. package/server/src/voice/realtime-session-runtime.mjs +282 -35
  175. package/server/src/voice/realtime-task-presentation.mjs +8 -2
  176. package/server/src/voice/realtime-turn-state.mjs +33 -2
  177. package/shared/backend/catalog.mjs +26 -2
  178. package/shared/backend/install.mjs +3 -1
  179. package/shared/backend/setup.mjs +43 -0
  180. package/shared/gateway/client-sdk.mjs +21 -6
  181. package/shared/gateway/setup.mjs +13 -1
  182. package/shared/gateway/websocket-auth.mjs +2 -1
  183. package/shared/protocol/gateway-client-protocol.mjs +14 -0
  184. package/shared/protocol/gateway-events.mjs +39 -1
  185. package/shared/realtime-legacy-environment.mjs +81 -0
  186. package/shared/realtime-model-catalog.mjs +68 -194
  187. package/shared/realtime-models/README.md +33 -0
  188. package/shared/realtime-models/dashscope.mjs +57 -0
  189. package/shared/realtime-models/google.mjs +10 -0
  190. package/shared/realtime-models/openai.mjs +24 -0
  191. package/shared/realtime-models/profile.mjs +38 -0
  192. package/shared/realtime-models/stepfun.mjs +10 -0
  193. package/shared/realtime-models/volcengine.mjs +12 -0
  194. package/shared/realtime-provider-catalog.mjs +23 -11
  195. package/shared/realtime-provider-definitions.mjs +168 -235
  196. package/shared/runtime-environment.mjs +23 -30
  197. package/shared/skill-library.mjs +49 -13
  198. package/shared/web-search-configuration.mjs +25 -2
  199. package/tui/package.json +2 -2
  200. package/tui/src/index.mjs +14 -9
  201. package/tui/src/runtime-configuration.mjs +2 -0
  202. package/tui/src/terminal-commands.mjs +40 -0
  203. package/tui/src/text-cli.mjs +10 -1
  204. package/web/dist/assets/index-Bc2Q04J9.css +1 -0
  205. package/web/dist/assets/index-bY4DFXKT.js +96 -0
  206. package/web/dist/index.html +2 -2
  207. package/web/dist/assets/index-BRaiI-dW.js +0 -91
  208. package/web/dist/assets/index-D9k8R2JY.css +0 -1
@@ -26,7 +26,7 @@ function inputSchemaSummary(schema) {
26
26
  /** Realtime presentation adapter; no Task state, execution or transport ownership. */
27
27
  export function createRealtimeTaskPresentation({
28
28
  getState, getFrontend, deliveryRuntime, updateContext, cancelPermission,
29
- taskAnnouncementFactory, config, onError, onProgressError,
29
+ taskAnnouncementFactory, config, onError, onProgressError, onPresentRequest = () => {},
30
30
  }) {
31
31
  return {
32
32
  state: getState,
@@ -87,6 +87,8 @@ export function createRealtimeTaskPresentation({
87
87
  ] : [
88
88
  '<backend_input_request>',
89
89
  `task_id=${task.id}`,
90
+ `input_request_id=${request.id}`,
91
+ `kind=${request.kind || 'input'}`,
90
92
  `request=${request.prompt}`,
91
93
  ...(fields ? [`fields=${fields}`] : []),
92
94
  ...(request.mode === 'url' && request.url ? [`url=${request.url}`] : []),
@@ -101,7 +103,11 @@ export function createRealtimeTaskPresentation({
101
103
  instructions: permission ? permissionResponseInstructions : inputRequestResponseInstructions,
102
104
  contextTiming: 'immediate',
103
105
  },
104
- }), options)
106
+ }), options).then(outcome => {
107
+ // Asked once the question was put to the user, not while it waited.
108
+ if (outcome?.completed) onPresentRequest(request.id)
109
+ return outcome
110
+ })
105
111
  },
106
112
  resolveRequest(kind, id, { announced }) {
107
113
  const frontend = getFrontend()
@@ -24,6 +24,12 @@ export class RealtimeTurnState {
24
24
  this.turnSequence = 0
25
25
  this.committedTurnId = ''
26
26
  this.committedTurnGeneration = 0
27
+ // Each committed user turn and the generation it began in.
28
+ this.userTurns = new Map()
29
+ // The generation of the last boundary (interrupt, mute, close).
30
+ this.boundaryGeneration = 0
31
+ // The turn sequence when the Gateway first asked each request.
32
+ this.requestTurns = new Map()
27
33
  this.userSpeaking = false
28
34
  this.voiceStartItemId = ''
29
35
  this.manualInputGeneration = null
@@ -82,8 +88,8 @@ export class RealtimeTurnState {
82
88
  return { context, supersededVoiceTurn }
83
89
  }
84
90
 
85
- resolveInput(itemId) {
86
- return this.correlation.resolve(itemId, this.current())
91
+ resolveInput(itemId, { fallbackToCurrent = true } = {}) {
92
+ return this.correlation.resolve(itemId, fallbackToCurrent ? this.current() : null)
87
93
  }
88
94
 
89
95
  completeInput(itemId) {
@@ -123,9 +129,33 @@ export class RealtimeTurnState {
123
129
  if (this.isStale(context)) return false
124
130
  this.committedTurnId = context.turnId
125
131
  this.committedTurnGeneration = context.turnGeneration
132
+ this.userTurns.set(context.turnId, context.turnGeneration)
133
+ if (this.userTurns.size > 100) this.userTurns.delete(this.userTurns.keys().next().value)
126
134
  return true
127
135
  }
128
136
 
137
+ // Later user turns may have superseded this one, but no boundary has.
138
+ isUserTurnSinceBoundary(context) {
139
+ const began = this.userTurns.get(context?.turnId)
140
+ return began === context?.turnGeneration && began > this.boundaryGeneration
141
+ }
142
+
143
+ // Whether user turn `laterId` began after user turn `turnId`.
144
+ beganAfterTurn(laterId, turnId) {
145
+ return this.userTurns.get(laterId) > this.userTurns.get(turnId)
146
+ }
147
+
148
+ noteRequest(requestId) {
149
+ if (!requestId || this.requestTurns.has(requestId)) return
150
+ this.requestTurns.set(requestId, this.turnSequence)
151
+ if (this.requestTurns.size > 100) this.requestTurns.delete(this.requestTurns.keys().next().value)
152
+ }
153
+
154
+ // Only a turn that began after the Gateway asked a request answers it.
155
+ beganAfterRequest(turnId, requestId) {
156
+ return this.userTurns.get(turnId) > this.requestTurns.get(requestId)
157
+ }
158
+
129
159
  finishManualResponse(context, { automatic = false } = {}) {
130
160
  if (
131
161
  this.manualInputGeneration === null
@@ -145,6 +175,7 @@ export class RealtimeTurnState {
145
175
  advanceBoundary() {
146
176
  this.turnGeneration = ++this.turnSequence
147
177
  this.committedTurnGeneration = this.turnGeneration
178
+ this.boundaryGeneration = this.turnGeneration
148
179
  return this.current()
149
180
  }
150
181
 
@@ -272,7 +272,7 @@ const definitions = new Map([
272
272
  command: 'claude',
273
273
  executableEnvironment: 'CLAUDE_CODE_EXECUTABLE',
274
274
  integration: 'adapter',
275
- adapterCommand: 'claude-code-acp',
275
+ adapterCommand: 'claude-agent-acp',
276
276
  adapterEnvironment: 'CLAUDE_CODE_ACP_BIN',
277
277
  adapterRuntimeEnvironment: 'CLAUDE_CODE_ACP_RUNTIME',
278
278
  },
@@ -280,7 +280,7 @@ const definitions = new Map([
280
280
  installation: {
281
281
  steps: [
282
282
  { kind: 'npm', package: '@anthropic-ai/claude-code@latest', packageEnv: 'CLAUDE_CODE_PACKAGE' },
283
- { kind: 'npm', label: 'ACP 适配器', component: 'adapter', package: '@zed-industries/claude-code-acp@latest', packageEnv: 'CLAUDE_CODE_ACP_PACKAGE' },
283
+ { kind: 'npm', label: 'ACP 适配器', component: 'adapter', package: '@agentclientprotocol/claude-agent-acp@latest', packageEnv: 'CLAUDE_CODE_ACP_PACKAGE' },
284
284
  ],
285
285
  },
286
286
  configuration: { mode: 'backend-owned' },
@@ -436,6 +436,30 @@ const definitions = new Map([
436
436
  explicitListEnvironment: 'QWEN_AUDIO_AGENT_ACP_FORWARD_ENV',
437
437
  },
438
438
  }],
439
+ ['llm', {
440
+ id: 'llm',
441
+ label: 'LLM',
442
+ skills: null,
443
+ setup: {
444
+ integration: 'llm',
445
+ },
446
+ lifecycle: {
447
+ installation: null,
448
+ configuration: { mode: 'api' },
449
+ },
450
+ supportsFullPermission: false,
451
+ environment: {
452
+ names: [
453
+ 'QWEN_AUDIO_AGENT_LLM_API_KEY',
454
+ 'QWEN_AUDIO_AGENT_LLM_BASE_URL',
455
+ 'QWEN_AUDIO_AGENT_LLM_SYSTEM_PROMPT',
456
+ 'DASHSCOPE_API_KEY',
457
+ 'DASHSCOPE_BASE_URL',
458
+ 'OPENAI_API_KEY',
459
+ 'OPENAI_BASE_URL',
460
+ ],
461
+ },
462
+ }],
439
463
  ])
440
464
 
441
465
  export function backendDefinition(protocol) {
@@ -139,7 +139,9 @@ export function installSupport(id, {
139
139
  if (!spec) {
140
140
  return {
141
141
  supported: false,
142
- reason: '通用 ACP 接入的 Agent 需自行安装,并通过 ACP_COMMAND 配置',
142
+ reason: definition.setup?.integration === 'llm'
143
+ ? '裸 LLM 后台为内置适配器,无需安装;请配置 API Key、Base URL 与模型'
144
+ : '通用 ACP 接入的 Agent 需自行安装,并通过 ACP_COMMAND 配置',
143
145
  }
144
146
  }
145
147
  if (!steps.length) {
@@ -333,6 +333,45 @@ function inspectBackend(id, {
333
333
  const definition = backendDefinition(id)
334
334
  const spec = definition?.setup
335
335
  if (!spec) throw new Error(`后台 ${id} 缺少 setup 配置`)
336
+ if (spec.integration === 'llm') {
337
+ const apiKey = clean(
338
+ env.QWEN_AUDIO_AGENT_LLM_API_KEY
339
+ || env.DASHSCOPE_API_KEY
340
+ || env.OPENAI_API_KEY,
341
+ )
342
+ const model = clean(env.QWEN_AUDIO_AGENT_BACKEND_MODEL)
343
+ const issues = [
344
+ ...(!apiKey ? ['请设置 QWEN_AUDIO_AGENT_LLM_API_KEY(或 DASHSCOPE_API_KEY / OPENAI_API_KEY)'] : []),
345
+ ...(!model || model.toLowerCase() === 'auto'
346
+ ? ['请设置 QWEN_AUDIO_AGENT_BACKEND_MODEL']
347
+ : []),
348
+ ]
349
+ const ready = issues.length === 0
350
+ return {
351
+ id,
352
+ label: definition.label,
353
+ selected: id === selected,
354
+ ready,
355
+ backend: {
356
+ ready,
357
+ source: 'api',
358
+ path: '',
359
+ installed: true,
360
+ ...(!ready ? { issue: issues.join(';') } : {}),
361
+ },
362
+ adapter: {
363
+ ready: true,
364
+ source: 'builtin',
365
+ path: '',
366
+ installed: true,
367
+ },
368
+ integration: spec.integration,
369
+ configuration: 'api',
370
+ authentication: 'api-key',
371
+ issues,
372
+ platform,
373
+ }
374
+ }
336
375
  const configured = spec.commandEnvironment
337
376
  ? environmentValue(env, spec.commandEnvironment)
338
377
  : environmentValue(env, spec.executableEnvironment)
@@ -500,6 +539,7 @@ export async function inspectBackendSetupsAsync({
500
539
  }
501
540
 
502
541
  function integrationText(item) {
542
+ if (item.integration === 'llm') return '内置 OpenAI-compatible Chat Completions'
503
543
  if (item.integration === 'msp') return '原生 Muse Session Protocol'
504
544
  if (item.integration === 'native') return '原生 ACP'
505
545
  if (item.integration === 'bridge') return '内置 ACP Bridge'
@@ -510,6 +550,7 @@ function integrationText(item) {
510
550
 
511
551
  function backendText(item) {
512
552
  if (!item.backend.ready) return item.backend.issue
553
+ if (item.backend.source === 'api') return 'API 配置完整'
513
554
  if (item.backend.source === 'managed') {
514
555
  return `启动时通过 npx 自动下载兼容版本(${item.backend.path})`
515
556
  }
@@ -534,6 +575,8 @@ export function formatBackendSetup(report) {
534
575
  integrationText(item),
535
576
  item.configuration === 'automatic-bailian'
536
577
  ? '自动配置百炼 API Key 与后台模型'
578
+ : item.configuration === 'api'
579
+ ? '无会话历史、无工具的纯文本 LLM'
537
580
  : item.configuration === 'preserved'
538
581
  ? '复用用户级配置'
539
582
  : '配置由 ACP Agent 管理',
@@ -14,6 +14,7 @@ const RESULT_TYPES = new Set([
14
14
  GatewayClientProtocolEvent.CLIENT_EVENT_PUBLISH_RESULT,
15
15
  GatewayClientProtocolEvent.SESSION_OUTPUT_VOICE_UPDATED,
16
16
  GatewayClientProtocolEvent.TASK_CREATE_RESULT,
17
+ GatewayClientProtocolEvent.TASK_UPDATE_RESULT,
17
18
  GatewayClientProtocolEvent.TASK_GET_RESULT,
18
19
  GatewayClientProtocolEvent.TASK_LIST_RESULT,
19
20
  GatewayClientProtocolEvent.TASK_CANCEL_RESULT,
@@ -264,11 +265,21 @@ export class GatewayClient {
264
265
  #connect() {
265
266
  if (this.stopped) return
266
267
  this.onStatus?.({ state: 'connecting' })
267
- const socket = this.createSocket(this.url, {
268
- headers: this.accessToken
269
- ? { Authorization: `Bearer ${this.accessToken}` }
270
- : {},
271
- })
268
+ let socket
269
+ try {
270
+ socket = this.createSocket(this.url, {
271
+ headers: this.accessToken
272
+ ? { Authorization: `Bearer ${this.accessToken}` }
273
+ : {},
274
+ })
275
+ } catch (error) {
276
+ this.onStatus?.({ state: 'unavailable', phase: 'connection', error })
277
+ // Callers that own reconnects need the same terminal status as a timeout.
278
+ if (this.stopped || this.socket !== null) return
279
+ this.onStatus?.({ state: 'disconnected' })
280
+ if (this.socket === null) this.#scheduleReconnect()
281
+ return
282
+ }
272
283
  this.socket = socket
273
284
  this.connectTimer = setTimeout(() => {
274
285
  if (this.socket !== socket || this.stopped) return
@@ -380,7 +391,11 @@ export class GatewayClient {
380
391
  this.#rejectPending('connection_closed', 'Gateway connection closed')
381
392
  this.onStatus?.({ state: 'unavailable', phase, error })
382
393
  try { socket.close?.() } catch { /* The timeout must still schedule recovery. */ }
383
- this.#scheduleReconnect()
394
+ // The expired socket's close event is ignored after clearing this.socket.
395
+ // Callers such as the TUI own reconnects and still need the terminal status.
396
+ if (this.stopped || this.socket !== null) return
397
+ this.onStatus?.({ state: 'disconnected' })
398
+ if (this.socket === null) this.#scheduleReconnect()
384
399
  }
385
400
 
386
401
  #receive(event) {
@@ -12,7 +12,19 @@
12
12
  import { assertRealtimeFrontendModel, realtimeProviderDefinition, resolveRealtimeFrontendConfiguration } from '../realtime-provider-catalog.mjs'
13
13
 
14
14
  export function gatewaySetupStatus(env = process.env) {
15
- const frontend = resolveRealtimeFrontendConfiguration(env)
15
+ let frontend
16
+ try {
17
+ frontend = resolveRealtimeFrontendConfiguration(env)
18
+ } catch (error) {
19
+ return {
20
+ ready: false,
21
+ provider: env.QWEN_AUDIO_REALTIME_PROVIDER || null,
22
+ missing: [{
23
+ key: 'QWEN_AUDIO_REALTIME_PROVIDER',
24
+ message: error.message,
25
+ }],
26
+ }
27
+ }
16
28
  const missing = []
17
29
  try {
18
30
  assertRealtimeFrontendModel(frontend.active)
@@ -1,7 +1,8 @@
1
1
  export const GATEWAY_WEBSOCKET_PROTOCOL = 'qwaudio.gcp.v6'
2
2
 
3
3
  const GATEWAY_WEBSOCKET_BEARER_PREFIX = 'qwaudio.bearer.'
4
- const TOKEN_PATTERN = /^[A-Za-z0-9_-]{24,256}$/
4
+ // Device tokens the Gateway issues are 128-bit base64url, i.e. 22 characters.
5
+ const TOKEN_PATTERN = /^[A-Za-z0-9_-]{22,256}$/
5
6
 
6
7
  function protocolValues(header = '') {
7
8
  return String(header)
@@ -34,6 +34,8 @@ export const GatewayClientProtocolEvent = Object.freeze({
34
34
  CLIENT_PRESENCE_UPDATE: 'client.presence.update',
35
35
  TASK_CREATE: 'task.create',
36
36
  TASK_CREATE_RESULT: 'task.create.result',
37
+ TASK_UPDATE: 'task.update',
38
+ TASK_UPDATE_RESULT: 'task.update.result',
37
39
  TASK_GET: 'task.get',
38
40
  TASK_GET_RESULT: 'task.get.result',
39
41
  TASK_LIST: 'task.list',
@@ -294,6 +296,11 @@ export const GatewayTaskGetSchema = GatewayClientEnvelopeSchema.extend({
294
296
  task_id: IdentifierSchema,
295
297
  })
296
298
 
299
+ export const GatewayTaskUpdateSchema = GatewayTaskCreateSchema.extend({
300
+ type: z.literal(GatewayClientProtocolEvent.TASK_UPDATE),
301
+ task_id: IdentifierSchema,
302
+ })
303
+
297
304
  export const GatewayTaskListSchema = GatewayClientEnvelopeSchema.extend({
298
305
  type: z.literal(GatewayClientProtocolEvent.TASK_LIST),
299
306
  active: z.boolean().optional(),
@@ -340,6 +347,10 @@ const TaskResultBaseSchema = GatewayServerEnvelopeSchema.extend({
340
347
  export const GatewayTaskCreateResultSchema = TaskResultBaseSchema.extend({
341
348
  type: z.literal(GatewayClientProtocolEvent.TASK_CREATE_RESULT),
342
349
  })
350
+ export const GatewayTaskUpdateResultSchema = TaskResultBaseSchema.extend({
351
+ type: z.literal(GatewayClientProtocolEvent.TASK_UPDATE_RESULT),
352
+ status: z.enum(['accepted', 'duplicate']),
353
+ })
343
354
  export const GatewayTaskGetResultSchema = TaskResultBaseSchema.extend({
344
355
  type: z.literal(GatewayClientProtocolEvent.TASK_GET_RESULT),
345
356
  })
@@ -385,6 +396,7 @@ const GATEWAY_RUNTIME_CLIENT_MESSAGE_SCHEMAS = Object.freeze({
385
396
  [GatewayClientProtocolEvent.SESSION_OUTPUT_VOICE_UPDATE]: GatewaySessionOutputVoiceUpdateSchema,
386
397
  [GatewayClientProtocolEvent.CLIENT_ACTION_RESULT]: GatewayClientActionResultSchema,
387
398
  [GatewayClientProtocolEvent.TASK_CREATE]: GatewayTaskCreateSchema,
399
+ [GatewayClientProtocolEvent.TASK_UPDATE]: GatewayTaskUpdateSchema,
388
400
  [GatewayClientProtocolEvent.TASK_GET]: GatewayTaskGetSchema,
389
401
  [GatewayClientProtocolEvent.TASK_LIST]: GatewayTaskListSchema,
390
402
  [GatewayClientProtocolEvent.TASK_CANCEL]: GatewayTaskCancelSchema,
@@ -399,6 +411,7 @@ const GATEWAY_RUNTIME_SERVER_MESSAGE_SCHEMAS = Object.freeze({
399
411
  [GatewayClientProtocolEvent.SESSION_OUTPUT_VOICE_UPDATED]: GatewaySessionOutputVoiceUpdatedSchema,
400
412
  [GatewayClientProtocolEvent.CLIENT_ACTION_REQUEST]: GatewayClientActionRequestSchema,
401
413
  [GatewayClientProtocolEvent.TASK_CREATE_RESULT]: GatewayTaskCreateResultSchema,
414
+ [GatewayClientProtocolEvent.TASK_UPDATE_RESULT]: GatewayTaskUpdateResultSchema,
402
415
  [GatewayClientProtocolEvent.TASK_GET_RESULT]: GatewayTaskGetResultSchema,
403
416
  [GatewayClientProtocolEvent.TASK_LIST_RESULT]: GatewayTaskListResultSchema,
404
417
  [GatewayClientProtocolEvent.TASK_CANCEL_RESULT]: GatewayTaskCancelResultSchema,
@@ -417,6 +430,7 @@ const GATEWAY_RUNTIME_REQUIRED_CAPABILITIES = Object.freeze({
417
430
  // Results are matched to an outstanding, capability-checked action request
418
431
  // by ClientActionPort. A generic result must not require the sleep action.
419
432
  [GatewayClientProtocolEvent.TASK_CREATE]: GatewayClientCapability.TASK_COMMANDS,
433
+ [GatewayClientProtocolEvent.TASK_UPDATE]: GatewayClientCapability.TASK_COMMANDS,
420
434
  [GatewayClientProtocolEvent.TASK_GET]: GatewayClientCapability.TASK_COMMANDS,
421
435
  [GatewayClientProtocolEvent.TASK_LIST]: GatewayClientCapability.TASK_COMMANDS,
422
436
  [GatewayClientProtocolEvent.TASK_CANCEL]: GatewayClientCapability.TASK_COMMANDS,
@@ -15,6 +15,32 @@ export const GatewayEventEnvelopeSchema = z.object({
15
15
  type: z.string().min(1),
16
16
  }).passthrough()
17
17
 
18
+ // Optional, numeric-only client observations. Invalid diagnostics must not
19
+ // invalidate a real playback receipt or leak arbitrary client data into logs.
20
+ const AudioDiagnosticNumber = z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER)
21
+ const AudioDiagnosticCount = AudioDiagnosticNumber.int()
22
+ export const GatewayAudioPlaybackDiagnosticsSchema = z.object({
23
+ chunkCount: AudioDiagnosticCount.optional(),
24
+ pcmDurationMs: AudioDiagnosticNumber.optional(),
25
+ maxReceiveGapMs: AudioDiagnosticNumber.optional(),
26
+ startDelayMs: AudioDiagnosticNumber.optional(),
27
+ maxScheduledAheadMs: AudioDiagnosticNumber.optional(),
28
+ scheduleGapCount: AudioDiagnosticCount.optional(),
29
+ maxScheduleGapMs: AudioDiagnosticNumber.optional(),
30
+ contextSuspensionCount: AudioDiagnosticCount.optional(),
31
+ underrunCount: AudioDiagnosticCount.optional(),
32
+ })
33
+
34
+ export function normalizeAudioPlaybackDiagnostics(value) {
35
+ const parsed = GatewayAudioPlaybackDiagnosticsSchema.safeParse(value)
36
+ return parsed.success && Object.keys(parsed.data).length ? parsed.data : undefined
37
+ }
38
+
39
+ const OptionalAudioDiagnosticsSchema = z.preprocess(
40
+ normalizeAudioPlaybackDiagnostics,
41
+ GatewayAudioPlaybackDiagnosticsSchema.optional(),
42
+ )
43
+
18
44
  export const GatewayArtifactPartSchema = z.union([
19
45
  z.object({
20
46
  text: z.string(),
@@ -85,7 +111,7 @@ export const GatewayAuthorizationSchema = z.object({
85
111
  export const GatewayInputRequestSchema = z.object({
86
112
  id: z.string().min(1),
87
113
  taskId: z.string().nullable(),
88
- status: z.enum(['pending', 'accepted', 'declined', 'cancelled']),
114
+ status: z.enum(['pending', 'answered', 'accepted', 'declined', 'cancelled']),
89
115
  kind: z.enum(['input', 'authorization']),
90
116
  mode: z.enum(['text', 'form', 'url']),
91
117
  prompt: z.string().min(1),
@@ -130,6 +156,7 @@ export const GatewayTaskSchema = z.object({
130
156
  seriesId: z.string().min(1).optional(),
131
157
  parentTaskId: z.string().nullable().optional(),
132
158
  objective: z.string(),
159
+ revision: z.number().int().nonnegative().optional(),
133
160
  ownerId: z.string().optional(),
134
161
  sessionId: z.string().optional(),
135
162
  turnId: z.string().nullable().optional(),
@@ -142,6 +169,12 @@ export const GatewayTaskSchema = z.object({
142
169
  message: z.string().nullable().optional(),
143
170
  artifacts: z.array(GatewayArtifactSchema).optional(),
144
171
  activity: z.array(GatewayActivitySchema).optional(),
172
+ updates: z.array(z.object({
173
+ instruction: z.string(),
174
+ status: z.enum(['queued', 'pending', 'delivered', 'failed']),
175
+ createdAt: z.number(),
176
+ error: z.string().optional(),
177
+ })).max(100).optional(),
145
178
  delegation: z.unknown().optional(),
146
179
  authorization: GatewayAuthorizationSchema.nullable().optional(),
147
180
  inputRequest: GatewayInputRequestSchema.nullable().optional(),
@@ -211,13 +244,16 @@ const GatewayClientPayloadSchemas = Object.freeze({
211
244
  [GatewayClientEvent.INPUT_MESSAGE]: GatewayInputMessagePayloadSchema,
212
245
  [GatewayClientEvent.PLAYBACK_STARTED]: z.object({
213
246
  responseId: z.string().min(1),
247
+ audioDiagnostics: OptionalAudioDiagnosticsSchema,
214
248
  }).passthrough(),
215
249
  [GatewayClientEvent.PLAYBACK_ENDED]: z.object({
216
250
  responseId: z.string().min(1),
251
+ audioDiagnostics: OptionalAudioDiagnosticsSchema,
217
252
  }).passthrough(),
218
253
  [GatewayClientEvent.PLAYBACK_CANCELLED]: z.object({
219
254
  responseId: z.string().min(1),
220
255
  reason: z.string().optional(),
256
+ audioDiagnostics: OptionalAudioDiagnosticsSchema,
221
257
  }).passthrough(),
222
258
  })
223
259
 
@@ -226,6 +262,8 @@ const GatewayVoicePayloadSchemas = Object.freeze({
226
262
  inputSampleRate: z.number().int().positive(),
227
263
  provider: z.string().min(1).optional(),
228
264
  providerLabel: z.string().min(1).optional(),
265
+ interruptionPlaysOut: z.boolean().optional(),
266
+ pacedOutputAudio: z.boolean().optional(),
229
267
  }).passthrough(),
230
268
  [GatewayServerEvent.VOICE_CONNECTION]: z.object({
231
269
  state: z.string().min(1),
@@ -0,0 +1,81 @@
1
+ // Read-only compatibility at the config boundary. New settings are always
2
+ // written with the shared REALTIME_* names; legacy names are not runtime fields.
3
+ import { resolveDashScopeRealtimeModelProfile, resolveRealtimeModelProfile } from './realtime-model-catalog.mjs'
4
+ import { DEFAULT_OPENAI_REALTIME_MODEL, DEFAULT_GPT_LIVE_1_REALTIME_MODEL } from './realtime-models/openai.mjs'
5
+
6
+ const LEGACY_OPENAI_MODELS = Object.freeze({
7
+ 'gpt-live': DEFAULT_OPENAI_REALTIME_MODEL,
8
+ 'openai-realtime': DEFAULT_OPENAI_REALTIME_MODEL,
9
+ gptlive: DEFAULT_OPENAI_REALTIME_MODEL,
10
+ 'gpt-realtime': DEFAULT_OPENAI_REALTIME_MODEL,
11
+ 'gpt-live-1': DEFAULT_GPT_LIVE_1_REALTIME_MODEL,
12
+ 'openai-live': DEFAULT_GPT_LIVE_1_REALTIME_MODEL,
13
+ gptlive1: DEFAULT_GPT_LIVE_1_REALTIME_MODEL,
14
+ })
15
+
16
+ export function legacyRealtimeModel(provider) {
17
+ return LEGACY_OPENAI_MODELS[String(provider || '').trim().toLowerCase()]
18
+ }
19
+
20
+ const LEGACY_FIELDS = {
21
+ dashscope: {
22
+ API_KEY: ['DASHSCOPE_API_KEY'], URL: ['QWEN_AUDIO_REALTIME_BASE_URL', 'QWEN_AUDIO_REALTIME_ENDPOINT'],
23
+ },
24
+ stepfun: {
25
+ API_KEY: ['STEPFUN_API_KEY'], URL: ['STEPFUN_REALTIME_URL'],
26
+ MODEL: ['STEPFUN_REALTIME_MODEL'], VOICE: ['STEPFUN_REALTIME_VOICE'],
27
+ },
28
+ openai: {
29
+ API_KEY: ['OPENAI_API_KEY', 'GPT_LIVE_API_KEY'], URL: ['GPT_LIVE_REALTIME_URL', 'OPENAI_REALTIME_URL'],
30
+ MODEL: ['GPT_LIVE_REALTIME_MODEL', 'OPENAI_REALTIME_MODEL'], VOICE: ['GPT_LIVE_REALTIME_VOICE', 'OPENAI_REALTIME_VOICE'],
31
+ },
32
+ google: {
33
+ API_KEY: ['GOOGLE_API_KEY', 'GEMINI_API_KEY', 'GOOGLE_LIVE_API_KEY'], URL: ['GOOGLE_LIVE_REALTIME_URL', 'GEMINI_LIVE_REALTIME_URL'],
34
+ MODEL: ['GOOGLE_LIVE_REALTIME_MODEL', 'GEMINI_LIVE_REALTIME_MODEL'], VOICE: ['GOOGLE_LIVE_REALTIME_VOICE', 'GEMINI_LIVE_REALTIME_VOICE'],
35
+ },
36
+ volcengine: {
37
+ API_KEY: ['DOUBAO_API_KEY', 'SEEDUPLEX_API_KEY', 'VOLCENGINE_DOUBAO_API_KEY'], URL: ['DOUBAO_SEEDUPLEX_REALTIME_URL'],
38
+ MODEL: ['DOUBAO_SEEDUPLEX_REALTIME_MODEL'], VOICE: ['DOUBAO_SEEDUPLEX_REALTIME_VOICE'],
39
+ },
40
+ 'speech-to-speech': { API_KEY: ['SPEECH_TO_SPEECH_AUTH_TOKEN', 'S2S_API_KEY'], URL: ['SPEECH_TO_SPEECH_REALTIME_URL', 'S2S_REALTIME_URL'] },
41
+ 'minicpm-o': { API_KEY: ['MINICPM_O_AUTH_TOKEN'], URL: ['MINICPM_O_REALTIME_URL'] },
42
+ }
43
+
44
+ export function legacyOmniVoiceFromEnvironment(env, model = env.QWEN_AUDIO_REALTIME_MODEL) {
45
+ return resolveDashScopeRealtimeModelProfile(model).family === 'omni'
46
+ ? env.QWEN_OMNI_REALTIME_VOICE : undefined
47
+ }
48
+
49
+ export function legacyRealtimeEnvironment(env, provider, { deferModelVoice = false, model = env.QWEN_AUDIO_REALTIME_MODEL } = {}) {
50
+ const result = {}
51
+ const legacyModel = legacyRealtimeModel(env.QWEN_AUDIO_REALTIME_PROVIDER)
52
+ // Resolve the model before any model-specific fallback, including old model
53
+ // variables. A legacy Live provider never inherits Realtime-only variables.
54
+ const modelSource = ['QWEN_AUDIO_REALTIME_MODEL',
55
+ ...(legacyModel === DEFAULT_GPT_LIVE_1_REALTIME_MODEL ? [] : LEGACY_FIELDS[provider]?.MODEL || []),
56
+ ].find(name => env[name] !== undefined)
57
+ if (modelSource) result.QWEN_AUDIO_REALTIME_MODEL = env[modelSource]
58
+ else if (legacyModel) result.QWEN_AUDIO_REALTIME_MODEL = legacyModel
59
+ const selectedModel = String(result.QWEN_AUDIO_REALTIME_MODEL ?? model ?? '').trim() || legacyModel || ''
60
+ // OpenAI credentials are service-wide. Old Realtime-specific URL/model/voice
61
+ // variables must never configure a Live connection.
62
+ const fields = provider === 'openai' && resolveRealtimeModelProfile(selectedModel, provider).adapter === 'openai-live'
63
+ ? { API_KEY: ['OPENAI_API_KEY'] } : LEGACY_FIELDS[provider]
64
+ for (const suffix of ['API_KEY', 'URL', 'VOICE']) {
65
+ const key = 'QWEN_AUDIO_REALTIME_' + suffix
66
+ const source = [key, ...(fields?.[suffix] || [])].find(name => env[name] !== undefined)
67
+ if (source) result[key] = env[source]
68
+ }
69
+ if (provider === 'dashscope') {
70
+ if (result.QWEN_AUDIO_REALTIME_URL === undefined && String(env.DASHSCOPE_WORKSPACE_ID || '').trim()) {
71
+ const api = resolveRealtimeModelProfile(selectedModel, provider).api === 'live' ? 'live' : 'realtime'
72
+ result.QWEN_AUDIO_REALTIME_URL = 'wss://' + String(env.DASHSCOPE_WORKSPACE_ID).trim()
73
+ + '.cn-beijing.maas.aliyuncs.com/api-ws/v1/' + api
74
+ }
75
+ const omniVoice = deferModelVoice ? undefined : legacyOmniVoiceFromEnvironment(env)
76
+ if (result.QWEN_AUDIO_REALTIME_VOICE === undefined && omniVoice !== undefined) {
77
+ result.QWEN_AUDIO_REALTIME_VOICE = omniVoice
78
+ }
79
+ }
80
+ return result
81
+ }