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,4 +1,5 @@
1
1
  import { projectFrontendConversation } from './frontend-conversation-projection.mjs'
2
+ import { captureCoordinatorConversation } from '../core/work-conversation-context.mjs'
2
3
 
3
4
  function sessionKey(ownerId, sessionId) {
4
5
  return `${ownerId}\u0000${sessionId}`
@@ -88,6 +89,7 @@ export class ConversationSync {
88
89
  recorded: new Map(),
89
90
  recordSequence: 0,
90
91
  recordEpoch: 0,
92
+ historyPosition: 0,
91
93
  consumers: new WeakMap(),
92
94
  }
93
95
  this.sessions.set(key, state)
@@ -130,9 +132,13 @@ export class ConversationSync {
130
132
  inputs = [],
131
133
  citations = [],
132
134
  createdAt = null,
135
+ historyPosition = null,
136
+ final = true,
133
137
  }, { notify = true } = {}) {
134
138
  const normalized = clean(content)
135
- if (!id || !normalized) return null
139
+ // Runtime sources record final text only. Do not let an accidental partial
140
+ // create (or overwrite) a durable message or consume its history position.
141
+ if (final === false || !id || !normalized) return null
136
142
  const state = this.state(ownerId, sessionId)
137
143
  const existing = state.byId.get(id)
138
144
  if (existing) {
@@ -170,7 +176,14 @@ export class ConversationSync {
170
176
  ? { citations: citations.map(citation => ({ ...citation })) }
171
177
  : {}),
172
178
  createdAt: Number(createdAt) || Date.now(),
179
+ // Unlike seq, this watermark survives Session Journal restoration. Its
180
+ // clock origin keeps legacy history order; increments handle equal times
181
+ // and clock rollback. Updating the same final message keeps its position.
182
+ historyPosition: Number.isSafeInteger(historyPosition) && historyPosition > 0
183
+ ? historyPosition
184
+ : Math.max(state.historyPosition + 1, Number(createdAt) || Date.now()),
173
185
  }
186
+ state.historyPosition = Math.max(state.historyPosition, message.historyPosition)
174
187
  state.messages.push(message)
175
188
  state.byId.set(id, message)
176
189
  while (state.messages.length > this.maxMessages) {
@@ -240,10 +253,14 @@ export class ConversationSync {
240
253
  }
241
254
  }
242
255
 
243
- restore({ ownerId, sessionId, messages = [] }) {
256
+ restore({ ownerId, sessionId, messages = [], historyPosition = 0 }) {
244
257
  for (const message of messages) {
245
258
  this.upsert({ ownerId, sessionId, ...message }, { notify: false })
246
259
  }
260
+ if (Number.isSafeInteger(historyPosition) && historyPosition > 0) {
261
+ const state = this.state(ownerId, sessionId)
262
+ state.historyPosition = Math.max(state.historyPosition, historyPosition)
263
+ }
247
264
  return this.frontendContext({ ownerId, sessionId })
248
265
  }
249
266
 
@@ -278,6 +295,13 @@ export class ConversationSync {
278
295
  return projectFrontendConversation(messages)
279
296
  }
280
297
 
298
+ coordinatorSnapshot({ ownerId, sessionId, excludeTurnId, maxChars } = {}) {
299
+ this.prune()
300
+ return captureCoordinatorConversation(this.peek(ownerId, sessionId)?.messages || [], {
301
+ sessionId, excludeTurnId, maxChars,
302
+ })
303
+ }
304
+
281
305
  }
282
306
 
283
307
  export const conversationSync = new ConversationSync()
@@ -4,6 +4,7 @@ import { config } from '../core/config.mjs'
4
4
  import { recentConversationMessages } from '../../../shared/conversation-history.mjs'
5
5
 
6
6
  const PROMPT_FILE = 'PROMPT.md'
7
+ const LIVE_PROMPT_FILE = 'LIVE_PROMPT.md'
7
8
  const ASSISTANT_FILE = 'ASSISTANT.md'
8
9
  const MAX_PROMPT_CHARS = 16000
9
10
  const MAX_ASSISTANT_CHARS = 4000
@@ -62,14 +63,26 @@ export function currentTimeSnapshot({
62
63
  }
63
64
 
64
65
  export function loadFrontendPrompt() {
65
- const content = readFileSync(
66
- resolve(config.frontendPromptDir, PROMPT_FILE),
67
- 'utf8',
68
- ).trim()
69
- if (!content) throw new Error(`${PROMPT_FILE} must not be empty`)
66
+ return readPrompt(resolve(config.frontendPromptDir, PROMPT_FILE), PROMPT_FILE)
67
+ }
68
+
69
+ function readPrompt(path, filename) {
70
+ const content = readFileSync(path, 'utf8').trim()
71
+ if (!content) throw new Error(`${filename} must not be empty`)
70
72
  return [...content].slice(0, MAX_PROMPT_CHARS).join('')
71
73
  }
72
74
 
75
+ export function loadLiveFrontendPrompt() {
76
+ try {
77
+ return readPrompt(resolve(config.frontendPromptDir, LIVE_PROMPT_FILE), LIVE_PROMPT_FILE)
78
+ } catch (error) {
79
+ // Existing custom prompt directories may only contain the Realtime policy.
80
+ // Do not substitute that tool-specific policy for the Live policy.
81
+ if (error.code !== 'ENOENT') throw error
82
+ return readPrompt(resolve(config.root, 'config/frontend-agent', LIVE_PROMPT_FILE), LIVE_PROMPT_FILE)
83
+ }
84
+ }
85
+
73
86
  export function loadAssistantProfile() {
74
87
  const content = readFileSync(
75
88
  config.assistantProfilePath || resolve(config.frontendPromptDir, ASSISTANT_FILE),
@@ -183,7 +183,7 @@ export class FrontendNotesStore {
183
183
  Object.entries(lists).slice(0, MAX_LISTS_PER_OWNER).forEach(([key, entry]) => {
184
184
  const safeKey = clean(key, MAX_LIST_NAME_CHARS).toLocaleLowerCase()
185
185
  const name = clean(entry?.name, MAX_LIST_NAME_CHARS)
186
- if (!safeKey || !name) return
186
+ if (!safeKey || !name || !Array.isArray(entry?.items)) return
187
187
  const items = []
188
188
  const seen = new Set()
189
189
  for (const item of (Array.isArray(entry?.items) ? entry.items : []).slice(0, MAX_ITEMS_PER_LIST)) {
@@ -197,14 +197,16 @@ export class FrontendNotesStore {
197
197
  addedAt: Number(item?.addedAt) || 0,
198
198
  })
199
199
  }
200
- if (!items.length) return
201
200
  normalized.set(safeKey, {
202
201
  name,
203
202
  items,
204
203
  createdAt: Number(entry?.createdAt) || this.now(),
205
- updatedAt: Math.max(
206
- ...items.map(item => item.addedAt || 0),
207
- ) || this.now(),
204
+ updatedAt: Number.isFinite(entry?.updatedAt)
205
+ ? entry.updatedAt
206
+ : Math.max(
207
+ Number.isFinite(entry?.createdAt) ? entry.createdAt : 0,
208
+ ...items.map(item => Number.isFinite(item.addedAt) ? item.addedAt : 0),
209
+ ),
208
210
  })
209
211
  })
210
212
  if (normalized.size) {
@@ -8,7 +8,7 @@ export function recordTaskResult({
8
8
  return conversationSync.record({
9
9
  ownerId,
10
10
  sessionId,
11
- id: `agent:${task.id}`,
11
+ id: `agent:${task.id}${task.revision ? `:${task.revision}` : ''}`,
12
12
  role: 'assistant',
13
13
  content: task.status === 'completed' ? task.result : task.error,
14
14
  source: 'agent-result',
@@ -13,6 +13,10 @@ export const BackendEventType = Object.freeze({
13
13
  AUTHORIZATION_RESOLVED: 'backend.permission.resolved',
14
14
  INPUT_REQUESTED: 'backend.input.requested',
15
15
  INPUT_RESOLVED: 'backend.input.resolved',
16
+ // Optional top-level `yielded: true` asserts that the initial execution has
17
+ // already released its capacity. The Task remains live; adapters must still
18
+ // await delegated work and serialize any later coordinator turns themselves.
19
+ // Unmarked delegation retains normal Task concurrency limits.
16
20
  DELEGATED: 'backend.delegated',
17
21
  DELEGATION_COMPLETED: 'backend.delegation.completed',
18
22
  })
@@ -1,5 +1,11 @@
1
+ // A budget is measured in UTF-16 code units, but never split a surrogate pair.
2
+ function cut(value, maxLength) {
3
+ const prefix = value.slice(0, maxLength)
4
+ return /[\uD800-\uDBFF]$/.test(prefix) ? prefix.slice(0, -1) : prefix
5
+ }
6
+
1
7
  function cleanText(value, maxLength) {
2
- return String(value || '').replace(/\s+/g, ' ').trim().slice(0, maxLength)
8
+ return cut(String(value || '').replace(/\s+/g, ' ').trim(), maxLength)
3
9
  }
4
10
 
5
11
  export function normalizePublicUrl(value) {
@@ -72,7 +78,7 @@ export function normalizeSearchResponse(response, { query, limit = 5 } = {}) {
72
78
  : {}),
73
79
  })
74
80
  }
75
- const summary = String(response?.summary || '').trim().slice(0, 8000)
81
+ const summary = cut(String(response?.summary || '').trim(), 8000)
76
82
  return {
77
83
  status: 'ok',
78
84
  query: cleanText(query, 500),
@@ -14,11 +14,6 @@ import {
14
14
  import {
15
15
  resolveRealtimeFrontendConfiguration,
16
16
  } from '../../../shared/realtime-provider-catalog.mjs'
17
- import {
18
- REALTIME_PROVIDERS,
19
- realtimeSettingsFromEnvironment,
20
- realtimeSettingsConnection,
21
- } from '../../../shared/realtime-provider-definitions.mjs'
22
17
  import {
23
18
  normalizeMemoryProviderSelection,
24
19
  } from '../../../shared/memory-provider-catalog.mjs'
@@ -67,6 +62,21 @@ export function resolveDisabledFrontendTools(env = process.env) {
67
62
  ]
68
63
  }
69
64
 
65
+ // GPT-Live 1 timing overrides in milliseconds; a key left unset keeps the
66
+ // adapter's default. The floor keeps an idle timer from never ending a turn.
67
+ const GPT_LIVE_1_TIMING_SETTINGS = Object.freeze({
68
+ outputIdleMs: 'GPT_LIVE_1_OUTPUT_IDLE_MS',
69
+ wordGapMs: 'GPT_LIVE_1_WORD_GAP_MS',
70
+ inputSegmentGapMs: 'GPT_LIVE_1_INPUT_SEGMENT_GAP_MS',
71
+ inputIdleMs: 'GPT_LIVE_1_INPUT_IDLE_MS',
72
+ })
73
+
74
+ export function resolveGptLive1Timing(env = process.env) {
75
+ return Object.fromEntries(Object.entries(GPT_LIVE_1_TIMING_SETTINGS)
76
+ .map(([key, name]) => [key, numberSetting(env[name], undefined, { min: 100, max: 10_000 })])
77
+ .filter(([, value]) => value !== undefined))
78
+ }
79
+
70
80
  export function resolveBackendWorkspace(
71
81
  protocol,
72
82
  env = process.env,
@@ -134,7 +144,16 @@ export function resolveBackendModels(env = process.env) {
134
144
  pi: common,
135
145
  muse: common,
136
146
  acp: common,
147
+ llm: common,
148
+ }
149
+ }
150
+
151
+ function defaultLlmBaseUrl(env = process.env) {
152
+ if (String(env.OPENAI_API_KEY || '').trim()
153
+ && !String(env.DASHSCOPE_API_KEY || '').trim()) {
154
+ return 'https://api.openai.com/v1'
137
155
  }
156
+ return 'https://dashscope.aliyuncs.com/compatible-mode/v1'
138
157
  }
139
158
 
140
159
  const configuredAgentProtocol = normalizeBackendProtocol(
@@ -225,12 +244,6 @@ const frontendProfileConfiguration = resolveFrontendProfileConfiguration({
225
244
  baseDirectory: root,
226
245
  })
227
246
 
228
- const realtimeSettings = realtimeSettingsFromEnvironment(process.env)
229
- const realtimeConnections = Object.fromEntries(REALTIME_PROVIDERS.map(provider => [
230
- provider.key,
231
- realtimeSettingsConnection({ ...realtimeSettings, realtimeProvider: provider.key }),
232
- ]))
233
-
234
247
  export const config = {
235
248
  root,
236
249
  configDirectory: runtimeEnvironment.configDirectory,
@@ -248,47 +261,13 @@ export const config = {
248
261
  ? 0
249
262
  : numberSetting(process.env.PORT, 3101, { min: 1, max: 65535 }),
250
263
  audioProvider: realtimeFrontend.active.provider,
264
+ realtimeModelCatalogs: realtimeFrontend.modelCatalogs,
251
265
  realtimeConfigSignature: realtimeFrontend.active.signature,
252
266
  realtimeCredential: realtimeFrontend.credential,
253
267
  realtimeEndpoint: realtimeFrontend.active.endpoint,
254
268
  realtimeModel: realtimeFrontend.active.model,
255
269
  realtimeVoice: realtimeFrontend.active.voice,
256
- // User-managed huggingface/speech-to-speech OpenAI Realtime endpoint. The
257
- // pipeline owns its STT, LLM, TTS and voice configuration; Gateway only
258
- // connects to the endpoint and supplies the shared frontend instructions and
259
- // tools for each realtime Session.
260
- speechToSpeechRealtimeUrl: realtimeConnections['speech-to-speech'].endpoint,
261
- // Do not advertise a local service merely because a default endpoint
262
- // exists. It becomes selectable when the user explicitly configures it or
263
- // chooses it as the active frontend.
264
- speechToSpeechConfigured: Boolean(realtimeSettings.speechToSpeechRealtimeUrl) || realtimeFrontend.active.provider === 'speech-to-speech',
265
- // The upstream WebSocket does not require authentication. This optional
266
- // credential is useful only when users put it behind an authenticated proxy.
267
- speechToSpeechAuthToken: realtimeConnections['speech-to-speech'].credential,
268
- // User-managed MiniCPM-o 4.5 audio full-duplex Realtime endpoint.
269
- miniCpmORealtimeUrl: realtimeConnections['minicpm-o'].endpoint,
270
- miniCpmOAuthToken: realtimeConnections['minicpm-o'].credential,
271
- miniCpmOConfigured: Boolean(realtimeSettings.miniCpmORealtimeUrl) || realtimeFrontend.active.provider === 'minicpm-o',
272
- audioModel: realtimeConnections['dashscope'].model,
273
- audioVoice: realtimeConnections['dashscope'].voice,
274
- dashscopeApiKey: realtimeConnections['dashscope'].credential,
275
- audioRealtimeBaseUrl: realtimeConnections['dashscope'].endpoint,
276
- stepfunApiKey: realtimeConnections['stepfun'].credential,
277
- stepfunRealtimeUrl: realtimeConnections['stepfun'].endpoint,
278
- stepfunModel: realtimeConnections['stepfun'].model,
279
- stepfunVoice: realtimeConnections['stepfun'].voice,
280
- openaiApiKey: realtimeConnections['gpt-live'].credential,
281
- gptLiveRealtimeUrl: realtimeConnections['gpt-live'].endpoint,
282
- gptLiveModel: realtimeConnections['gpt-live'].model,
283
- gptLiveVoice: realtimeConnections['gpt-live'].voice,
284
- googleApiKey: realtimeConnections['google-live'].credential,
285
- googleLiveRealtimeUrl: realtimeConnections['google-live'].endpoint,
286
- googleLiveModel: realtimeConnections['google-live'].model,
287
- googleLiveVoice: realtimeConnections['google-live'].voice,
288
- doubaoApiKey: realtimeConnections['doubao-seeduplex'].credential,
289
- doubaoSeeduplexRealtimeUrl: realtimeConnections['doubao-seeduplex'].endpoint,
290
- doubaoSeeduplexModel: realtimeConnections['doubao-seeduplex'].model,
291
- doubaoSeeduplexVoice: realtimeConnections['doubao-seeduplex'].voice,
270
+ gptLive1Timing: resolveGptLive1Timing(),
292
271
  webSearchProvider: webSearch.provider,
293
272
  webSearchMcpUrl: webSearch.mcpUrl,
294
273
  webSearchMcpToken: webSearch.mcpToken,
@@ -464,6 +443,24 @@ export const config = {
464
443
  label: String(process.env.ACP_LABEL || 'ACP Agent').trim() || 'ACP Agent',
465
444
  coordinatorAgent: String(process.env.ACP_COORDINATOR_AGENT || '').trim(),
466
445
  },
446
+ llm: {
447
+ model: String(backendModels.llm).trim(),
448
+ baseUrl: String(
449
+ process.env.QWEN_AUDIO_AGENT_LLM_BASE_URL
450
+ || process.env.OPENAI_BASE_URL
451
+ || process.env.DASHSCOPE_BASE_URL
452
+ || defaultLlmBaseUrl(),
453
+ ).trim().replace(/\/+$/, ''),
454
+ apiKey: String(
455
+ process.env.QWEN_AUDIO_AGENT_LLM_API_KEY
456
+ || process.env.DASHSCOPE_API_KEY
457
+ || process.env.OPENAI_API_KEY
458
+ || '',
459
+ ).trim(),
460
+ systemPrompt: String(
461
+ process.env.QWEN_AUDIO_AGENT_LLM_SYSTEM_PROMPT || '',
462
+ ).trim(),
463
+ },
467
464
  },
468
465
  announceIntoContext: (
469
466
  String(process.env.QWEN_AUDIO_AGENT_ANNOUNCE_INTO_CONTEXT || 'true').toLowerCase()
@@ -544,12 +541,12 @@ export const config = {
544
541
  ),
545
542
  taskMaxConcurrent: numberSetting(
546
543
  process.env.QWEN_AUDIO_AGENT_TASK_MAX_CONCURRENT,
547
- 4,
544
+ 1,
548
545
  { min: 1, max: 64 },
549
546
  ),
550
547
  taskMaxConcurrentPerOwner: numberSetting(
551
548
  process.env.QWEN_AUDIO_AGENT_TASK_MAX_CONCURRENT_PER_OWNER,
552
- 2,
549
+ 1,
553
550
  { min: 1, max: 16 },
554
551
  ),
555
552
  conversationSessionTtlMs: numberSetting(
@@ -659,8 +656,3 @@ export const config = {
659
656
  { min: 0, max: 86_400 },
660
657
  ) * 1000,
661
658
  }
662
-
663
- export function realtimeUrl(baseUrl, model) {
664
- const separator = baseUrl.includes('?') ? '&' : '?'
665
- return `${baseUrl}${separator}model=${encodeURIComponent(model)}`
666
- }
@@ -10,6 +10,7 @@
10
10
  // Every capability listed here is locked by a test (see docs/contract.md);
11
11
  // anything not listed is internal and may change in any release.
12
12
  //
13
+ // 5.10.0 adds authenticated, owner-scoped client input state in /api/health.
13
14
  // 5.9.0 adds host-issued direct WSS device connection codes. Conversation
14
15
  // Clients authenticate and run on one WS/WSS connection; the loopback HTTP
15
16
  // management plane remains available to the Gateway operator.
@@ -50,7 +51,7 @@
50
51
  // desktop.settings-window, …) are not part of this contract, and a removed
51
52
  // capability is a breaking change. Hosts migrating from the fork must branch
52
53
  // on the capability list below, never on the version number.
53
- export const GATEWAY_PROTOCOL_VERSION = '5.9.0'
54
+ export const GATEWAY_PROTOCOL_VERSION = '5.10.0'
54
55
 
55
56
  export const GATEWAY_CAPABILITIES = Object.freeze([
56
57
  // The Gateway statically hosts web/dist at its own origin, so a client may
@@ -90,6 +91,8 @@ export const GATEWAY_CAPABILITIES = Object.freeze([
90
91
  // POST /api/input/suspend|resume, GET /api/input; the Gateway relays the
91
92
  // suspension to clients through input.suspend/input.resume.
92
93
  'input.suspend-protocol',
94
+ // /api/health reports accepted client input separately from host suspension.
95
+ 'input.client-status',
93
96
  // input.suspend also clears playback so host recording stays clean.
94
97
  'input.suspend-clears-playback',
95
98
  // A suspension expires on its own when the holder never sends resume.
@@ -2,10 +2,16 @@ import { config } from './config.mjs'
2
2
  import { isIP } from 'node:net'
3
3
 
4
4
  const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]', '::1'])
5
- const TRUSTED_NATIVE_CLIENT_ORIGINS = new Set(['https://qwaudio.local'])
5
+ const TRUSTED_NATIVE_CLIENT_ORIGINS = new Set([
6
+ 'https://qwaudio.local',
7
+ 'capacitor://qwaudio.local',
8
+ ])
6
9
 
7
10
  function normalizedOrigin(value) {
8
11
  if (typeof value !== 'string' || !value.trim()) return ''
12
+ // WKWebView uses a custom scheme for bundled iOS resources. Recognize only
13
+ // the fixed native app origins; arbitrary opaque origins remain invalid.
14
+ if (TRUSTED_NATIVE_CLIENT_ORIGINS.has(value.trim())) return value.trim()
9
15
  try {
10
16
  const url = new URL(value)
11
17
  return ['http:', 'https:'].includes(url.protocol) ? url.origin : ''
@@ -0,0 +1,138 @@
1
+ /** Pure BackendPort conversation DTO helpers; no history store dependencies. */
2
+ export const COORDINATOR_CONVERSATION_MAX_CHARS = 2_000
3
+
4
+ const SOURCES_BY_ROLE = {
5
+ user: new Set(['voice-user', 'text-user']),
6
+ assistant: new Set(['realtime-direct', 'agent-presentation']),
7
+ }
8
+
9
+ function position(value) {
10
+ return Number.isSafeInteger(value) && value > 0 ? value : 0
11
+ }
12
+
13
+ function budget(value) {
14
+ return Number.isSafeInteger(value) && value >= 0
15
+ ? Math.min(value, COORDINATOR_CONVERSATION_MAX_CHARS)
16
+ : COORDINATOR_CONVERSATION_MAX_CHARS
17
+ }
18
+
19
+ function line(message) {
20
+ return `${message.role === 'user' ? 'User' : 'Assistant'}: ${message.content}`
21
+ }
22
+
23
+ function truncate(value, limit) {
24
+ if (value.length <= limit) return value
25
+ if (limit < 1) return ''
26
+ let prefix = value.slice(0, limit - 1)
27
+ // A budget is measured in UTF-16 code units, but never split a surrogate pair.
28
+ if (/[\uD800-\uDBFF]$/.test(prefix)) prefix = prefix.slice(0, -1)
29
+ return `${prefix}…`
30
+ }
31
+
32
+ function recentMessages(messages, maxChars) {
33
+ const selected = []
34
+ let used = 0
35
+ let truncated = false
36
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
37
+ const message = messages[index]
38
+ const size = line(message).length + (selected.length ? 1 : 0)
39
+ if (used + size > maxChars) {
40
+ truncated = true
41
+ // Preserve a contiguous suffix of whole messages. Only a single newest
42
+ // overlong message is shortened; never replace newer context with older.
43
+ if (!selected.length) {
44
+ const contentBudget = maxChars - line({ ...message, content: '' }).length
45
+ if (contentBudget > 0) {
46
+ selected.push({ ...message, content: truncate(message.content, contentBudget) })
47
+ }
48
+ }
49
+ break
50
+ }
51
+ selected.push({ ...message })
52
+ used += size
53
+ }
54
+ return { messages: selected.reverse(), truncated }
55
+ }
56
+
57
+ /**
58
+ * Capture at Task admission, not when the backend eventually runs. Reuses the
59
+ * existing history and copies at most one bounded text window, never a second
60
+ * conversation store. The snapshot is JSON-serializable with the accepted work.
61
+ *
62
+ * ConversationSync records these sources only on final user input / natural
63
+ * assistant presentation. Raw agent-result, tool events and partial text are
64
+ * deliberately not eligible, including raw results not yet presented aloud.
65
+ */
66
+ export function captureCoordinatorConversation(messages = [], {
67
+ sessionId,
68
+ excludeTurnId,
69
+ maxChars = COORDINATOR_CONVERSATION_MAX_CHARS,
70
+ } = {}) {
71
+ const scope = String(sessionId || '')
72
+ if (!scope) throw new TypeError('conversation sessionId is required')
73
+ const limit = budget(maxChars)
74
+ const ordered = messages.filter(message => (
75
+ position(message.historyPosition)
76
+ && SOURCES_BY_ROLE[message.role]?.has(message.source)
77
+ && message.final !== false
78
+ && message.id
79
+ && String(message.content || '').trim()
80
+ )).sort((left, right) => left.historyPosition - right.historyPosition)
81
+ const last = ordered.at(-1)
82
+ const eligible = ordered.filter(message => (
83
+ !(message.role === 'user' && excludeTurnId && message.turnId === excludeTurnId)
84
+ )).map(message => ({
85
+ id: String(message.id),
86
+ role: message.role,
87
+ content: String(message.content),
88
+ position: message.historyPosition,
89
+ }))
90
+ const selected = recentMessages(eligible, limit)
91
+ return {
92
+ version: 1,
93
+ sessionId: scope,
94
+ maxChars: limit,
95
+ firstPosition: ordered[0]?.historyPosition || 0,
96
+ messages: selected.messages,
97
+ truncated: selected.truncated,
98
+ // The current input is already conveyed by the task objective. Include its
99
+ // position in the watermark even though its text is excluded above.
100
+ cursor: {
101
+ sessionId: scope,
102
+ messageId: last ? String(last.id) : null,
103
+ position: last?.historyPosition || 0,
104
+ },
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Resolve at actual delivery against the last ACKNOWLEDGED durable cursor.
110
+ * Never persist the returned cursor until its prompt was accepted; retries can
111
+ * reuse the immutable admission snapshot without reading any later dialogue.
112
+ */
113
+ export function conversationDelta(snapshot, acknowledgedCursor = null) {
114
+ if (snapshot?.version !== 1 || !snapshot.sessionId || !Array.isArray(snapshot.messages)) {
115
+ throw new TypeError('a coordinator conversation snapshot is required')
116
+ }
117
+ const sameSession = acknowledgedCursor?.sessionId === snapshot.sessionId
118
+ const after = sameSession ? position(acknowledgedCursor.position) : 0
119
+ const through = position(snapshot.cursor?.position)
120
+ if (sameSession && after >= through) {
121
+ return {
122
+ text: '', messages: [], cursor: { ...acknowledgedCursor },
123
+ truncated: false, gap: false, stale: true,
124
+ }
125
+ }
126
+ const selected = recentMessages(
127
+ snapshot.messages.filter(message => message.position > after && message.position <= through),
128
+ budget(snapshot.maxChars),
129
+ )
130
+ return {
131
+ text: selected.messages.map(line).join('\n'),
132
+ messages: selected.messages,
133
+ cursor: { ...snapshot.cursor },
134
+ truncated: snapshot.truncated || selected.truncated,
135
+ gap: Boolean(after && snapshot.firstPosition > after),
136
+ stale: false,
137
+ }
138
+ }
@@ -1,5 +1,6 @@
1
1
  export const InputRequestStatus = Object.freeze({
2
2
  PENDING: 'pending',
3
+ ANSWERED: 'answered',
3
4
  ACCEPTED: 'accepted',
4
5
  DECLINED: 'declined',
5
6
  CANCELLED: 'cancelled',
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  buildFrontendContext,
3
3
  loadFrontendPrompt,
4
+ loadLiveFrontendPrompt,
4
5
  resolveAssistantProfile,
5
6
  } from '../conversation/frontend-agent-context.mjs'
6
7
  import { FrontendToolRegistry } from './tools/frontend-tool-registry.mjs'
@@ -11,13 +12,12 @@ import {
11
12
  } from './tools/spawn-thinking-tool.mjs'
12
13
  import {
13
14
  agentTaskToolEntries,
14
- BACKEND_INPUT_RESPONSE_CAPABILITY,
15
15
  CANCEL_AGENT_TASK_TOOL_NAME,
16
16
  GET_AGENT_TASK_STATUS_TOOL_NAME,
17
17
  PERMISSION_RESPONSE_CAPABILITY,
18
- RESPOND_AGENT_INPUT_TOOL_NAME,
19
18
  RESPOND_PERMISSION_TOOL_NAME,
20
19
  SPAWN_THINKING_TOOL_NAME,
20
+ UPDATE_AGENT_TASK_TOOL_NAME,
21
21
  } from './tools/features/agent-task-tools.mjs'
22
22
  import {
23
23
  coreToolEntries,
@@ -41,7 +41,6 @@ import {
41
41
  } from './tools/features/schedule-tools.mjs'
42
42
 
43
43
  export {
44
- BACKEND_INPUT_RESPONSE_CAPABILITY,
45
44
  CANCEL_AGENT_TASK_TOOL_NAME,
46
45
  FETCH_URL_TOOL_NAME,
47
46
  FRONTEND_RECALL_CAPABILITY,
@@ -50,10 +49,10 @@ export {
50
49
  NOTES_TOOL_NAME,
51
50
  PERMISSION_RESPONSE_CAPABILITY,
52
51
  RECALL_TOOL_NAME,
53
- RESPOND_AGENT_INPUT_TOOL_NAME,
54
52
  RESPOND_PERMISSION_TOOL_NAME,
55
53
  SCHEDULE_REMINDER_TOOL_NAME,
56
54
  SPAWN_THINKING_TOOL_NAME,
55
+ UPDATE_AGENT_TASK_TOOL_NAME,
57
56
  WEB_SEARCH_TOOL_NAME,
58
57
  }
59
58
 
@@ -71,6 +70,7 @@ const entriesByName = new Map(featureEntries.map(entry => [
71
70
  ]))
72
71
  const toolOrder = [
73
72
  SPAWN_THINKING_TOOL_NAME,
73
+ UPDATE_AGENT_TASK_TOOL_NAME,
74
74
  SCHEDULE_REMINDER_TOOL_NAME,
75
75
  CANCEL_AGENT_TASK_TOOL_NAME,
76
76
  GET_AGENT_TASK_STATUS_TOOL_NAME,
@@ -78,7 +78,6 @@ const toolOrder = [
78
78
  NOTES_TOOL_NAME,
79
79
  RECALL_TOOL_NAME,
80
80
  RESPOND_PERMISSION_TOOL_NAME,
81
- RESPOND_AGENT_INPUT_TOOL_NAME,
82
81
  WEB_SEARCH_TOOL_NAME,
83
82
  FETCH_URL_TOOL_NAME,
84
83
  ...optionalFrontendFeatures.flatMap(feature => (
@@ -157,17 +156,31 @@ export const permissionResponseInstructions = [
157
156
  export const inputRequestResponseInstructions = [
158
157
  '这是同一项后台工作为继续执行而提出的补充问题,不是最终结果,也不是新任务。',
159
158
  '自然、简短地转达问题并等待用户回答;不要调用 spawn_thinking。',
160
- '用户回答后调用 respond_agent_input,把回答交回同一项工作。',
159
+ '用户回答后调用 update_agent_task,把 instruction 和 input_request_id 交回同一项工作。',
161
160
  '不要朗读协议字段或工作 ID,也不要把等待输入说成工作已经完成。',
162
161
  '问题的收件人是用户,不是你;不要用第一人称代用户回答或批准。收到请求本身不是用户的同意,必须等待用户下一次真实答复。',
162
+ '若内容是授权预览,只转述本次拟执行操作及预览明确披露的影响,然后询问是否批准并停止输出。不要在前面声称本次或后续操作已经提交、处理中或完成,不要附加示例回答,更不能生成“我同意”之类的用户话语。',
163
+ '忠实转达用户的确认、拒绝或修改要求,由后台结合原问题处理;回答送达不代表操作已批准或执行完成。',
163
164
  ].join(' ')
164
165
 
165
166
  export function buildFrontendInstructions(agentContext = {}) {
166
- return [
167
+ return composeFrontendInstructions(agentContext, [
167
168
  loadFrontendPrompt(),
168
169
  ...optionalFrontendFeatures.filter(feature => feature.entries.some(entry => (
169
170
  frontendToolRegistry.isEnabled(entry.definition.function.name, agentContext)
170
171
  ))).map(feature => feature.instructions).filter(Boolean),
172
+ ])
173
+ }
174
+
175
+ export function buildLiveFrontendInstructions(agentContext = {}) {
176
+ // Native delegation has no frontend function tools. Context remains shared,
177
+ // but rules for calling those tools must not enter the Live instructions.
178
+ return composeFrontendInstructions(agentContext, [loadLiveFrontendPrompt()])
179
+ }
180
+
181
+ function composeFrontendInstructions(agentContext, instructions) {
182
+ return [
183
+ ...instructions,
171
184
  '# Assistant Profile',
172
185
  '<assistant_profile authority="persona_only">',
173
186
  resolveAssistantProfile(agentContext),
@@ -24,19 +24,30 @@ function decodedCodePoint(value, radix) {
24
24
  return String.fromCodePoint(codePoint)
25
25
  }
26
26
 
27
+ const NAMED_ENTITIES = {
28
+ amp: '&',
29
+ lt: '<',
30
+ gt: '>',
31
+ quot: '"',
32
+ apos: "'",
33
+ nbsp: ' ',
34
+ ensp: ' ',
35
+ emsp: ' ',
36
+ middot: '·',
37
+ }
38
+
39
+ // Decode in a single pass so text produced by one entity is never decoded
40
+ // again: `&amp;lt;` is the literal text `&lt;`, not `<`.
27
41
  function decodeEntities(value) {
28
- return String(value || '')
29
- .replace(/&amp;/giu, '&')
30
- .replace(/&lt;/giu, '<')
31
- .replace(/&gt;/giu, '>')
32
- .replace(/&quot;/giu, '"')
33
- .replace(/&(?:apos|#(?:39|x27));/giu, "'")
34
- .replace(/&nbsp;/giu, ' ')
35
- .replace(/&ensp;/giu, ' ')
36
- .replace(/&emsp;/giu, ' ')
37
- .replace(/&middot;/giu, '·')
38
- .replace(/&#(\d+);/gu, (_, code) => decodedCodePoint(code, 10))
39
- .replace(/&#x([0-9a-f]+);/giu, (_, code) => decodedCodePoint(code, 16))
42
+ return String(value || '').replace(
43
+ /&(?:#(\d+)|#x([0-9a-f]+)|([a-z]+));/giu,
44
+ (entity, decimal, hex, name) => {
45
+ if (decimal !== undefined) return decodedCodePoint(decimal, 10)
46
+ if (hex !== undefined) return decodedCodePoint(hex, 16)
47
+ const key = name.toLowerCase()
48
+ return Object.hasOwn(NAMED_ENTITIES, key) ? NAMED_ENTITIES[key] : entity
49
+ },
50
+ )
40
51
  }
41
52
 
42
53
  function plainText(value) {