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.
- package/README.md +21 -10
- package/README_ZH.md +19 -10
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/cli/package.json +1 -1
- package/cli/src/arguments.mjs +4 -1
- package/cli/src/config-command.mjs +36 -6
- package/cli/src/gateway-service.mjs +7 -1
- package/cli/src/launcher.mjs +13 -0
- package/config/frontend-agent/LIVE_PROMPT.md +64 -0
- package/config/frontend-agent/PROMPT.md +29 -26
- package/desktop/src/i18n.mjs +6 -1
- package/desktop/src/settings-config.mjs +32 -40
- package/desktop/src/settings-store.mjs +19 -28
- package/docs/architecture/deep-dive.md +103 -66
- package/docs/architecture/deep-dive.zh.md +73 -50
- package/docs/backends/configuration.md +4 -4
- package/docs/backends/configuration.zh.md +4 -4
- package/docs/backends/overview.md +3 -0
- package/docs/backends/overview.zh.md +3 -0
- package/docs/configuration/backend.md +15 -1
- package/docs/configuration/backend.zh.md +15 -1
- package/docs/configuration/frontend.md +78 -28
- package/docs/configuration/frontend.zh.md +76 -28
- package/docs/configuration.md +1 -1
- package/docs/configuration.zh.md +1 -1
- package/docs/contract.md +24 -2
- package/docs/contract.zh.md +20 -2
- package/docs/extensions.md +14 -0
- package/docs/extensions.zh.md +11 -0
- package/docs/gateway-protocol.md +26 -0
- package/docs/gateway-protocol.zh.md +22 -0
- package/docs/gateway-webrtc-client.md +3 -3
- package/docs/gateway-webrtc-client.zh.md +3 -3
- package/docs/getting-started/install.md +4 -1
- package/docs/getting-started/install.zh.md +4 -1
- package/docs/getting-started/mobile.md +8 -2
- package/docs/getting-started/mobile.zh.md +5 -0
- package/docs/getting-started/quickstart.md +2 -2
- package/docs/getting-started/quickstart.zh.md +2 -2
- package/docs/getting-started/webui.md +2 -0
- package/docs/getting-started/webui.zh.md +2 -0
- package/docs/guides/knowledge.md +8 -5
- package/docs/guides/knowledge.zh.md +4 -3
- package/docs/guides/tasks.md +63 -2
- package/docs/guides/tasks.zh.md +45 -1
- package/docs/guides/web-search.md +32 -1
- package/docs/guides/web-search.zh.md +28 -1
- package/docs/operations/troubleshooting.md +30 -0
- package/docs/operations/troubleshooting.zh.md +26 -0
- package/docs/reference/backend-adapter-sdk.md +33 -2
- package/docs/reference/backend-adapter-sdk.zh.md +29 -2
- package/docs/reference/cli.md +3 -3
- package/docs/reference/cli.zh.md +3 -3
- package/docs/scenarios/lightrag.md +2 -2
- package/docs/scenarios/lightrag.zh.md +2 -2
- package/docs/scenarios/x-omni.md +5 -2
- package/docs/scenarios/x-omni.zh.md +5 -2
- package/docs/voice-agent-architecture-presentation.zh.md +34 -37
- package/docs/voice-frontends/custom-provider.md +22 -4
- package/docs/voice-frontends/custom-provider.zh.md +22 -4
- package/docs/voice-frontends/google-live.md +14 -8
- package/docs/voice-frontends/google-live.zh.md +13 -8
- package/docs/voice-frontends/gpt-live-1.md +149 -0
- package/docs/voice-frontends/gpt-live-1.zh.md +114 -0
- package/docs/voice-frontends/minicpm-o.md +8 -4
- package/docs/voice-frontends/minicpm-o.zh.md +7 -4
- package/docs/voice-frontends/{gpt-live.md → openai-realtime.md} +19 -10
- package/docs/voice-frontends/{gpt-live.zh.md → openai-realtime.zh.md} +18 -10
- package/docs/voice-frontends/qwen-audio-live.md +164 -0
- package/docs/voice-frontends/qwen-audio-live.zh.md +122 -0
- package/docs/voice-frontends/qwen-audio-realtime.md +41 -15
- package/docs/voice-frontends/qwen-audio-realtime.zh.md +34 -12
- package/docs/voice-frontends/qwen-omni-realtime.md +12 -9
- package/docs/voice-frontends/qwen-omni-realtime.zh.md +12 -9
- package/docs/voice-frontends/speech-to-speech.md +8 -4
- package/docs/voice-frontends/speech-to-speech.zh.md +7 -3
- package/docs/voice-frontends/stepfun.md +7 -4
- package/docs/voice-frontends/stepfun.zh.md +7 -4
- package/examples/webrtc/start.mjs +2 -1
- package/package.json +34 -16
- package/scripts/audit-dependencies.mjs +3 -25
- package/scripts/electron-smoke.mjs +5 -5
- package/scripts/patch-build-node-gyp.mjs +63 -0
- package/scripts/prepare-build.mjs +2 -0
- package/scripts/release-check +2 -2
- package/scripts/runtime/claude-code-acp.mjs +5 -5
- package/scripts/verify-package.mjs +3 -0
- package/server/package.json +5 -5
- package/server/src/app/gateway-application.mjs +3 -0
- package/server/src/app/gateway-http-routes.mjs +3 -0
- package/server/src/app/session-conversation-history.mjs +9 -1
- package/server/src/backend/adapters/a2a/backend-adapter.mjs +32 -26
- package/server/src/backend/adapters/acp/backend-adapter.mjs +703 -251
- package/server/src/backend/adapters/acp/coordinator-contract.mjs +2 -13
- package/server/src/backend/adapters/acp/coordinator-instructions.mjs +29 -8
- package/server/src/backend/adapters/acp/coordinator-queue.mjs +58 -0
- package/server/src/backend/adapters/acp/drivers/codex.mjs +1 -1
- package/server/src/backend/adapters/acp/drivers/openclaw.mjs +1 -2
- package/server/src/backend/adapters/acp/input-broker.mjs +2 -0
- package/server/src/backend/adapters/acp/process-client.mjs +111 -16
- package/server/src/backend/adapters/acp/session-configuration.mjs +2 -19
- package/server/src/backend/adapters/acp/session-registry.mjs +9 -0
- package/server/src/backend/adapters/acp/session-tools.mjs +1 -1
- package/server/src/backend/adapters/acp/turn-updates.mjs +188 -0
- package/server/src/backend/adapters/acp/work-continuation.mjs +48 -0
- package/server/src/backend/adapters/agent-client.mjs +24 -1
- package/server/src/backend/adapters/llm/backend-adapter.mjs +393 -0
- package/server/src/backend/adapters/muse/backend-adapter.mjs +2 -0
- package/server/src/backend/availability.mjs +12 -3
- package/server/src/backend/backend-adapter-sdk.mjs +3 -0
- package/server/src/backend/backend-port.mjs +13 -0
- package/server/src/backend/backend-work-runtime.mjs +23 -0
- package/server/src/client/client-command-runtime.mjs +14 -0
- package/server/src/conversation/conversation-sync.mjs +26 -2
- package/server/src/conversation/frontend-agent-context.mjs +18 -5
- package/server/src/conversation/frontend-notes.mjs +7 -5
- package/server/src/conversation/task-result-projector.mjs +1 -1
- package/server/src/core/backend-events.mjs +4 -0
- package/server/src/core/citation.mjs +8 -2
- package/server/src/core/config.mjs +46 -54
- package/server/src/core/gateway-protocol.mjs +4 -1
- package/server/src/core/request-security.mjs +7 -1
- package/server/src/core/work-conversation-context.mjs +138 -0
- package/server/src/core/work-input-request.mjs +1 -0
- package/server/src/frontend/frontend-tools.mjs +20 -7
- package/server/src/frontend/retrieval/providers/bing.mjs +23 -12
- package/server/src/frontend/retrieval/providers/factory.mjs +18 -1
- package/server/src/frontend/retrieval/providers/mcp.mjs +30 -11
- package/server/src/frontend/retrieval/providers/so360.mjs +23 -12
- package/server/src/frontend/tools/agent-task-runtime.mjs +119 -99
- package/server/src/frontend/tools/features/agent-task-tools.mjs +23 -42
- package/server/src/frontend/tools/frontend-tool-context.mjs +2 -2
- package/server/src/frontend/tools/spawn-thinking-tool.mjs +2 -2
- package/server/src/frontend/tools/tool-call-handler.mjs +166 -86
- package/server/src/knowledge/providers/local/library.mjs +26 -6
- package/server/src/knowledge/providers/local/provider.mjs +25 -6
- package/server/src/memory/providers/markdown/context-store.mjs +24 -11
- package/server/src/orchestration/session-task-coordinator.mjs +13 -3
- package/server/src/orchestration/task-operations.mjs +54 -12
- package/server/src/orchestration/task-updates.mjs +82 -0
- package/server/src/task/reminder-scheduler.mjs +5 -1
- package/server/src/task/task-manager.mjs +72 -15
- package/server/src/task/task-recovery.mjs +12 -2
- package/server/src/task/task-scheduler.mjs +5 -5
- package/server/src/task/task-state.mjs +13 -0
- package/server/src/transport/gateway-client-transport.mjs +35 -0
- package/server/src/transport/webrtc/protocol.mjs +1 -1
- package/server/src/voice/announcement/announcement-manager.mjs +3 -0
- package/server/src/voice/audio-stream-diagnostics.mjs +139 -0
- package/server/src/voice/native-delegation-runtime.mjs +360 -0
- package/server/src/voice/providers/dashscope-live.mjs +93 -0
- package/server/src/voice/providers/dashscope.mjs +45 -33
- package/server/src/voice/providers/doubao-seeduplex-protocol.mjs +54 -0
- package/server/src/voice/providers/doubao-seeduplex.mjs +16 -11
- package/server/src/voice/providers/ga-protocol.mjs +7 -2
- package/server/src/voice/providers/google-live-protocol.mjs +124 -34
- package/server/src/voice/providers/google-live.mjs +20 -14
- package/server/src/voice/providers/gpt-live-1-protocol.mjs +597 -0
- package/server/src/voice/providers/gpt-live-1.mjs +3 -0
- package/server/src/voice/providers/gpt-live-client-context.mjs +182 -0
- package/server/src/voice/providers/minicpm-o.mjs +9 -7
- package/server/src/voice/providers/openai-live.mjs +150 -0
- package/server/src/voice/providers/{gpt-live.mjs → openai-realtime.mjs} +23 -19
- package/server/src/voice/providers/provider-registry.mjs +11 -1
- package/server/src/voice/providers/qwen-live-protocol.mjs +399 -0
- package/server/src/voice/providers/registry.mjs +47 -12
- package/server/src/voice/providers/runtime-configuration.mjs +34 -0
- package/server/src/voice/providers/s2s.mjs +9 -7
- package/server/src/voice/providers/stepfun.mjs +14 -11
- package/server/src/voice/realtime-input-runtime.mjs +58 -20
- package/server/src/voice/realtime-presentation-runtime.mjs +111 -27
- package/server/src/voice/realtime-provider-session.mjs +59 -14
- package/server/src/voice/realtime-provider.mjs +358 -45
- package/server/src/voice/realtime-session-runtime.mjs +282 -35
- package/server/src/voice/realtime-task-presentation.mjs +8 -2
- package/server/src/voice/realtime-turn-state.mjs +33 -2
- package/shared/backend/catalog.mjs +26 -2
- package/shared/backend/install.mjs +3 -1
- package/shared/backend/setup.mjs +43 -0
- package/shared/gateway/client-sdk.mjs +21 -6
- package/shared/gateway/setup.mjs +13 -1
- package/shared/gateway/websocket-auth.mjs +2 -1
- package/shared/protocol/gateway-client-protocol.mjs +14 -0
- package/shared/protocol/gateway-events.mjs +39 -1
- package/shared/realtime-legacy-environment.mjs +81 -0
- package/shared/realtime-model-catalog.mjs +68 -194
- package/shared/realtime-models/README.md +33 -0
- package/shared/realtime-models/dashscope.mjs +57 -0
- package/shared/realtime-models/google.mjs +10 -0
- package/shared/realtime-models/openai.mjs +24 -0
- package/shared/realtime-models/profile.mjs +38 -0
- package/shared/realtime-models/stepfun.mjs +10 -0
- package/shared/realtime-models/volcengine.mjs +12 -0
- package/shared/realtime-provider-catalog.mjs +23 -11
- package/shared/realtime-provider-definitions.mjs +168 -235
- package/shared/runtime-environment.mjs +23 -30
- package/shared/skill-library.mjs +49 -13
- package/shared/web-search-configuration.mjs +25 -2
- package/tui/package.json +2 -2
- package/tui/src/index.mjs +14 -9
- package/tui/src/runtime-configuration.mjs +2 -0
- package/tui/src/terminal-commands.mjs +40 -0
- package/tui/src/text-cli.mjs +10 -1
- package/web/dist/assets/index-Bc2Q04J9.css +1 -0
- package/web/dist/assets/index-bY4DFXKT.js +96 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-BRaiI-dW.js +0 -91
- package/web/dist/assets/index-D9k8R2JY.css +0 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
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.
|
|
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.
|
|
58
|
-
//
|
|
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(
|
|
74
|
+
endpoint = new URL(connection.endpoint)
|
|
63
75
|
} catch {
|
|
64
|
-
throw new RealtimeConfigurationError('请配置有效的
|
|
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} 需要百炼业务空间专属地址;请将
|
|
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
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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}
|
|
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
|
|
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:
|
|
112
|
+
conversationItemIdEcho: family !== 'omni',
|
|
101
113
|
imageRequiresAudioStart: true,
|
|
102
114
|
}
|
|
103
115
|
},
|
|
104
116
|
|
|
105
|
-
model: () =>
|
|
106
|
-
modelCatalog: listDashScopeRealtimeModelProfiles,
|
|
117
|
+
model: () => connection.model,
|
|
118
|
+
modelCatalog: () => listDashScopeRealtimeModelProfiles(config.realtimeModelCatalogs),
|
|
107
119
|
modelProfile: activeModelProfile,
|
|
108
|
-
voice: () =>
|
|
109
|
-
isConfigured: () =>
|
|
110
|
-
missingConfigurationMessage: '
|
|
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:
|
|
114
|
-
headers: () => ({ Authorization: `Bearer ${
|
|
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
|
|
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.
|
|
141
|
+
if (profile.api === 'omni-v2') {
|
|
130
142
|
// Keep the client audio contract unchanged: mono PCM16, 16 kHz in /
|
|
131
|
-
// 24 kHz out.
|
|
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
|
|
148
|
+
...(voice ? { voice } : {}),
|
|
137
149
|
},
|
|
138
150
|
}
|
|
139
151
|
} else {
|
|
140
152
|
if (profile.modelCapabilities.audioOutput) {
|
|
141
|
-
session.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
|
-
|
|
18
|
-
'
|
|
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
|
-
|
|
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: () =>
|
|
48
|
+
model: () => connection.model,
|
|
44
49
|
modelProfile,
|
|
45
|
-
modelCatalog: () => realtimeModelCatalog('
|
|
46
|
-
voice: () =>
|
|
47
|
-
isConfigured: () =>
|
|
48
|
-
missingConfigurationMessage: '
|
|
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: () =>
|
|
51
|
-
headers: () => ({ 'X-Api-Key':
|
|
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
|
-
|
|
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)
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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(
|
|
20
|
+
return resolveRealtimeModelProfile(connection.model, 'google', config.realtimeModelCatalogs)
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
function googleLiveUrl() {
|
|
21
|
-
const url = new URL(
|
|
24
|
+
const url = new URL(connection.endpoint)
|
|
22
25
|
if (!url.searchParams.has('key') && !url.searchParams.has('access_token')) {
|
|
23
|
-
url.searchParams.set('key',
|
|
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 ? {
|
|
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
|
-
|
|
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: () =>
|
|
78
|
+
model: () => connection.model,
|
|
73
79
|
modelProfile,
|
|
74
|
-
modelCatalog: () => realtimeModelCatalog('google
|
|
75
|
-
voice: () =>
|
|
76
|
-
isConfigured: () =>
|
|
77
|
-
missingConfigurationMessage: '
|
|
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 ||
|
|
96
|
+
const voice = String(sessionOptions?.voice || '').trim() || googleLiveProvider.voice()
|
|
91
97
|
const configuredSpeech = speechConfig(voice)
|
|
92
98
|
return {
|
|
93
|
-
model:
|
|
94
|
-
?
|
|
95
|
-
: `models/${
|
|
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 } : {}),
|