qwen-audio-agent 2.1.0 → 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 +6 -3
- package/README_ZH.md +6 -3
- package/cli/package.json +1 -1
- package/cli/src/config-command.mjs +33 -2
- package/cli/src/gateway-service.mjs +7 -1
- package/config/frontend-agent/LIVE_PROMPT.md +64 -0
- package/desktop/src/i18n.mjs +1 -1
- package/desktop/src/settings-config.mjs +10 -24
- package/docs/configuration/frontend.md +29 -12
- package/docs/configuration/frontend.zh.md +28 -12
- package/docs/contract.md +2 -0
- package/docs/contract.zh.md +2 -0
- package/docs/extensions.md +14 -0
- package/docs/extensions.zh.md +11 -0
- package/docs/getting-started/install.md +3 -0
- package/docs/getting-started/install.zh.md +3 -0
- package/docs/getting-started/mobile.md +8 -2
- package/docs/getting-started/mobile.zh.md +5 -0
- package/docs/guides/web-search.md +17 -1
- package/docs/guides/web-search.zh.md +15 -1
- package/docs/operations/troubleshooting.md +30 -0
- package/docs/operations/troubleshooting.zh.md +26 -0
- package/docs/voice-frontends/custom-provider.md +18 -3
- package/docs/voice-frontends/custom-provider.zh.md +18 -3
- package/docs/voice-frontends/google-live.md +7 -3
- package/docs/voice-frontends/google-live.zh.md +6 -3
- 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/{gpt-live.md → openai-realtime.md} +12 -5
- package/docs/voice-frontends/{gpt-live.zh.md → openai-realtime.zh.md} +11 -5
- 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 +2 -1
- package/docs/voice-frontends/qwen-audio-realtime.zh.md +2 -1
- package/docs/voice-frontends/qwen-omni-realtime.md +1 -1
- package/docs/voice-frontends/qwen-omni-realtime.zh.md +1 -1
- package/package.json +13 -4
- package/scripts/patch-build-node-gyp.mjs +63 -0
- package/scripts/prepare-build.mjs +2 -0
- package/scripts/verify-package.mjs +3 -0
- package/server/package.json +2 -2
- package/server/src/conversation/frontend-agent-context.mjs +18 -5
- package/server/src/core/citation.mjs +8 -2
- package/server/src/core/config.mjs +16 -5
- package/server/src/core/request-security.mjs +7 -1
- package/server/src/frontend/frontend-tools.mjs +14 -1
- package/server/src/frontend/retrieval/providers/bing.mjs +23 -12
- package/server/src/frontend/retrieval/providers/factory.mjs +9 -1
- package/server/src/frontend/retrieval/providers/mcp.mjs +17 -9
- package/server/src/frontend/retrieval/providers/so360.mjs +23 -12
- package/server/src/frontend/tools/agent-task-runtime.mjs +22 -4
- package/server/src/frontend/tools/tool-call-handler.mjs +56 -20
- package/server/src/memory/providers/markdown/context-store.mjs +3 -1
- package/server/src/orchestration/session-task-coordinator.mjs +4 -1
- package/server/src/orchestration/task-operations.mjs +5 -3
- package/server/src/orchestration/task-updates.mjs +2 -1
- package/server/src/transport/gateway-client-transport.mjs +19 -0
- package/server/src/transport/webrtc/protocol.mjs +1 -1
- 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 +12 -4
- package/server/src/voice/providers/doubao-seeduplex-protocol.mjs +54 -0
- package/server/src/voice/providers/doubao-seeduplex.mjs +6 -5
- 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 +6 -5
- 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/openai-live.mjs +150 -0
- package/server/src/voice/providers/{gpt-live.mjs → openai-realtime.mjs} +15 -14
- 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 +45 -10
- package/server/src/voice/providers/runtime-configuration.mjs +17 -6
- package/server/src/voice/providers/stepfun.mjs +1 -1
- package/server/src/voice/realtime-input-runtime.mjs +56 -20
- package/server/src/voice/realtime-presentation-runtime.mjs +21 -4
- package/server/src/voice/realtime-provider-session.mjs +59 -14
- package/server/src/voice/realtime-provider.mjs +332 -36
- package/server/src/voice/realtime-session-runtime.mjs +207 -16
- package/server/src/voice/realtime-task-presentation.mjs +6 -2
- package/server/src/voice/realtime-turn-state.mjs +33 -2
- package/shared/gateway/client-sdk.mjs +15 -5
- package/shared/gateway/websocket-auth.mjs +2 -1
- package/shared/protocol/gateway-events.mjs +31 -0
- package/shared/realtime-legacy-environment.mjs +37 -8
- package/shared/realtime-model-catalog.mjs +12 -10
- package/shared/realtime-models/README.md +10 -2
- package/shared/realtime-models/dashscope.mjs +11 -0
- package/shared/realtime-models/{google-live.mjs → google.mjs} +1 -1
- package/shared/realtime-models/openai.mjs +24 -0
- package/shared/realtime-models/profile.mjs +6 -3
- package/shared/realtime-models/{doubao-seeduplex.mjs → volcengine.mjs} +1 -1
- package/shared/realtime-provider-catalog.mjs +7 -6
- package/shared/realtime-provider-definitions.mjs +87 -22
- package/shared/runtime-environment.mjs +2 -2
- package/shared/web-search-configuration.mjs +14 -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/shared/realtime-models/gpt-live.mjs +0 -10
- package/web/dist/assets/index-8erKDCr2.css +0 -1
- package/web/dist/assets/index-Cs4hYWbS.js +0 -96
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const MAX_FRAGMENTS = 512
|
|
2
|
+
const MAX_CONTEXT_CHARACTERS = 12_000
|
|
3
|
+
const MAX_DELEGATIONS = 256
|
|
4
|
+
const READY_EVENT = 'gpt-live-1.delegation_ready'
|
|
5
|
+
const hasWords = value => /[\p{L}\p{N}]/u.test(value)
|
|
6
|
+
const clean = value => String(value || '').replace(/\[[^[\]]*\]/g, '').replace(/\[[^[\]]{0,24}$/, '').trim()
|
|
7
|
+
const textContext = value => String(value || '').replace(/<input_parts>[\s\S]*?<\/input_parts>/g, '').trim()
|
|
8
|
+
|
|
9
|
+
// Client delegation contains only an ID and a session timestamp. Keep its
|
|
10
|
+
// transcript input separate from presentation turns: a late ASR fragment still
|
|
11
|
+
// belongs to the execution context even when its displayed turn has closed.
|
|
12
|
+
export class GptLiveClientContext {
|
|
13
|
+
constructor({ emit, settleMs = 300, waitMs = 2_000 } = {}) {
|
|
14
|
+
this.emit = emit
|
|
15
|
+
this.settleMs = settleMs
|
|
16
|
+
this.waitMs = waitMs
|
|
17
|
+
this.fragments = []
|
|
18
|
+
this.pending = new Map()
|
|
19
|
+
this.seen = new Set()
|
|
20
|
+
this.previousOffset = -Infinity
|
|
21
|
+
this.latestTime = 0
|
|
22
|
+
this.sessionId = ''
|
|
23
|
+
this.closed = false
|
|
24
|
+
this.readyEvents = new WeakSet()
|
|
25
|
+
this.lastDroppedUser = null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
seed(input = []) {
|
|
29
|
+
for (const message of input) {
|
|
30
|
+
if (!['user', 'assistant'].includes(message.role)) continue
|
|
31
|
+
const content = textContext((message.content || []).map(part => part.text || '').join('\n'))
|
|
32
|
+
if (content) this.fragments.push({ role: message.role, content, start: -Infinity, end: -Infinity, seeded: true })
|
|
33
|
+
}
|
|
34
|
+
this.trim()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
rememberContext(role, value) {
|
|
38
|
+
if (this.closed) return
|
|
39
|
+
const content = textContext(value)
|
|
40
|
+
if (!content) return
|
|
41
|
+
// Text values and verified task updates aid later spoken references, but
|
|
42
|
+
// cannot themselves trigger another delegation. Historic file metadata is
|
|
43
|
+
// excluded: attaching files requires an explicit, current input selection.
|
|
44
|
+
this.fragments.push({ role, content, start: this.latestTime, end: this.latestTime, seeded: true })
|
|
45
|
+
this.trim()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
record(event, inputItemId = '') {
|
|
49
|
+
if (this.closed) return
|
|
50
|
+
const role = event.type === 'session.input_transcript.delta' ? 'user' : 'assistant'
|
|
51
|
+
const content = String(event.delta || '')
|
|
52
|
+
const start = event.start_ms
|
|
53
|
+
const end = event.end_ms
|
|
54
|
+
// Untimed speech remains visible to the UI, but must not be guessed into a
|
|
55
|
+
// particular delegated request or replay an earlier request.
|
|
56
|
+
if (!content || !Number.isFinite(start) || !Number.isFinite(end) || end < start) return
|
|
57
|
+
this.latestTime = Math.max(this.latestTime, end)
|
|
58
|
+
// The presentation adapter may already have finalized a delayed fragment's
|
|
59
|
+
// turn. Recover only an adjacent timestamp-matched ID, never the current
|
|
60
|
+
// user turn (which may belong to a later question).
|
|
61
|
+
if (role === 'user' && !inputItemId) {
|
|
62
|
+
const previous = this.fragments.filter(fragment => fragment.role === 'user' && fragment.inputItemId
|
|
63
|
+
&& fragment.start <= start && start - fragment.end < 1_200).sort((a, b) => b.start - a.start)[0]
|
|
64
|
+
inputItemId = previous?.inputItemId || ''
|
|
65
|
+
}
|
|
66
|
+
this.fragments.push({ role, content, start, end, ...(role === 'user' ? { inputItemId } : {}) })
|
|
67
|
+
this.trim()
|
|
68
|
+
if (role === 'user') for (const pending of this.pending.values()) {
|
|
69
|
+
if (start <= pending.offset && start > pending.after) this.schedule(pending)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
trim() {
|
|
74
|
+
const drop = () => {
|
|
75
|
+
const fragment = this.fragments.shift()
|
|
76
|
+
if (fragment.role === 'user' && !fragment.seeded) this.lastDroppedUser = { start: fragment.start, end: fragment.end }
|
|
77
|
+
return fragment.content.length
|
|
78
|
+
}
|
|
79
|
+
while (this.fragments.length > MAX_FRAGMENTS) drop()
|
|
80
|
+
let characters = this.fragments.reduce((sum, fragment) => sum + fragment.content.length, 0)
|
|
81
|
+
while (characters > MAX_CONTEXT_CHARACTERS && this.fragments.length > 1) {
|
|
82
|
+
characters -= drop()
|
|
83
|
+
}
|
|
84
|
+
// Never execute a truncated user instruction. An oversized fragment can
|
|
85
|
+
// still be displayed, but the resulting delegation has no executable input.
|
|
86
|
+
if (characters > MAX_CONTEXT_CHARACTERS) drop()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
receive(event) {
|
|
90
|
+
const delegation = event.delegation
|
|
91
|
+
if (this.closed || delegation?.target !== 'client' || !delegation.id || !event.event_id) return
|
|
92
|
+
if (this.seen.has(delegation.id) || this.seen.size >= MAX_DELEGATIONS) return
|
|
93
|
+
this.seen.add(delegation.id)
|
|
94
|
+
const offset = event.offset_ms
|
|
95
|
+
const pending = { id: delegation.id, eventId: event.event_id, offset, after: this.previousOffset }
|
|
96
|
+
if (!Number.isFinite(offset) || offset <= this.previousOffset) {
|
|
97
|
+
this.publish(pending, null)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
this.previousOffset = offset
|
|
101
|
+
this.latestTime = Math.max(this.latestTime, offset)
|
|
102
|
+
this.pending.set(pending.id, pending)
|
|
103
|
+
pending.deadline = setTimeout(() => this.finish(pending), this.waitMs)
|
|
104
|
+
pending.deadline.unref?.()
|
|
105
|
+
this.schedule(pending)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
schedule(pending) {
|
|
109
|
+
clearTimeout(pending.settle)
|
|
110
|
+
// No transcript yet: wait for it, up to the hard deadline.
|
|
111
|
+
if (!this.fresh(pending).length) return
|
|
112
|
+
pending.settle = setTimeout(() => this.finish(pending), this.settleMs)
|
|
113
|
+
pending.settle.unref?.()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fresh(pending) {
|
|
117
|
+
return this.fragments.filter(fragment => !fragment.seeded && fragment.role === 'user'
|
|
118
|
+
&& fragment.start <= pending.offset && fragment.start > pending.after
|
|
119
|
+
&& hasWords(clean(fragment.content)))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
finish(pending) {
|
|
123
|
+
if (!this.pending.delete(pending.id) || this.closed) return
|
|
124
|
+
clearTimeout(pending.deadline)
|
|
125
|
+
clearTimeout(pending.settle)
|
|
126
|
+
const fresh = this.fresh(pending).sort((a, b) => a.start - b.start)
|
|
127
|
+
// Earlier conversation is context, not a concatenated list of new tasks.
|
|
128
|
+
let latest = []
|
|
129
|
+
for (const fragment of fresh) {
|
|
130
|
+
if (latest.length && fragment.start - latest.at(-1).end >= 1_200) latest = []
|
|
131
|
+
latest.push(fragment)
|
|
132
|
+
}
|
|
133
|
+
const objective = clean(latest.map(fragment => fragment.content).join(''))
|
|
134
|
+
if (!objective) return this.publish(pending, null)
|
|
135
|
+
const dropped = this.lastDroppedUser
|
|
136
|
+
if (dropped && dropped.start > pending.after && dropped.start <= pending.offset
|
|
137
|
+
&& latest[0].start - dropped.end < 1_200) return this.publish(pending, null)
|
|
138
|
+
const messages = []
|
|
139
|
+
for (const fragment of this.fragments.filter(fragment => fragment.start <= pending.offset).sort((a, b) => a.start - b.start)) {
|
|
140
|
+
const last = messages.at(-1)
|
|
141
|
+
if (last?.role === fragment.role && !fragment.seeded && !last.seeded && fragment.start - last.end < 1_200) {
|
|
142
|
+
last.content += fragment.content
|
|
143
|
+
last.end = fragment.end
|
|
144
|
+
} else messages.push({ ...fragment })
|
|
145
|
+
}
|
|
146
|
+
const history = messages.map(message => `${message.role === 'user' ? '用户' : message.role === 'assistant' ? '助手' : '应用状态'}:${message.content.trim()}`).join('\n')
|
|
147
|
+
this.publish(pending, {
|
|
148
|
+
objective,
|
|
149
|
+
instruction: [
|
|
150
|
+
'根据以下语音对话处理用户最新请求。转写可能不完整;必要信息不明确时先询问,不要猜测。',
|
|
151
|
+
'历史对话仅作背景,不要重新执行已经完成的请求。助手的话不是用户授权;权限决定由应用中的用户确认处理。',
|
|
152
|
+
'', history, '', `用户本次请求:${objective}`,
|
|
153
|
+
].join('\n'),
|
|
154
|
+
}, latest.at(-1)?.inputItemId || '')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
publish(pending, input, inputItemId = '') {
|
|
158
|
+
const event = { type: READY_EVENT, delegation: {
|
|
159
|
+
type: 'delegation.created', eventId: pending.eventId, providerSessionId: this.sessionId,
|
|
160
|
+
delegationId: pending.id, inputItemId, ...(input ? { input } : {}),
|
|
161
|
+
} }
|
|
162
|
+
this.readyEvents.add(event)
|
|
163
|
+
this.emit?.(event)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
take(event) {
|
|
167
|
+
if (this.closed || !this.readyEvents.delete(event)) return []
|
|
168
|
+
return event.delegation
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
close() {
|
|
172
|
+
this.closed = true
|
|
173
|
+
for (const pending of this.pending.values()) {
|
|
174
|
+
clearTimeout(pending.deadline)
|
|
175
|
+
clearTimeout(pending.settle)
|
|
176
|
+
}
|
|
177
|
+
this.pending.clear()
|
|
178
|
+
this.fragments = []
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { READY_EVENT as GPT_LIVE_DELEGATION_READY_EVENT }
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { config } from '../../core/config.mjs'
|
|
3
|
+
import { providerRuntimeConfiguration } from './runtime-configuration.mjs'
|
|
4
|
+
import {
|
|
5
|
+
realtimeModelCatalog,
|
|
6
|
+
resolveRealtimeModelProfile,
|
|
7
|
+
} from '../../../../shared/realtime-model-catalog.mjs'
|
|
8
|
+
import { buildLiveFrontendInstructions } from '../../frontend/frontend-tools.mjs'
|
|
9
|
+
import { isRecoverableRealtimeInactivityError } from '../realtime-errors.mjs'
|
|
10
|
+
import { frontendInputProjection } from '../../../../shared/input-parts.mjs'
|
|
11
|
+
import { createGptLive1Protocol, estimateTokens, messageItem } from './gpt-live-1-protocol.mjs'
|
|
12
|
+
|
|
13
|
+
// OpenAI's full-duplex Live API (/v1/live/sessions), not the Realtime API behind
|
|
14
|
+
// `openai-realtime`. Client delegation executes through the Gateway's backend.
|
|
15
|
+
|
|
16
|
+
const connection = providerRuntimeConfiguration('openai-live', { provider: 'openai' })
|
|
17
|
+
|
|
18
|
+
function modelProfile() {
|
|
19
|
+
return resolveRealtimeModelProfile(connection.model, 'openai', config.realtimeModelCatalogs)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Startup history: session.input takes up to 128 messages and 8,192 tokens; the
|
|
23
|
+
// estimate is rough, so keep a margin.
|
|
24
|
+
const SESSION_INPUT_MAX_MESSAGES = 64
|
|
25
|
+
const SESSION_INPUT_TOKEN_BUDGET = 6144
|
|
26
|
+
|
|
27
|
+
export function sessionInputHistory(messages = []) {
|
|
28
|
+
const selected = []
|
|
29
|
+
let used = 0
|
|
30
|
+
for (const message of [...(Array.isArray(messages) ? messages : [])].reverse()) {
|
|
31
|
+
const role = message?.role === 'assistant' ? 'assistant' : message?.role === 'user' ? 'user' : ''
|
|
32
|
+
const text = typeof message?.content === 'string' ? message.content.trim() : ''
|
|
33
|
+
if (!role || !text) continue
|
|
34
|
+
const tokens = estimateTokens(text)
|
|
35
|
+
if (used + tokens > SESSION_INPUT_TOKEN_BUDGET || selected.length >= SESSION_INPUT_MAX_MESSAGES) break
|
|
36
|
+
selected.unshift(messageItem(role, text))
|
|
37
|
+
used += tokens
|
|
38
|
+
}
|
|
39
|
+
return selected
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Histories the service refused at startup, by content: only a retry with the
|
|
43
|
+
// same history omits it (every connection shares this module).
|
|
44
|
+
const REJECTED_HISTORY_LIMIT = 16
|
|
45
|
+
const rejectedHistories = new Set()
|
|
46
|
+
|
|
47
|
+
function historyKey(input) {
|
|
48
|
+
return createHash('sha256').update(JSON.stringify(input)).digest('hex')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function rememberRejectedHistory(input) {
|
|
52
|
+
if (!Array.isArray(input) || !input.length) return
|
|
53
|
+
rejectedHistories.add(historyKey(input))
|
|
54
|
+
while (rejectedHistories.size > REJECTED_HISTORY_LIMIT) {
|
|
55
|
+
rejectedHistories.delete(rejectedHistories.values().next().value)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function seededHistory(recentMessages) {
|
|
60
|
+
const input = sessionInputHistory(recentMessages)
|
|
61
|
+
if (input.length && rejectedHistories.delete(historyKey(input))) return []
|
|
62
|
+
return input
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const openaiLiveProvider = {
|
|
66
|
+
key: 'openai-live',
|
|
67
|
+
provider: 'openai',
|
|
68
|
+
label: 'OpenAI',
|
|
69
|
+
aliases: ['gptlive1', 'gpt-live-1'],
|
|
70
|
+
// Live API input and output are both raw mono PCM16 at 24 kHz.
|
|
71
|
+
inputSampleRate: 24000,
|
|
72
|
+
outputSampleRate: 24000,
|
|
73
|
+
createProtocol: context => createGptLive1Protocol({
|
|
74
|
+
...config.gptLive1Timing,
|
|
75
|
+
...context,
|
|
76
|
+
onStartupError: (error, { session } = {}) => {
|
|
77
|
+
if (/^(session\.)?input\b/.test(String(error?.param || ''))) rememberRejectedHistory(session?.input)
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
capabilities: {
|
|
81
|
+
// session.started is the only startup acknowledgement.
|
|
82
|
+
acknowledgesSessionUpdate: false,
|
|
83
|
+
// Client mode has no remotely configured backend or frontend function tools.
|
|
84
|
+
mutableSession: false,
|
|
85
|
+
nativeDelegation: true,
|
|
86
|
+
nativeSessionContext: true,
|
|
87
|
+
clientResponses: false,
|
|
88
|
+
// The Live API echoes no receipt for an item.
|
|
89
|
+
conversationItemIdEcho: false,
|
|
90
|
+
acknowledgesConversationItems: false,
|
|
91
|
+
// History goes into session.input at startup.
|
|
92
|
+
restoreConversationContext: false,
|
|
93
|
+
// Work and its delivery are not client-created voice responses.
|
|
94
|
+
perResponseInstructions: false,
|
|
95
|
+
sessionOutputVoice: true,
|
|
96
|
+
concurrentVoicePlayback: true,
|
|
97
|
+
interruptionPlaysOut: true,
|
|
98
|
+
// Speech streams as it is spoken.
|
|
99
|
+
pacedOutputAudio: true,
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
model: () => connection.model,
|
|
103
|
+
modelProfile,
|
|
104
|
+
modelCatalog: () => realtimeModelCatalog('openai', config.realtimeModelCatalogs).profiles,
|
|
105
|
+
voice: () => String(connection.voice || '').trim() || null,
|
|
106
|
+
isConfigured: () => connection.configured,
|
|
107
|
+
missingConfigurationMessage: '请先选择 OpenAI 的 Live 模型并配置 QWEN_AUDIO_REALTIME_API_KEY',
|
|
108
|
+
connectTimeoutMessage: '连接 GPT-Live 1 Live API 超时',
|
|
109
|
+
url: () => connection.endpoint,
|
|
110
|
+
headers: () => ({ Authorization: `Bearer ${connection.credential}` }),
|
|
111
|
+
// A rejected command (session.update, an append) fails only itself.
|
|
112
|
+
classifyError: message => {
|
|
113
|
+
if (isRecoverableRealtimeInactivityError(message)) return 'inactivity'
|
|
114
|
+
// Session capacity only; a failed backend response fails its turn.
|
|
115
|
+
if (/unexpected server response: 429|too many (?:concurrent )?sessions|concurrent[_ -]?sessions?/i.test(message)) return 'capacity_busy'
|
|
116
|
+
// The key is checked at the handshake; a later auth error fails only the turn.
|
|
117
|
+
if (/invalid[_ -]?api[_ -]?key|unexpected server response: (?:401|403)|model[_ -]?not[_ -]?(?:found|deployed)/i.test(message)) return 'fatal'
|
|
118
|
+
// Only a close for content is recovered; other moderation cuts only speech.
|
|
119
|
+
if (/\bsession_closed\b/.test(message)) return 'content_safety'
|
|
120
|
+
return 'other'
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
buildSession: ({ agentContext, sessionOptions }) => {
|
|
124
|
+
const voice = String(sessionOptions?.voice || connection.voice || '').trim()
|
|
125
|
+
const input = seededHistory(agentContext?.recentMessages)
|
|
126
|
+
return {
|
|
127
|
+
model: connection.model,
|
|
128
|
+
instructions: buildLiveFrontendInstructions(agentContext),
|
|
129
|
+
...(input.length ? { input } : {}),
|
|
130
|
+
...(voice ? { audio: { output: { voice } } } : {}),
|
|
131
|
+
delegation: { type: 'client' },
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// The Gateway executes typed inputs directly; only mirror their context here.
|
|
136
|
+
projectUserInput: ({ parts, options, protocol }) => {
|
|
137
|
+
const content = frontendInputProjection(parts, options)
|
|
138
|
+
if (!content) return null
|
|
139
|
+
return {
|
|
140
|
+
conversationItem: protocol.userTextItem(content),
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
buildSpeakResponse: () => null,
|
|
145
|
+
|
|
146
|
+
// Native task delivery bypasses Realtime response injections.
|
|
147
|
+
buildResultInjection: () => null,
|
|
148
|
+
buildPermissionInjection: () => null,
|
|
149
|
+
|
|
150
|
+
}
|
|
@@ -15,19 +15,19 @@ import {
|
|
|
15
15
|
import { isRecoverableRealtimeInactivityError } from '../realtime-errors.mjs'
|
|
16
16
|
import { gaRealtimeProtocol } from './ga-protocol.mjs'
|
|
17
17
|
|
|
18
|
-
const connection = providerRuntimeConfiguration('
|
|
18
|
+
const connection = providerRuntimeConfiguration('openai-realtime', { provider: 'openai' })
|
|
19
19
|
|
|
20
20
|
function modelProfile() {
|
|
21
|
-
return resolveRealtimeModelProfile(connection.model, '
|
|
21
|
+
return resolveRealtimeModelProfile(connection.model, 'openai', config.realtimeModelCatalogs)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function
|
|
24
|
+
function openaiRealtimeUrl() {
|
|
25
25
|
const url = new URL(connection.endpoint)
|
|
26
26
|
url.searchParams.set('model', connection.model)
|
|
27
27
|
return url.toString()
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function
|
|
30
|
+
function openaiRealtimeTools(agentContext) {
|
|
31
31
|
return frontendTools(agentContext).map(tool => ({
|
|
32
32
|
type: 'function',
|
|
33
33
|
name: tool.function.name,
|
|
@@ -36,10 +36,11 @@ function gptLiveTools(agentContext) {
|
|
|
36
36
|
}))
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export const
|
|
40
|
-
key: '
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
export const openaiRealtimeProvider = {
|
|
40
|
+
key: 'openai-realtime',
|
|
41
|
+
provider: 'openai',
|
|
42
|
+
label: 'OpenAI',
|
|
43
|
+
aliases: ['gpt-live', 'openai', 'gptlive', 'gpt-realtime'],
|
|
43
44
|
inputSampleRate: 24000,
|
|
44
45
|
outputSampleRate: 24000,
|
|
45
46
|
protocol: gaRealtimeProtocol,
|
|
@@ -51,12 +52,12 @@ export const gptLiveProvider = {
|
|
|
51
52
|
|
|
52
53
|
model: () => connection.model,
|
|
53
54
|
modelProfile,
|
|
54
|
-
modelCatalog: () => realtimeModelCatalog('
|
|
55
|
+
modelCatalog: () => realtimeModelCatalog('openai', config.realtimeModelCatalogs).profiles,
|
|
55
56
|
voice: () => String(connection.voice || '').trim() || modelProfile().sessionDefaults.voice,
|
|
56
57
|
isConfigured: () => connection.configured,
|
|
57
|
-
missingConfigurationMessage: '请先选择
|
|
58
|
-
connectTimeoutMessage: '连接
|
|
59
|
-
url:
|
|
58
|
+
missingConfigurationMessage: '请先选择 OpenAI 的 Realtime 模型并配置 QWEN_AUDIO_REALTIME_API_KEY',
|
|
59
|
+
connectTimeoutMessage: '连接 OpenAI Realtime 超时',
|
|
60
|
+
url: openaiRealtimeUrl,
|
|
60
61
|
headers: () => ({ Authorization: `Bearer ${connection.credential}` }),
|
|
61
62
|
classifyError: message => {
|
|
62
63
|
if (isRecoverableRealtimeInactivityError(message)) return 'inactivity'
|
|
@@ -68,11 +69,11 @@ export const gptLiveProvider = {
|
|
|
68
69
|
},
|
|
69
70
|
|
|
70
71
|
buildSession: ({ agentContext, sessionOptions }) => {
|
|
71
|
-
const voice = String(sessionOptions?.voice || '').trim() ||
|
|
72
|
+
const voice = String(sessionOptions?.voice || '').trim() || openaiRealtimeProvider.voice()
|
|
72
73
|
return {
|
|
73
74
|
type: 'realtime',
|
|
74
75
|
instructions: buildFrontendInstructions(agentContext),
|
|
75
|
-
tools:
|
|
76
|
+
tools: openaiRealtimeTools(agentContext),
|
|
76
77
|
output_modalities: ['audio'],
|
|
77
78
|
audio: {
|
|
78
79
|
input: {
|
|
@@ -30,6 +30,7 @@ const PROTOCOL_METHODS = [
|
|
|
30
30
|
const CAPABILITY_FLAGS = [
|
|
31
31
|
'acknowledgesSessionUpdate',
|
|
32
32
|
'singleResponseSlot',
|
|
33
|
+
'requiresResponseCreated',
|
|
33
34
|
'responseMetadataCorrelation',
|
|
34
35
|
'perResponseInstructions',
|
|
35
36
|
'conversationItemIdEcho',
|
|
@@ -38,9 +39,18 @@ const CAPABILITY_FLAGS = [
|
|
|
38
39
|
'restoreConversationContext',
|
|
39
40
|
'conversationItems',
|
|
40
41
|
'automaticToolResponses',
|
|
42
|
+
'automaticUserResponses',
|
|
43
|
+
'contextOnlyItems',
|
|
41
44
|
'clientResponses',
|
|
45
|
+
'nativeDelegation',
|
|
46
|
+
'nativeSessionContext',
|
|
42
47
|
'mutableSession',
|
|
43
48
|
'imageRequiresAudioStart',
|
|
49
|
+
'concurrentVoicePlayback',
|
|
50
|
+
'toolOutputsBeforeResponse',
|
|
51
|
+
'interruptionPlaysOut',
|
|
52
|
+
'pacedOutputAudio',
|
|
53
|
+
'inputMuteOnSleep',
|
|
44
54
|
]
|
|
45
55
|
|
|
46
56
|
const MODEL_CAPABILITY_FLAGS = [
|
|
@@ -160,7 +170,7 @@ export function validateRealtimeProtocol(protocol, providerKey = 'unknown') {
|
|
|
160
170
|
`Realtime Provider ${providerKey} protocol.connectionMessages 必须是函数`,
|
|
161
171
|
)
|
|
162
172
|
}
|
|
163
|
-
for (const method of ['inputMute', 'inputUnmute', 'sessionClose']) {
|
|
173
|
+
for (const method of ['inputMute', 'inputUnmute', 'sessionClose', 'interruptPlayback', 'delegationUpdate']) {
|
|
164
174
|
if (
|
|
165
175
|
protocol[method] !== undefined
|
|
166
176
|
&& typeof protocol[method] !== 'function'
|