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
@@ -1,9 +1,7 @@
1
- import { config, realtimeUrl } from '../../core/config.mjs'
1
+ import { providerRuntimeConfiguration } from './runtime-configuration.mjs'
2
+ import { config } from '../../core/config.mjs'
2
3
  import { PERMISSION_DECISIONS } from '../../../../shared/permission-decisions.mjs'
3
4
  import {
4
- DASHSCOPE_OMNI_38_FLASH_REALTIME_MODEL,
5
- DASHSCOPE_OMNI_FLASH_REALTIME_MODEL,
6
- DASHSCOPE_OMNI_PLUS_REALTIME_MODEL,
7
5
  listDashScopeRealtimeModelProfiles,
8
6
  resolveDashScopeRealtimeModelProfile,
9
7
  } from '../../../../shared/realtime-provider-catalog.mjs'
@@ -17,8 +15,22 @@ import {
17
15
  import { isRecoverableRealtimeInactivityError, RealtimeConfigurationError } from '../realtime-errors.mjs'
18
16
  import { openAiCompatibleProtocol } from './openai-compatible-protocol.mjs'
19
17
 
18
+ const connection = providerRuntimeConfiguration('dashscope')
19
+
20
+ function realtimeUrl() {
21
+ const url = new URL(connection.endpoint)
22
+ url.searchParams.set('model', connection.model)
23
+ return url.toString()
24
+ }
25
+
20
26
  function classifyError(message) {
21
27
  if (isRecoverableRealtimeInactivityError(message)) return 'inactivity'
28
+ // DashScope exposes one response slot per realtime session. A gateway
29
+ // response can race the tail of another model/tool response before its
30
+ // lifecycle events reach us; let RealtimeFrontend replay it after idle.
31
+ if (/another response is in progress|cannot create response while .*response.*in progress/i.test(message)) {
32
+ return 'response_slot_busy'
33
+ }
22
34
  if (/user is speaking/i.test(message)) return 'input_busy'
23
35
  if (/already has (?:a pending response request|an active response)|another response is in progress/i.test(message)) {
24
36
  return 'response_slot_busy'
@@ -41,7 +53,7 @@ function classifyError(message) {
41
53
  }
42
54
 
43
55
  function activeModelProfile() {
44
- return resolveDashScopeRealtimeModelProfile(config.audioModel)
56
+ return resolveDashScopeRealtimeModelProfile(connection.model, config.realtimeModelCatalogs)
45
57
  }
46
58
 
47
59
  function responseModalities(profile) {
@@ -54,70 +66,70 @@ function responseModalities(profile) {
54
66
 
55
67
  function validateSessionOptions({ sessionOptions = {} } = {}) {
56
68
  const profile = activeModelProfile()
57
- if (profile.id === DASHSCOPE_OMNI_38_FLASH_REALTIME_MODEL) {
58
- // 3.8 requires a workspace endpoint. Reject the known incompatible public
69
+ if (profile.sessionConstraints.workspaceEndpoint) {
70
+ // This API requires a workspace endpoint. Reject the known incompatible public
59
71
  // endpoints, but allow user-managed proxies instead of enforcing a host allowlist.
60
72
  let endpoint
61
73
  try {
62
- endpoint = new URL(config.audioRealtimeBaseUrl)
74
+ endpoint = new URL(connection.endpoint)
63
75
  } catch {
64
- throw new RealtimeConfigurationError('请配置有效的 QWEN_AUDIO_REALTIME_BASE_URL WebSocket 服务地址')
76
+ throw new RealtimeConfigurationError('请配置有效的 QWEN_AUDIO_REALTIME_URL WebSocket 服务地址')
65
77
  }
66
78
  if (['dashscope.aliyuncs.com', 'dashscope-intl.aliyuncs.com', 'dashscope-us.aliyuncs.com'].includes(endpoint.hostname)) {
67
79
  throw new RealtimeConfigurationError(
68
- `${profile.id} 需要百炼业务空间专属地址;请将 QWEN_AUDIO_REALTIME_BASE_URL(桌面版“服务地址”)设为该业务空间的 WebSocket 地址,并使用对应的 API Key`,
80
+ `${profile.id} 需要百炼业务空间专属地址;请将 QWEN_AUDIO_REALTIME_URL(桌面版“服务地址”)设为该业务空间的 WebSocket 地址,并使用对应的 API Key`,
69
81
  )
70
82
  }
71
83
  }
72
84
  const voice = String(sessionOptions.voice || '').trim() || dashscopeProvider.voice()
73
- // Known mismatch, not a complete voice allowlist. Cherry belongs to the older
74
- // Omni generation and causes silent closes on 3.5 (#334). Unknown/cloned
75
- // voices remain the provider's responsibility; do not infer their model from
76
- // their IDs. See https://help.aliyun.com/zh/model-studio/omni-voice-list
77
- if (
78
- voice === 'Cherry'
79
- && [DASHSCOPE_OMNI_FLASH_REALTIME_MODEL, DASHSCOPE_OMNI_PLUS_REALTIME_MODEL].includes(profile.id)
80
- ) {
85
+ // The selected API defines known incompatible voices, not a full allowlist.
86
+ // Unknown/cloned voices remain the upstream provider's responsibility.
87
+ if (profile.sessionConstraints.unsupportedVoices?.includes(voice)) {
88
+ const suggestion = profile.sessionDefaults.voice
89
+ ? `请改用该模型的默认音色 ${profile.sessionDefaults.voice}`
90
+ : '请清空音色以使用服务默认值,或选择该 API 支持的音色'
81
91
  throw new RealtimeConfigurationError(
82
- `音色 ${voice} 不支持模型 ${profile.id};请改用该模型的默认音色 ${profile.sessionDefaults.voice}`,
92
+ `音色 ${voice} 不支持模型 ${profile.id};${suggestion}`,
83
93
  )
84
94
  }
85
95
  }
86
96
 
87
97
  export const dashscopeProvider = {
88
98
  key: 'dashscope',
89
- label: 'DashScope Realtime',
99
+ label: 'DashScope',
90
100
  aliases: ['qwen'],
91
101
  inputSampleRate: 16000,
92
102
  outputSampleRate: 24000,
93
103
  protocol: openAiCompatibleProtocol,
94
104
 
95
105
  get capabilities() {
106
+ const { family } = activeModelProfile()
96
107
  return {
97
108
  perResponseInstructions: true,
98
109
  singleResponseSlot: true,
110
+ requiresResponseCreated: family === 'audio',
99
111
  sessionOutputVoice: true,
100
- conversationItemIdEcho: activeModelProfile().family !== 'omni',
112
+ conversationItemIdEcho: family !== 'omni',
101
113
  imageRequiresAudioStart: true,
102
114
  }
103
115
  },
104
116
 
105
- model: () => config.audioModel,
106
- modelCatalog: listDashScopeRealtimeModelProfiles,
117
+ model: () => connection.model,
118
+ modelCatalog: () => listDashScopeRealtimeModelProfiles(config.realtimeModelCatalogs),
107
119
  modelProfile: activeModelProfile,
108
- voice: () => config.audioVoice || activeModelProfile().sessionDefaults.voice,
109
- isConfigured: () => Boolean(config.dashscopeApiKey),
110
- missingConfigurationMessage: '请先配置 DASHSCOPE_API_KEY',
120
+ voice: () => String(connection.voice || '').trim() || activeModelProfile().sessionDefaults.voice,
121
+ isConfigured: () => connection.configured,
122
+ missingConfigurationMessage: '请先选择 dashscope 并配置 QWEN_AUDIO_REALTIME_API_KEY',
111
123
  connectTimeoutMessage: '连接 Qwen Audio Realtime 超时',
112
124
 
113
- url: () => realtimeUrl(config.audioRealtimeBaseUrl, config.audioModel),
114
- headers: () => ({ Authorization: `Bearer ${config.dashscopeApiKey}` }),
125
+ url: realtimeUrl,
126
+ headers: () => ({ Authorization: `Bearer ${connection.credential}` }),
115
127
  classifyError,
116
128
  validateSessionOptions,
117
129
 
118
130
  buildSession: ({ configured, agentContext, sessionOptions }) => {
119
131
  const profile = activeModelProfile()
120
- const sessionVoice = String(sessionOptions?.voice || '').trim()
132
+ const voice = String(sessionOptions?.voice || '').trim() || dashscopeProvider.voice()
121
133
  const session = {
122
134
  instructions: buildFrontendInstructions(agentContext),
123
135
  }
@@ -126,19 +138,19 @@ export const dashscopeProvider = {
126
138
  }
127
139
  if (!configured) {
128
140
  session.modalities = responseModalities(profile)
129
- if (profile.id === DASHSCOPE_OMNI_38_FLASH_REALTIME_MODEL) {
141
+ if (profile.api === 'omni-v2') {
130
142
  // Keep the client audio contract unchanged: mono PCM16, 16 kHz in /
131
- // 24 kHz out. 3.8 uses the nested audio configuration on first setup only.
143
+ // 24 kHz out. Omni v2 uses nested audio configuration on first setup only.
132
144
  session.audio = {
133
145
  input: { format: { type: 'pcm', sample_rate: dashscopeProvider.inputSampleRate } },
134
146
  output: {
135
147
  format: { type: 'pcm', sample_rate: dashscopeProvider.outputSampleRate },
136
- voice: sessionVoice || dashscopeProvider.voice(),
148
+ ...(voice ? { voice } : {}),
137
149
  },
138
150
  }
139
151
  } else {
140
152
  if (profile.modelCapabilities.audioOutput) {
141
- session.voice = sessionVoice || dashscopeProvider.voice()
153
+ if (voice) session.voice = voice
142
154
  session.output_audio_format = 'pcm'
143
155
  }
144
156
  if (profile.transportCapabilities.audioInput) {
@@ -77,6 +77,8 @@ function conversationItem(item) {
77
77
  export function createDoubaoSeeduplexProtocol() {
78
78
  let activeResponseId = ''
79
79
  let pendingUserText = ''
80
+ let activeAsrItemId = ''
81
+ let endedAsrItemId = ''
80
82
 
81
83
  const responseId = event => (
82
84
  event.response_id
@@ -187,6 +189,58 @@ export function createDoubaoSeeduplexProtocol() {
187
189
  response: { ...event.response, status: 'cancelled' },
188
190
  })
189
191
  }
192
+ // Doubao ASR events arrive with item_id but the Gateway input pipeline
193
+ // expects realtime-protocol field names and a paired speech boundary. The
194
+ // live endpoint never emits input_audio_buffer.speech_started,
195
+ // speech_stopped or committed, so both ends of one utterance are
196
+ // synthesized from the transcription events of a single item_id.
197
+ if (event?.type === 'conversation.item.input_audio_transcription.started') {
198
+ const itemId = event.item_id || id('item')
199
+ activeAsrItemId = itemId
200
+ endedAsrItemId = ''
201
+ return [{
202
+ type: 'input_audio_buffer.speech_started',
203
+ item_id: itemId,
204
+ event_id: event.event_id,
205
+ }]
206
+ }
207
+ if (event?.type === 'conversation.item.input_audio_transcription.delta') {
208
+ return [{
209
+ ...event,
210
+ item_id: event.item_id || activeAsrItemId,
211
+ text: '',
212
+ stash: String(event.delta || ''),
213
+ }]
214
+ }
215
+ if (event?.type === 'conversation.item.input_audio_transcription.completed') {
216
+ const itemId = event.item_id || activeAsrItemId
217
+ const events = []
218
+ // The close of an utterance is the only end boundary this provider
219
+ // sends, so it is synthesized here from the final transcript of the
220
+ // same item_id that opened the utterance above. Emitting it only for
221
+ // the item that is still open keeps the pair 1:1: a final that belongs
222
+ // to another (older) item stays transcript-only, so a late event can
223
+ // never close the turn that is speaking now.
224
+ // `input_audio_buffer.committed` rather than `speech_stopped` on
225
+ // purpose: the input pipeline ends the turn for both, but only
226
+ // `speech_stopped` arms the response-start watchdog, which would
227
+ // report a missing reply and reconnect the session whenever a duplex
228
+ // model answers late or stays silent.
229
+ if (itemId && itemId === activeAsrItemId && itemId !== endedAsrItemId) {
230
+ endedAsrItemId = itemId
231
+ events.push({
232
+ type: 'input_audio_buffer.committed',
233
+ item_id: itemId,
234
+ event_id: event.event_id,
235
+ })
236
+ }
237
+ events.push({
238
+ ...event,
239
+ item_id: itemId,
240
+ transcript: String(event.text || event.transcript || ''),
241
+ })
242
+ return events
243
+ }
190
244
  return normalizeResponseEvent(event)
191
245
  },
192
246
 
@@ -1,3 +1,4 @@
1
+ import { providerRuntimeConfiguration } from './runtime-configuration.mjs'
1
2
  import { config } from '../../core/config.mjs'
2
3
  import {
3
4
  realtimeModelCatalog,
@@ -12,10 +13,13 @@ import {
12
13
  import { isRecoverableRealtimeInactivityError } from '../realtime-errors.mjs'
13
14
  import { createDoubaoSeeduplexProtocol } from './doubao-seeduplex-protocol.mjs'
14
15
 
16
+ const connection = providerRuntimeConfiguration('doubao-seeduplex', { provider: 'volcengine' })
17
+
15
18
  function modelProfile() {
16
19
  return resolveRealtimeModelProfile(
17
- config.doubaoSeeduplexModel,
18
- 'doubao-seeduplex',
20
+ connection.model,
21
+ 'volcengine',
22
+ config.realtimeModelCatalogs,
19
23
  )
20
24
  }
21
25
 
@@ -25,7 +29,8 @@ function cleanText(value) {
25
29
 
26
30
  export const doubaoSeeduplexProvider = {
27
31
  key: 'doubao-seeduplex',
28
- label: 'Doubao Seeduplex Realtime',
32
+ provider: 'volcengine',
33
+ label: 'Volcengine',
29
34
  aliases: ['doubao', 'seeduplex', 'volcengine'],
30
35
  inputSampleRate: 16000,
31
36
  outputSampleRate: 24000,
@@ -40,15 +45,15 @@ export const doubaoSeeduplexProvider = {
40
45
  perResponseInstructions: false,
41
46
  sessionOutputVoice: true,
42
47
  },
43
- model: () => config.doubaoSeeduplexModel,
48
+ model: () => connection.model,
44
49
  modelProfile,
45
- modelCatalog: () => realtimeModelCatalog('doubao-seeduplex').profiles,
46
- voice: () => config.doubaoSeeduplexVoice || modelProfile().sessionDefaults.voice,
47
- isConfigured: () => Boolean(config.doubaoApiKey),
48
- missingConfigurationMessage: '请先配置 DOUBAO_API_KEY(也支持 SEEDUPLEX_API_KEY)',
50
+ modelCatalog: () => realtimeModelCatalog('volcengine', config.realtimeModelCatalogs).profiles,
51
+ voice: () => cleanText(connection.voice) || modelProfile().sessionDefaults.voice,
52
+ isConfigured: () => connection.configured,
53
+ missingConfigurationMessage: '请先选择 volcengine 并配置 QWEN_AUDIO_REALTIME_API_KEY',
49
54
  connectTimeoutMessage: '连接 Doubao Seeduplex Realtime 超时',
50
- url: () => config.doubaoSeeduplexRealtimeUrl,
51
- headers: () => ({ 'X-Api-Key': config.doubaoApiKey }),
55
+ url: () => connection.endpoint,
56
+ headers: () => ({ 'X-Api-Key': connection.credential }),
52
57
  classifyError: message => {
53
58
  if (isRecoverableRealtimeInactivityError(message)) return 'inactivity'
54
59
  if (/no active response|no response.*cancel/i.test(message)) return 'no_active_response'
@@ -68,7 +73,7 @@ export const doubaoSeeduplexProvider = {
68
73
  },
69
74
  output: {
70
75
  format: { type: 'pcm', rate: 24000 },
71
- voice,
76
+ ...(voice ? { voice } : {}),
72
77
  speed: 0,
73
78
  loudness: 0,
74
79
  },
@@ -31,7 +31,8 @@ const RESPONSE_CORRELATION_KEY = 'qwen_audio_request_id'
31
31
  *
32
32
  * - response payloads use output_modalities instead of modalities;
33
33
  * - text deltas arrive as response.output_text.* instead of response.text.*;
34
- * - conversation item ids are namespaced per item type.
34
+ * - conversation item ids are namespaced per item type and at most 32 characters;
35
+ * - conversation.item.added acknowledges an item, not a completed response.
35
36
  */
36
37
  export const gaRealtimeProtocol = Object.freeze({
37
38
  encodeOutgoing: payload => ({
@@ -45,6 +46,8 @@ export const gaRealtimeProtocol = Object.freeze({
45
46
  return { ...event, type: 'response.text.delta' }
46
47
  case 'response.output_text.done':
47
48
  return { ...event, type: 'response.text.done' }
49
+ case 'conversation.item.added':
50
+ return { ...event, type: 'conversation.item.created' }
48
51
  default:
49
52
  return event
50
53
  }
@@ -66,7 +69,9 @@ export const gaRealtimeProtocol = Object.freeze({
66
69
 
67
70
  conversationItemId: item => {
68
71
  const prefix = ID_PREFIXES[item?.type] || 'item'
69
- return `${prefix}_${randomUUID().replaceAll('-', '')}`
72
+ // OpenAI limits the entire item id, including its type namespace, to 32 characters.
73
+ const suffix = randomUUID().replaceAll('-', '').slice(0, 32 - prefix.length - 1)
74
+ return `${prefix}_${suffix}`
70
75
  },
71
76
 
72
77
  conversationItemCreate: item => ({
@@ -39,16 +39,19 @@ function googleTools(tools = []) {
39
39
  }
40
40
 
41
41
  export function createGoogleLiveProtocol() {
42
- const responseIds = new Set()
43
42
  const callNames = new Map()
44
43
  let activeResponseId = ''
45
44
  let interrupted = false
46
45
  let automaticResponsePending = false
46
+ let input = null
47
+ let responseInput = null
48
+ let outputTranscript = ''
49
+ let outputTranscriptFinished = false
47
50
 
48
51
  const ensureResponse = events => {
49
- if (!activeResponseId) activeResponseId = id('response')
50
- if (!responseIds.has(activeResponseId)) {
51
- responseIds.add(activeResponseId)
52
+ if (!activeResponseId) {
53
+ activeResponseId = id('response')
54
+ responseInput = input
52
55
  events.push({
53
56
  type: 'response.created',
54
57
  response: { id: activeResponseId },
@@ -59,16 +62,92 @@ export function createGoogleLiveProtocol() {
59
62
 
60
63
  const finishResponse = events => {
61
64
  if (!activeResponseId) return
65
+ if (!interrupted && outputTranscript.trim()) {
66
+ events.push({
67
+ type: 'response.audio_transcript.done',
68
+ response_id: activeResponseId,
69
+ transcript: outputTranscript,
70
+ })
71
+ }
62
72
  events.push({
63
73
  type: 'response.done',
64
74
  response: { id: activeResponseId, status: interrupted ? 'cancelled' : 'completed' },
65
75
  })
66
- responseIds.delete(activeResponseId)
67
76
  activeResponseId = ''
68
- interrupted = false
77
+ responseInput = null
78
+ outputTranscript = ''
79
+ outputTranscriptFinished = false
69
80
  automaticResponsePending = false
70
81
  }
71
82
 
83
+ const newInput = () => ({ id: id('input'), text: '' })
84
+
85
+ const finishInput = events => {
86
+ if (!input?.text.trim() || input.finalized) return
87
+ input.finalized = true
88
+ events.push({
89
+ type: 'conversation.item.input_audio_transcription.completed',
90
+ item_id: input.id,
91
+ transcript: input.text,
92
+ })
93
+ }
94
+
95
+ const handleActivity = (type, events) => {
96
+ if (type === 'ACTIVITY_START') {
97
+ if (input?.activity === 'speaking') return
98
+ if (input?.activity === 'ended' || input?.finalized) {
99
+ finishInput(events)
100
+ input = null
101
+ }
102
+ if (!input) {
103
+ input = newInput()
104
+ events.push({
105
+ type: 'input_audio_buffer.speech_started',
106
+ item_id: input.id,
107
+ providerHandlesInterruption: true,
108
+ })
109
+ }
110
+ input.activity = 'speaking'
111
+ } else if (type === 'ACTIVITY_END' && input?.activity === 'speaking') {
112
+ input.activity = 'ended'
113
+ events.push({ type: 'input_audio_buffer.speech_stopped', item_id: input.id })
114
+ if (input.finished) finishInput(events)
115
+ }
116
+ }
117
+
118
+ const handleInputTranscript = (transcription, events) => {
119
+ if (!transcription) return
120
+ const text = transcription.text
121
+ if (input?.finalized) {
122
+ if (input.activity || !input.modelTurnEnded) return
123
+ // An id-less explicit final that arrived after the model turn can be
124
+ // repeated. A new fragment or voice activity opens the next input.
125
+ if (transcription.finished === true && text === input.finalFragment) return
126
+ input = null
127
+ }
128
+ if (!input && typeof text === 'string' && text) {
129
+ input = newInput()
130
+ events.push({
131
+ type: 'conversation.item.input_audio_transcription.started',
132
+ item_id: input.id,
133
+ })
134
+ }
135
+ if (!input || input.finished) return
136
+ if (typeof text === 'string' && text) {
137
+ input.text += text
138
+ events.push({
139
+ type: 'conversation.item.input_audio_transcription.delta',
140
+ item_id: input.id,
141
+ text: input.text,
142
+ })
143
+ }
144
+ if (typeof transcription.finished === 'boolean') input.finished = transcription.finished
145
+ if (input.finished) input.finalFragment = text
146
+ if (input.activity !== 'speaking' && (input.finished || (input.modelTurnEnded && input.finished !== false))) {
147
+ finishInput(events)
148
+ }
149
+ }
150
+
72
151
  return Object.freeze({
73
152
  encodeOutgoing: payload => payload,
74
153
 
@@ -82,51 +161,60 @@ export function createGoogleLiveProtocol() {
82
161
  }
83
162
 
84
163
  const events = []
164
+ handleActivity(event?.voiceActivity?.type, events)
85
165
  const serverContent = event?.serverContent
86
166
  if (serverContent) {
87
- if (serverContent.interrupted) interrupted = true
88
- const responseId = (
89
- serverContent.modelTurn
90
- || serverContent.outputTranscription
91
- ) ? ensureResponse(events) : activeResponseId
167
+ if (serverContent.interrupted && !interrupted) {
168
+ interrupted = true
169
+ events.push({ type: 'response.interrupted', response_id: activeResponseId })
170
+ }
171
+ handleInputTranscript(serverContent.inputTranscription, events)
172
+ if (
173
+ serverContent.turnComplete && !interrupted
174
+ && input && input.activity !== 'speaking'
175
+ && (!responseInput || responseInput === input)
176
+ ) {
177
+ // A previous response can close while the next voice input is open.
178
+ // Keep an ended activity available for independently delivered ASR.
179
+ input.modelTurnEnded = true
180
+ if (input.finished !== false) finishInput(events)
181
+ if (!input.activity && input.finalized) input = null
182
+ }
92
183
 
93
- for (const part of serverContent.modelTurn?.parts || []) {
184
+ const modelTurn = interrupted ? null : serverContent.modelTurn
185
+ const modelResponseId = modelTurn ? ensureResponse(events) : activeResponseId
186
+ for (const part of modelTurn?.parts || []) {
94
187
  if (typeof part.text === 'string' && part.text) {
95
188
  events.push({
96
189
  type: 'response.text.delta',
97
- response_id: responseId || ensureResponse(events),
190
+ response_id: modelResponseId,
98
191
  delta: part.text,
99
192
  })
100
193
  }
101
194
  if (part.inlineData?.data) {
102
195
  events.push({
103
196
  type: 'response.audio.delta',
104
- response_id: responseId || ensureResponse(events),
197
+ response_id: modelResponseId,
105
198
  delta: part.inlineData.data,
106
199
  sampleRate: audioRate(part.inlineData.mimeType),
107
200
  })
108
201
  }
109
202
  }
110
203
 
111
- if (serverContent.inputTranscription?.text) {
112
- events.push({
113
- type: serverContent.turnComplete
114
- ? 'conversation.item.input_audio_transcription.completed'
115
- : 'conversation.item.input_audio_transcription.delta',
116
- transcript: serverContent.inputTranscription.text,
117
- delta: serverContent.inputTranscription.text,
118
- item_id: id('input'),
119
- })
120
- }
121
- if (serverContent.outputTranscription?.text) {
122
- events.push({
123
- type: serverContent.turnComplete
124
- ? 'response.audio_transcript.done'
125
- : 'response.audio_transcript.delta',
126
- response_id: responseId || ensureResponse(events),
127
- transcript: serverContent.outputTranscription.text,
128
- delta: serverContent.outputTranscription.text,
129
- })
204
+ const output = serverContent.outputTranscription
205
+ if (!interrupted && output && !outputTranscriptFinished) {
206
+ if (typeof output.text === 'string' && output.text) {
207
+ const responseId = ensureResponse(events)
208
+ outputTranscript += output.text
209
+ if (!serverContent.turnComplete) {
210
+ events.push({
211
+ type: 'response.audio_transcript.delta',
212
+ response_id: responseId,
213
+ delta: output.text,
214
+ })
215
+ }
216
+ }
217
+ outputTranscriptFinished = output.finished === true
130
218
  }
131
219
  // generationComplete can precede playback/turn completion. Keep the
132
220
  // response slot occupied until the service actually closes the turn.
@@ -136,7 +224,8 @@ export function createGoogleLiveProtocol() {
136
224
  }
137
225
 
138
226
  const calls = event?.toolCall?.functionCalls || []
139
- if (calls.length) {
227
+ if (calls.length && !interrupted) {
228
+ if (input?.activity !== 'speaking' && input?.finished !== false) finishInput(events)
140
229
  const responseId = ensureResponse(events)
141
230
  for (const call of calls) {
142
231
  const callId = String(call.id || id('call'))
@@ -162,6 +251,7 @@ export function createGoogleLiveProtocol() {
162
251
  })
163
252
  }
164
253
 
254
+ if (serverContent?.turnComplete) interrupted = false
165
255
  return events.length ? events : event
166
256
  },
167
257
 
@@ -1,3 +1,4 @@
1
+ import { providerRuntimeConfiguration } from './runtime-configuration.mjs'
1
2
  import { config } from '../../core/config.mjs'
2
3
  import {
3
4
  realtimeModelCatalog,
@@ -13,14 +14,16 @@ import {
13
14
  } from '../../frontend/frontend-tools.mjs'
14
15
  import { createGoogleLiveProtocol } from './google-live-protocol.mjs'
15
16
 
17
+ const connection = providerRuntimeConfiguration('google-live', { provider: 'google' })
18
+
16
19
  function modelProfile() {
17
- return resolveRealtimeModelProfile(config.googleLiveModel, 'google-live')
20
+ return resolveRealtimeModelProfile(connection.model, 'google', config.realtimeModelCatalogs)
18
21
  }
19
22
 
20
23
  function googleLiveUrl() {
21
- const url = new URL(config.googleLiveRealtimeUrl)
24
+ const url = new URL(connection.endpoint)
22
25
  if (!url.searchParams.has('key') && !url.searchParams.has('access_token')) {
23
- url.searchParams.set('key', config.googleApiKey)
26
+ url.searchParams.set('key', connection.credential)
24
27
  }
25
28
  return url.toString()
26
29
  }
@@ -29,10 +32,12 @@ function googleToolDeclarations(agentContext) {
29
32
  const declarations = frontendTools(agentContext)
30
33
  .map(tool => tool.function)
31
34
  .filter(tool => tool?.name)
35
+ // Gemini rejects JSON Schema keywords such as additionalProperties in
36
+ // `parameters` (OpenAPI subset); `parametersJsonSchema` takes them as-is.
32
37
  .map(tool => ({
33
38
  name: tool.name,
34
39
  ...(tool.description ? { description: tool.description } : {}),
35
- ...(tool.parameters ? { parameters: tool.parameters } : {}),
40
+ ...(tool.parameters ? { parametersJsonSchema: tool.parameters } : {}),
36
41
  }))
37
42
  return declarations.length ? [{ functionDeclarations: declarations }] : []
38
43
  }
@@ -54,7 +59,8 @@ function userTextItem(text) {
54
59
 
55
60
  export const googleLiveProvider = {
56
61
  key: 'google-live',
57
- label: 'Google Live',
62
+ provider: 'google',
63
+ label: 'Google',
58
64
  aliases: ['google', 'gemini-live', 'googlelive'],
59
65
  inputSampleRate: 16000,
60
66
  outputSampleRate: 24000,
@@ -69,12 +75,12 @@ export const googleLiveProvider = {
69
75
  mutableSession: false,
70
76
  },
71
77
 
72
- model: () => config.googleLiveModel,
78
+ model: () => connection.model,
73
79
  modelProfile,
74
- modelCatalog: () => realtimeModelCatalog('google-live').profiles,
75
- voice: () => config.googleLiveVoice || null,
76
- isConfigured: () => Boolean(config.googleApiKey),
77
- missingConfigurationMessage: '请先配置 GOOGLE_API_KEY 或 GEMINI_API_KEY',
80
+ modelCatalog: () => realtimeModelCatalog('google', config.realtimeModelCatalogs).profiles,
81
+ voice: () => String(connection.voice || '').trim() || modelProfile().sessionDefaults.voice,
82
+ isConfigured: () => connection.configured,
83
+ missingConfigurationMessage: '请先选择 google 并配置 QWEN_AUDIO_REALTIME_API_KEY',
78
84
  connectTimeoutMessage: '连接 Google Live 超时',
79
85
  url: googleLiveUrl,
80
86
  headers: () => ({}),
@@ -87,12 +93,12 @@ export const googleLiveProvider = {
87
93
  },
88
94
 
89
95
  buildSession: ({ agentContext, sessionOptions }) => {
90
- const voice = String(sessionOptions?.voice || config.googleLiveVoice || '').trim()
96
+ const voice = String(sessionOptions?.voice || '').trim() || googleLiveProvider.voice()
91
97
  const configuredSpeech = speechConfig(voice)
92
98
  return {
93
- model: config.googleLiveModel.startsWith('models/')
94
- ? config.googleLiveModel
95
- : `models/${config.googleLiveModel}`,
99
+ model: connection.model.startsWith('models/')
100
+ ? connection.model
101
+ : `models/${connection.model}`,
96
102
  generationConfig: {
97
103
  responseModalities: ['AUDIO'],
98
104
  ...(configuredSpeech ? { speechConfig: configuredSpeech } : {}),