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
|
@@ -14,6 +14,7 @@ const PROVIDER_INPUT_EVENTS = new Set([
|
|
|
14
14
|
'input_audio_buffer.speech_stopped',
|
|
15
15
|
'input_audio_buffer.committed',
|
|
16
16
|
'conversation.item.ambient_audio_transcription.completed',
|
|
17
|
+
'conversation.item.input_audio_transcription.started',
|
|
17
18
|
'conversation.item.input_audio_transcription.delta',
|
|
18
19
|
'conversation.item.input_audio_transcription.text',
|
|
19
20
|
'conversation.item.input_audio_transcription.completed',
|
|
@@ -40,6 +41,7 @@ export class RealtimeInputRuntime {
|
|
|
40
41
|
send,
|
|
41
42
|
getFrontend,
|
|
42
43
|
ensureFrontend,
|
|
44
|
+
submitUserInput,
|
|
43
45
|
clearResponseCandidate,
|
|
44
46
|
expectResponseFor,
|
|
45
47
|
shouldEnsurePermissionResponse,
|
|
@@ -60,6 +62,7 @@ export class RealtimeInputRuntime {
|
|
|
60
62
|
this.send = send
|
|
61
63
|
this.getFrontend = getFrontend
|
|
62
64
|
this.ensureFrontend = ensureFrontend
|
|
65
|
+
this.submitUserInput = submitUserInput || ((parts, context) => this.getFrontend().sendUserInput(parts, context))
|
|
63
66
|
this.clearResponseCandidate = clearResponseCandidate
|
|
64
67
|
this.expectResponseFor = expectResponseFor
|
|
65
68
|
this.shouldEnsurePermissionResponse = shouldEnsurePermissionResponse
|
|
@@ -85,6 +88,8 @@ export class RealtimeInputRuntime {
|
|
|
85
88
|
this.#commitAudio(event)
|
|
86
89
|
} else if (event.type === 'conversation.item.ambient_audio_transcription.completed') {
|
|
87
90
|
this.turns.completeInput(event.item_id)
|
|
91
|
+
} else if (event.type === 'conversation.item.input_audio_transcription.started') {
|
|
92
|
+
this.#startTranscript(event)
|
|
88
93
|
} else if (
|
|
89
94
|
event.type === 'conversation.item.input_audio_transcription.delta'
|
|
90
95
|
|| event.type === 'conversation.item.input_audio_transcription.text'
|
|
@@ -114,10 +119,7 @@ export class RealtimeInputRuntime {
|
|
|
114
119
|
})
|
|
115
120
|
this.announcementWindow.beginTurn(started.context.turnId)
|
|
116
121
|
this.announcements.dismissActive()
|
|
117
|
-
this
|
|
118
|
-
type: GatewayServerEvent.PLAYBACK_CLEAR,
|
|
119
|
-
reason: 'user_interruption',
|
|
120
|
-
})
|
|
122
|
+
this.#clearPlaybackForInterruption()
|
|
121
123
|
this.send({
|
|
122
124
|
type: GatewayServerEvent.TURN_STARTED,
|
|
123
125
|
turnId: started.context.turnId,
|
|
@@ -127,7 +129,29 @@ export class RealtimeInputRuntime {
|
|
|
127
129
|
state: 'listening',
|
|
128
130
|
turnId: started.context.turnId,
|
|
129
131
|
})
|
|
130
|
-
|
|
132
|
+
if (!event.providerHandlesInterruption) {
|
|
133
|
+
this.getFrontend()?.cancel({ reason: 'user_interruption', speech: true })
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// A frontend whose model finishes the speech it already generated keeps playing.
|
|
138
|
+
#clearPlaybackForInterruption() {
|
|
139
|
+
if (this.getFrontend()?.capabilities?.interruptionPlaysOut) return
|
|
140
|
+
this.send({
|
|
141
|
+
type: GatewayServerEvent.PLAYBACK_CLEAR,
|
|
142
|
+
reason: 'user_interruption',
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#startTranscript(event) {
|
|
147
|
+
const started = this.turns.beginVoice(event.item_id)
|
|
148
|
+
if (!started.accepted) return
|
|
149
|
+
// Some providers deliver transcription without a VAD start. Associate
|
|
150
|
+
// the text with a voice turn without interrupting ongoing playback.
|
|
151
|
+
this.turns.endSpeech()
|
|
152
|
+
this.turns.commit(started.context)
|
|
153
|
+
this.clearResponseCandidate()
|
|
154
|
+
this.send({ type: GatewayServerEvent.TURN_STARTED, turnId: started.context.turnId })
|
|
131
155
|
}
|
|
132
156
|
|
|
133
157
|
#stopSpeech(event) {
|
|
@@ -148,6 +172,8 @@ export class RealtimeInputRuntime {
|
|
|
148
172
|
this.announcementWindow.endSpeech()
|
|
149
173
|
if (event.reason === 'turn_invalid') {
|
|
150
174
|
this.turns.invalidateInput(event.item_id)
|
|
175
|
+
this.announcementWindow.responseDone({ turnId: stoppedTurn.turnId, failed: true })
|
|
176
|
+
this.announcements.flush()
|
|
151
177
|
this.send({
|
|
152
178
|
type: GatewayServerEvent.TRANSCRIPT_DISCARD,
|
|
153
179
|
role: 'user',
|
|
@@ -206,15 +232,25 @@ export class RealtimeInputRuntime {
|
|
|
206
232
|
}
|
|
207
233
|
|
|
208
234
|
#completeTranscript(event) {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
235
|
+
const revision = event.__transcriptRevision === true
|
|
236
|
+
let transcriptTurn
|
|
237
|
+
if (revision) {
|
|
238
|
+
// Only a provider's local segmentation may revise an already completed
|
|
239
|
+
// item. Never fall back to the current turn or reopen a speech boundary.
|
|
240
|
+
if (!this.turns.correlation.isComplete(event.item_id)
|
|
241
|
+
|| this.turns.isInputInvalid(event.item_id)) return
|
|
242
|
+
transcriptTurn = this.turns.resolveInput(event.item_id, { fallbackToCurrent: false })
|
|
243
|
+
if (!this.turns.isUserTurnSinceBoundary(transcriptTurn)) return
|
|
244
|
+
} else {
|
|
245
|
+
const completedInput = this.turns.completeInput(event.item_id)
|
|
246
|
+
transcriptTurn = completedInput.context
|
|
247
|
+
if (completedInput.invalid
|
|
248
|
+
|| completedInput.duplicate
|
|
249
|
+
|| this.turns.isStale(transcriptTurn)) return
|
|
250
|
+
}
|
|
216
251
|
const transcript = String(event.transcript || '').trim()
|
|
217
252
|
if (!transcript) {
|
|
253
|
+
if (revision) return
|
|
218
254
|
this.send({
|
|
219
255
|
type: GatewayServerEvent.TRANSCRIPT_DISCARD,
|
|
220
256
|
role: 'user',
|
|
@@ -222,9 +258,9 @@ export class RealtimeInputRuntime {
|
|
|
222
258
|
})
|
|
223
259
|
return
|
|
224
260
|
}
|
|
225
|
-
this.turns.commit(transcriptTurn)
|
|
261
|
+
if (!revision) this.turns.commit(transcriptTurn)
|
|
226
262
|
this.transcripts.record(transcriptTurn.turnId, transcript)
|
|
227
|
-
if (this.shouldEnsurePermissionResponse(transcriptTurn)) {
|
|
263
|
+
if (!revision && this.shouldEnsurePermissionResponse(transcriptTurn)) {
|
|
228
264
|
this.ensurePermissionResponseFor(transcriptTurn)
|
|
229
265
|
}
|
|
230
266
|
this.conversationSync.record({
|
|
@@ -275,10 +311,7 @@ export class RealtimeInputRuntime {
|
|
|
275
311
|
this.announcementWindow.beginTurn(inputTurnId)
|
|
276
312
|
this.announcementWindow.endSpeech()
|
|
277
313
|
this.announcements.dismissActive()
|
|
278
|
-
this
|
|
279
|
-
type: GatewayServerEvent.PLAYBACK_CLEAR,
|
|
280
|
-
reason: 'user_interruption',
|
|
281
|
-
})
|
|
314
|
+
this.#clearPlaybackForInterruption()
|
|
282
315
|
if (supersededVoiceTurn?.turnId) {
|
|
283
316
|
this.send({
|
|
284
317
|
type: GatewayServerEvent.TRANSCRIPT_DISCARD,
|
|
@@ -294,7 +327,7 @@ export class RealtimeInputRuntime {
|
|
|
294
327
|
turnId: inputTurnId,
|
|
295
328
|
origin: 'model',
|
|
296
329
|
})
|
|
297
|
-
this.getFrontend()?.cancel()
|
|
330
|
+
this.getFrontend()?.cancel({ reason: 'user_interruption' })
|
|
298
331
|
this.transcripts.record(inputTurnId, text || display)
|
|
299
332
|
this.transcripts.recordParts(inputTurnId, inputFileParts(parts))
|
|
300
333
|
this.conversationSync.record({
|
|
@@ -314,8 +347,13 @@ export class RealtimeInputRuntime {
|
|
|
314
347
|
turnId: inputTurnId,
|
|
315
348
|
})
|
|
316
349
|
this.ensureFrontend()
|
|
317
|
-
.then(() => this.
|
|
350
|
+
.then(() => this.submitUserInput(parts, inputContext))
|
|
318
351
|
.then(outcome => {
|
|
352
|
+
// Native input scheduling does not reserve a Realtime response slot.
|
|
353
|
+
// Allow the next spoken input even while this request awaits a reply.
|
|
354
|
+
if (this.getFrontend()?.capabilities?.automaticUserResponses) {
|
|
355
|
+
this.turns.finishManualResponse(inputContext)
|
|
356
|
+
}
|
|
319
357
|
if (!outcome?.timedOut) return
|
|
320
358
|
this.turns.failManualInput(inputContext)
|
|
321
359
|
this.send({
|
|
@@ -15,6 +15,7 @@ import { realtimeResponseId } from './response-lifecycle.mjs'
|
|
|
15
15
|
|
|
16
16
|
const PRESENTATION_RESPONSE_EVENTS = new Set([
|
|
17
17
|
'response.created',
|
|
18
|
+
'response.interrupted',
|
|
18
19
|
'response.audio.delta',
|
|
19
20
|
'response.output_audio.delta',
|
|
20
21
|
'response.audio_transcript.delta',
|
|
@@ -31,11 +32,19 @@ export function confirmsTaskNotificationOnPlaybackStart(context) {
|
|
|
31
32
|
context
|
|
32
33
|
&& (
|
|
33
34
|
context.origin === 'announcement'
|
|
34
|
-
|| context
|
|
35
|
+
|| isTaskNotification(context)
|
|
35
36
|
),
|
|
36
37
|
)
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// A due reminder reaches the model as a Gateway system event for its task.
|
|
41
|
+
function isTaskNotification(context) {
|
|
42
|
+
return Boolean(
|
|
43
|
+
context?.consumesTaskNotification
|
|
44
|
+
|| (context?.origin === 'gateway-system-event' && contextTaskIds(context).length),
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
export function acceptsPlaybackReceipt({
|
|
40
49
|
outputEnabled,
|
|
41
50
|
active,
|
|
@@ -72,8 +81,10 @@ export class RealtimePresentationRuntime {
|
|
|
72
81
|
getFrontend,
|
|
73
82
|
getOutputEnabled,
|
|
74
83
|
getNonVoiceClient,
|
|
84
|
+
getPlaybackReceipts = () => true,
|
|
75
85
|
getResponseTurnCandidate,
|
|
76
86
|
clearResponseCandidate,
|
|
87
|
+
clearResponseWatchdog,
|
|
77
88
|
announcementQuietMs,
|
|
78
89
|
responseContextCleanupMs,
|
|
79
90
|
turnCitations = null,
|
|
@@ -89,8 +100,10 @@ export class RealtimePresentationRuntime {
|
|
|
89
100
|
this.getFrontend = getFrontend
|
|
90
101
|
this.getOutputEnabled = getOutputEnabled
|
|
91
102
|
this.getNonVoiceClient = getNonVoiceClient
|
|
103
|
+
this.getPlaybackReceipts = getPlaybackReceipts
|
|
92
104
|
this.getResponseTurnCandidate = getResponseTurnCandidate
|
|
93
105
|
this.clearResponseCandidate = clearResponseCandidate
|
|
106
|
+
this.clearResponseWatchdog = clearResponseWatchdog
|
|
94
107
|
this.announcementQuietMs = announcementQuietMs
|
|
95
108
|
this.responseContextCleanupMs = responseContextCleanupMs
|
|
96
109
|
this.turnCitations = turnCitations
|
|
@@ -194,7 +207,9 @@ export class RealtimePresentationRuntime {
|
|
|
194
207
|
}
|
|
195
208
|
if (automaticTurn) {
|
|
196
209
|
this.turns.commit(automaticTurn)
|
|
197
|
-
|
|
210
|
+
// A voice-only reply cannot settle a pending permission: keep that fallback.
|
|
211
|
+
if (event.__voicePlayback && this.#capability('concurrentVoicePlayback')) this.clearResponseWatchdog()
|
|
212
|
+
else this.clearResponseCandidate()
|
|
198
213
|
}
|
|
199
214
|
if (!context.responseStarted && !context.suppressed) {
|
|
200
215
|
context.responseStarted = true
|
|
@@ -210,7 +225,12 @@ export class RealtimePresentationRuntime {
|
|
|
210
225
|
handle(event) {
|
|
211
226
|
if (!PRESENTATION_RESPONSE_EVENTS.has(event?.type)) return false
|
|
212
227
|
if (event.type === 'response.created') return true
|
|
213
|
-
if (
|
|
228
|
+
if (event.type === 'response.interrupted') {
|
|
229
|
+
const id = realtimeResponseId(event)
|
|
230
|
+
const reason = 'user_interruption'
|
|
231
|
+
if (this.contexts.has(id) && !this.playbackTurns.has(id)) this.cancelPlayback(id, { reason })
|
|
232
|
+
if (this.playbackTurns.size) this.send({ type: GatewayServerEvent.PLAYBACK_CLEAR, reason })
|
|
233
|
+
} else if (
|
|
214
234
|
event.type === 'response.audio.delta'
|
|
215
235
|
|| event.type === 'response.output_audio.delta'
|
|
216
236
|
) {
|
|
@@ -251,10 +271,12 @@ export class RealtimePresentationRuntime {
|
|
|
251
271
|
if (id) {
|
|
252
272
|
context.hasAudio = true
|
|
253
273
|
this.playbackTurns.set(id, responseTurnId)
|
|
254
|
-
this.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
274
|
+
if (this.getPlaybackReceipts()) {
|
|
275
|
+
this.announcementWindow.queueAudio(id, {
|
|
276
|
+
turnId: responseTurnId,
|
|
277
|
+
origin: context.origin || 'model',
|
|
278
|
+
})
|
|
279
|
+
}
|
|
258
280
|
}
|
|
259
281
|
this.send({
|
|
260
282
|
type: GatewayServerEvent.AUDIO_DELTA,
|
|
@@ -266,11 +288,15 @@ export class RealtimePresentationRuntime {
|
|
|
266
288
|
})
|
|
267
289
|
}
|
|
268
290
|
|
|
291
|
+
#capability(name) {
|
|
292
|
+
return this.getFrontend()?.capabilities?.[name] === true
|
|
293
|
+
}
|
|
294
|
+
|
|
269
295
|
#audioTranscriptDelta(event) {
|
|
270
296
|
const id = realtimeResponseId(event)
|
|
271
297
|
const context = this.#contextFor(event)
|
|
272
298
|
if (context.suppressed) return
|
|
273
|
-
if (!context.playbackStarted) {
|
|
299
|
+
if (this.getPlaybackReceipts() && !context.playbackStarted) {
|
|
274
300
|
context.pendingTranscripts.push({
|
|
275
301
|
content: event.delta || '',
|
|
276
302
|
final: false,
|
|
@@ -291,7 +317,7 @@ export class RealtimePresentationRuntime {
|
|
|
291
317
|
if (context.suppressed) return
|
|
292
318
|
context.transcriptDone = true
|
|
293
319
|
context.assistantTranscript = event.transcript || ''
|
|
294
|
-
if (!context.playbackStarted) {
|
|
320
|
+
if (this.getPlaybackReceipts() && !context.playbackStarted) {
|
|
295
321
|
context.pendingTranscripts.push({
|
|
296
322
|
content: event.transcript || '',
|
|
297
323
|
final: true,
|
|
@@ -331,11 +357,13 @@ export class RealtimePresentationRuntime {
|
|
|
331
357
|
content: event.text || '',
|
|
332
358
|
final: true,
|
|
333
359
|
})
|
|
360
|
+
this.#finishContextIfComplete(id, context)
|
|
334
361
|
}
|
|
335
362
|
|
|
336
363
|
#responseDone(event) {
|
|
337
364
|
const id = realtimeResponseId(event)
|
|
338
365
|
const context = this.contexts.get(id)
|
|
366
|
+
const awaitsPlayback = this.getPlaybackReceipts()
|
|
339
367
|
const terminalToolResponse = this.toolCalls.consumeTerminalToolResponse(id)
|
|
340
368
|
const responseTurnId = context?.turnId || this.turns.turnId
|
|
341
369
|
const responseStatus = event.response?.status
|
|
@@ -353,13 +381,6 @@ export class RealtimePresentationRuntime {
|
|
|
353
381
|
&& !suppressToolFollowUp,
|
|
354
382
|
)
|
|
355
383
|
if (context) context.awaitsToolFollowUp = toolFollowUpPending
|
|
356
|
-
this.toolCalls.finishToolResponse(id, {
|
|
357
|
-
suppressResponse,
|
|
358
|
-
sourceHasSpeech,
|
|
359
|
-
}).catch(error => this.send({
|
|
360
|
-
type: GatewayServerEvent.ERROR,
|
|
361
|
-
message: error.message,
|
|
362
|
-
}))
|
|
363
384
|
const guardDecision = evaluateResponseGuards({
|
|
364
385
|
origin: context?.origin || 'model',
|
|
365
386
|
hasFunctionCall: Boolean(context?.hasFunctionCall),
|
|
@@ -373,7 +394,7 @@ export class RealtimePresentationRuntime {
|
|
|
373
394
|
responseId: id,
|
|
374
395
|
turnId: responseTurnId,
|
|
375
396
|
})
|
|
376
|
-
if (!context?.hasAudio && !toolFollowUpPending) {
|
|
397
|
+
if ((!context?.hasAudio || !awaitsPlayback) && !toolFollowUpPending) {
|
|
377
398
|
this.send({
|
|
378
399
|
type: GatewayServerEvent.VOICE_STATE,
|
|
379
400
|
state: 'idle',
|
|
@@ -387,16 +408,23 @@ export class RealtimePresentationRuntime {
|
|
|
387
408
|
if (context?.hasAudio && !failed) {
|
|
388
409
|
context.responseDone = true
|
|
389
410
|
this.#finishContextIfComplete(id, context)
|
|
411
|
+
if (!awaitsPlayback) {
|
|
412
|
+
this.playbackTurns.delete(id)
|
|
413
|
+
if (this.contexts.has(id)) this.#scheduleContextCleanup(id, context)
|
|
414
|
+
}
|
|
390
415
|
} else {
|
|
391
416
|
const nonVoiceClient = this.getNonVoiceClient()
|
|
417
|
+
// A full-duplex announcement plays under a response of its own: its
|
|
418
|
+
// completion is the last signal tied to the announcement.
|
|
419
|
+
const confirmsOnResponseDone = nonVoiceClient || this.#capability('concurrentVoicePlayback')
|
|
392
420
|
const completedNonVoiceAnnouncement = (
|
|
393
421
|
context?.origin === 'announcement'
|
|
394
|
-
&&
|
|
422
|
+
&& confirmsOnResponseDone
|
|
395
423
|
&& !failed
|
|
396
424
|
)
|
|
397
425
|
const completedNonVoiceTaskNotification = (
|
|
398
|
-
context
|
|
399
|
-
&&
|
|
426
|
+
isTaskNotification(context)
|
|
427
|
+
&& confirmsOnResponseDone
|
|
400
428
|
&& !failed
|
|
401
429
|
)
|
|
402
430
|
if (
|
|
@@ -418,7 +446,15 @@ export class RealtimePresentationRuntime {
|
|
|
418
446
|
} else if (completedNonVoiceTaskNotification) {
|
|
419
447
|
this.announcements.confirmMany(contextTaskIds(context))
|
|
420
448
|
}
|
|
421
|
-
|
|
449
|
+
if (!awaitsPlayback && context && (failed || context.suppressed)) {
|
|
450
|
+
// Keep a bounded tombstone so late provider chunks cannot revive a
|
|
451
|
+
// cancelled response on clients with no playback acknowledgement.
|
|
452
|
+
context.suppressed = true
|
|
453
|
+
context.pendingTranscripts = []
|
|
454
|
+
this.#scheduleContextCleanup(id, context)
|
|
455
|
+
} else {
|
|
456
|
+
this.contexts.delete(id)
|
|
457
|
+
}
|
|
422
458
|
}
|
|
423
459
|
if (failed && id) {
|
|
424
460
|
this.playbackTurns.delete(id)
|
|
@@ -429,11 +465,20 @@ export class RealtimePresentationRuntime {
|
|
|
429
465
|
this.announcementWindow.responseDone({
|
|
430
466
|
turnId: responseTurnId,
|
|
431
467
|
origin: context?.origin || 'model',
|
|
432
|
-
hasAudio: Boolean(context?.hasAudio && !context?.playbackEnded),
|
|
468
|
+
hasAudio: Boolean(awaitsPlayback && context?.hasAudio && !context?.playbackEnded),
|
|
433
469
|
awaitsToolFollowUp: toolFollowUpPending,
|
|
434
470
|
suppressed: Boolean(context?.suppressed) || terminalToolResponse,
|
|
435
471
|
failed,
|
|
436
472
|
})
|
|
473
|
+
// Set the source response's waiting state first: a failed tool batch can
|
|
474
|
+
// settle synchronously and must not have its release overwritten below.
|
|
475
|
+
this.toolCalls.finishToolResponse(id, {
|
|
476
|
+
suppressResponse,
|
|
477
|
+
sourceHasSpeech,
|
|
478
|
+
}).catch(error => this.send({
|
|
479
|
+
type: GatewayServerEvent.ERROR,
|
|
480
|
+
message: error.message,
|
|
481
|
+
}))
|
|
437
482
|
if (guardDecision) this.#requestGuardCorrection(guardDecision, context, responseTurnId)
|
|
438
483
|
this.#flushAnnouncementsSoon()
|
|
439
484
|
}
|
|
@@ -522,7 +567,8 @@ export class RealtimePresentationRuntime {
|
|
|
522
567
|
#finishContextIfComplete(id, context) {
|
|
523
568
|
if (
|
|
524
569
|
context
|
|
525
|
-
&& context.playbackEnded
|
|
570
|
+
&& (context.playbackEnded || !this.getPlaybackReceipts())
|
|
571
|
+
&& !context.suppressed
|
|
526
572
|
&& context.responseDone
|
|
527
573
|
&& context.transcriptDone
|
|
528
574
|
) {
|
|
@@ -532,11 +578,14 @@ export class RealtimePresentationRuntime {
|
|
|
532
578
|
|
|
533
579
|
#scheduleContextCleanup(id, context) {
|
|
534
580
|
const timer = setTimeout(() => {
|
|
535
|
-
|
|
581
|
+
const current = this.contexts.get(id)
|
|
582
|
+
// Provider metadata merges replace the object; the response's turn is
|
|
583
|
+
// stable even if its final transcript arrives after response.done.
|
|
584
|
+
if (!current || current.turnId !== context.turnId || current.turnGeneration !== context.turnGeneration) return
|
|
536
585
|
this.contexts.delete(id)
|
|
537
586
|
this.playbackTurns.delete(id)
|
|
538
587
|
this.announcementWindow.finishPlayback(id, {
|
|
539
|
-
awaitsToolFollowUp: awaitsToolFollowUp(
|
|
588
|
+
awaitsToolFollowUp: awaitsToolFollowUp(current),
|
|
540
589
|
})
|
|
541
590
|
}, this.responseContextCleanupMs)
|
|
542
591
|
timer.unref?.()
|
|
@@ -605,10 +654,40 @@ export class RealtimePresentationRuntime {
|
|
|
605
654
|
this.#flushAnnouncementsSoon()
|
|
606
655
|
}
|
|
607
656
|
|
|
657
|
+
failToolResponse({ responseId, turnId }) {
|
|
658
|
+
const context = this.contexts.get(responseId)
|
|
659
|
+
if (context) context.awaitsToolFollowUp = false
|
|
660
|
+
const hasAudio = Boolean(this.getPlaybackReceipts() && context?.hasAudio && !context.playbackEnded)
|
|
661
|
+
this.announcementWindow.responseDone({
|
|
662
|
+
turnId,
|
|
663
|
+
origin: context?.origin || 'model',
|
|
664
|
+
hasAudio,
|
|
665
|
+
failed: true,
|
|
666
|
+
})
|
|
667
|
+
if (!hasAudio && turnId === this.turns.turnId && !this.turns.userSpeaking) {
|
|
668
|
+
this.send({
|
|
669
|
+
type: GatewayServerEvent.VOICE_STATE,
|
|
670
|
+
state: 'idle',
|
|
671
|
+
turnId,
|
|
672
|
+
origin: context?.origin || 'model',
|
|
673
|
+
})
|
|
674
|
+
}
|
|
675
|
+
this.#flushAnnouncementsSoon()
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
clearPlayback({ reason = '' } = {}) {
|
|
679
|
+
// A Gateway playback.clear is authoritative. Do not keep cleared audio
|
|
680
|
+
// blocking results just because a client cancellation receipt is lost.
|
|
681
|
+
for (const id of this.playbackTurns.keys()) {
|
|
682
|
+
this.cancelPlayback(id, { reason })
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
608
686
|
cancelPlayback(id, { reason = '' } = {}) {
|
|
609
687
|
const context = this.contexts.get(id)
|
|
688
|
+
if (context?.suppressed && context.playbackEnded) return
|
|
610
689
|
this.announcementWindow.finishPlayback(id, {
|
|
611
|
-
awaitsToolFollowUp:
|
|
690
|
+
awaitsToolFollowUp: false,
|
|
612
691
|
})
|
|
613
692
|
const playbackTurnId = this.playbackTurns.get(id) || this.turns.turnId
|
|
614
693
|
this.playbackTurns.delete(id)
|
|
@@ -656,6 +735,11 @@ export class RealtimePresentationRuntime {
|
|
|
656
735
|
failResponse(event) {
|
|
657
736
|
const id = realtimeResponseId(event)
|
|
658
737
|
const context = this.contexts.get(id)
|
|
738
|
+
if (context && !this.getPlaybackReceipts()) {
|
|
739
|
+
context.suppressed = true
|
|
740
|
+
context.pendingTranscripts = []
|
|
741
|
+
this.playbackTurns.delete(id)
|
|
742
|
+
}
|
|
659
743
|
if (context?.origin === 'announcement') {
|
|
660
744
|
this.send({ type: GatewayServerEvent.PLAYBACK_CLEAR })
|
|
661
745
|
this.announcementWindow.finishPlayback(id)
|
|
@@ -677,7 +761,7 @@ export class RealtimePresentationRuntime {
|
|
|
677
761
|
this.announcementWindow.responseDone({
|
|
678
762
|
turnId: context?.turnId || this.turns.turnId,
|
|
679
763
|
origin: context?.origin || 'model',
|
|
680
|
-
hasAudio: Boolean(context?.hasAudio),
|
|
764
|
+
hasAudio: Boolean(this.getPlaybackReceipts() && context?.hasAudio),
|
|
681
765
|
awaitsToolFollowUp: false,
|
|
682
766
|
failed: true,
|
|
683
767
|
})
|
|
@@ -34,7 +34,11 @@ export class RealtimeProviderSession {
|
|
|
34
34
|
reconnectBackoff = new ReconnectBackoff(),
|
|
35
35
|
}) {
|
|
36
36
|
this.providerRegistry = providerRegistry
|
|
37
|
-
|
|
37
|
+
const initialProvider = providerRegistry.resolve(defaultProvider)
|
|
38
|
+
// Registry keys identify adapters; public supplier IDs need not be aliases
|
|
39
|
+
// in an SDK registry, and can be shared by several different adapters.
|
|
40
|
+
this.adapterKey = initialProvider.key
|
|
41
|
+
this.providerKey = initialProvider.provider || initialProvider.key
|
|
38
42
|
this.getAgentContext = getAgentContext
|
|
39
43
|
this.getSessionOptions = getSessionOptions
|
|
40
44
|
this.shouldReconnect = shouldReconnect
|
|
@@ -56,6 +60,8 @@ export class RealtimeProviderSession {
|
|
|
56
60
|
this.frontend = null
|
|
57
61
|
this.connectPromise = null
|
|
58
62
|
this.pendingAudio = []
|
|
63
|
+
this.pendingAudioSince = null
|
|
64
|
+
this.pendingAudioDropped = 0
|
|
59
65
|
this.pendingImage = null
|
|
60
66
|
this.scheduledReconnect = null
|
|
61
67
|
this.connectedAt = 0
|
|
@@ -88,7 +94,7 @@ export class RealtimeProviderSession {
|
|
|
88
94
|
|
|
89
95
|
provider() {
|
|
90
96
|
return this.frontend?.provider
|
|
91
|
-
?? this.providerRegistry.resolve(this.
|
|
97
|
+
?? this.providerRegistry.resolve(this.adapterKey)
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
classifyError(message) {
|
|
@@ -97,8 +103,9 @@ export class RealtimeProviderSession {
|
|
|
97
103
|
|
|
98
104
|
switchProvider(providerName) {
|
|
99
105
|
const requested = this.providerRegistry.resolve(providerName)
|
|
100
|
-
if (requested.key === this.
|
|
101
|
-
this.
|
|
106
|
+
if (requested.key === this.adapterKey) return false
|
|
107
|
+
this.adapterKey = requested.key
|
|
108
|
+
this.providerKey = requested.provider || requested.key
|
|
102
109
|
this.blockedError = ''
|
|
103
110
|
this.detach({ clearAudio: false })
|
|
104
111
|
return true
|
|
@@ -119,6 +126,8 @@ export class RealtimeProviderSession {
|
|
|
119
126
|
|
|
120
127
|
clearPendingAudio() {
|
|
121
128
|
this.pendingAudio = []
|
|
129
|
+
this.pendingAudioSince = null
|
|
130
|
+
this.pendingAudioDropped = 0
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
clearPendingImage() {
|
|
@@ -148,8 +157,10 @@ export class RealtimeProviderSession {
|
|
|
148
157
|
this.frontend.appendAudio(audio)
|
|
149
158
|
return
|
|
150
159
|
}
|
|
160
|
+
if (this.pendingAudioSince === null) this.pendingAudioSince = performance.now()
|
|
151
161
|
this.pendingAudio.push(audio)
|
|
152
162
|
if (this.pendingAudio.length > this.maxPendingAudioChunks) {
|
|
163
|
+
this.pendingAudioDropped += this.pendingAudio.length - this.maxPendingAudioChunks
|
|
153
164
|
this.pendingAudio.splice(
|
|
154
165
|
0,
|
|
155
166
|
this.pendingAudio.length - this.maxPendingAudioChunks,
|
|
@@ -182,15 +193,19 @@ export class RealtimeProviderSession {
|
|
|
182
193
|
if (this.blockedError) return Promise.reject(new Error(this.blockedError))
|
|
183
194
|
if (this.ready) return Promise.resolve()
|
|
184
195
|
if (this.connectPromise) return this.connectPromise
|
|
196
|
+
// Built-in registries may resolve a different adapter after a model change.
|
|
197
|
+
const selected = this.providerRegistry.resolve(this.adapterKey)
|
|
198
|
+
this.adapterKey = selected.key
|
|
199
|
+
this.providerKey = selected.provider || selected.key
|
|
185
200
|
this.onConnectionState({
|
|
186
201
|
state: 'connecting',
|
|
187
202
|
provider: this.providerKey,
|
|
188
203
|
})
|
|
189
204
|
const connectStartedAt = Date.now()
|
|
190
|
-
this.logger.info('realtime.connecting', { provider: this.providerKey })
|
|
205
|
+
this.logger.info('realtime.connecting', { provider: this.providerKey, adapter: this.adapterKey })
|
|
191
206
|
let createdFrontend
|
|
192
207
|
createdFrontend = this.createFrontend({
|
|
193
|
-
providerName: this.
|
|
208
|
+
providerName: this.adapterKey,
|
|
194
209
|
providerRegistry: this.providerRegistry,
|
|
195
210
|
agentContext: this.getAgentContext(),
|
|
196
211
|
sessionOptions: this.getSessionOptions(),
|
|
@@ -212,25 +227,53 @@ export class RealtimeProviderSession {
|
|
|
212
227
|
this.blockedError = ''
|
|
213
228
|
this.connectedAt = Date.now()
|
|
214
229
|
this.logger.info('realtime.connected', {
|
|
215
|
-
provider: createdFrontend.provider.key,
|
|
230
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
231
|
+
adapter: createdFrontend.provider.key,
|
|
216
232
|
durationMs: this.connectedAt - connectStartedAt,
|
|
217
233
|
})
|
|
218
234
|
this.onConnectionState({
|
|
219
235
|
state: 'connected',
|
|
220
|
-
provider: createdFrontend.provider.key,
|
|
236
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
221
237
|
})
|
|
222
238
|
this.onConnected(createdFrontend)
|
|
239
|
+
// Opted-in sleep protocols must restore mute before any buffered input.
|
|
240
|
+
// Other providers keep their existing connect/flush ordering.
|
|
241
|
+
const muteBeforeAudio = this.inputMuted && createdFrontend.provider.capabilities?.inputMuteOnSleep === true
|
|
242
|
+
if (muteBeforeAudio) {
|
|
243
|
+
createdFrontend.setInputMuted?.(true)
|
|
244
|
+
this.clearPendingAudio()
|
|
245
|
+
}
|
|
246
|
+
if (this.pendingAudio.length) {
|
|
247
|
+
// Describe the bounded reconnect buffer, never the audio itself.
|
|
248
|
+
// This is the buffering window, not the age of the oldest retained
|
|
249
|
+
// frame: overflow may already have discarded earlier frames.
|
|
250
|
+
try {
|
|
251
|
+
const sampleRate = createdFrontend.provider.inputSampleRate
|
|
252
|
+
this.logger.info('realtime.audio.input_buffer_flushed', {
|
|
253
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
254
|
+
adapter: createdFrontend.provider.key,
|
|
255
|
+
retainedChunks: this.pendingAudio.length,
|
|
256
|
+
droppedChunks: this.pendingAudioDropped,
|
|
257
|
+
bufferingMs: this.pendingAudioSince === null ? 0 : Math.round(performance.now() - this.pendingAudioSince),
|
|
258
|
+
...(Number.isFinite(sampleRate) && sampleRate > 0 ? {
|
|
259
|
+
retainedPcmDurationMs: Math.round(this.pendingAudio.reduce((bytes, audio) =>
|
|
260
|
+
bytes + Buffer.byteLength(audio, 'base64'), 0) / (sampleRate * 2) * 1000),
|
|
261
|
+
} : {}),
|
|
262
|
+
})
|
|
263
|
+
} catch { /* Diagnostics must not interrupt audio recovery. */ }
|
|
264
|
+
}
|
|
223
265
|
this.pendingAudio.forEach(audio => createdFrontend.appendAudio(audio))
|
|
224
|
-
this.
|
|
266
|
+
this.clearPendingAudio()
|
|
225
267
|
if (this.pendingImage) createdFrontend.appendImage(this.pendingImage)
|
|
226
268
|
this.pendingImage = null
|
|
227
|
-
createdFrontend.setInputMuted?.(this.inputMuted)
|
|
269
|
+
if (!muteBeforeAudio) createdFrontend.setInputMuted?.(this.inputMuted)
|
|
228
270
|
this.onReady(createdFrontend)
|
|
229
271
|
})
|
|
230
272
|
.catch(error => {
|
|
231
273
|
if (this.frontend !== createdFrontend) return
|
|
232
274
|
this.logger.error('realtime.connect_failed', {
|
|
233
|
-
provider: createdFrontend.provider.key,
|
|
275
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
276
|
+
adapter: createdFrontend.provider.key,
|
|
234
277
|
durationMs: Date.now() - connectStartedAt,
|
|
235
278
|
error,
|
|
236
279
|
})
|
|
@@ -245,7 +288,7 @@ export class RealtimeProviderSession {
|
|
|
245
288
|
if (classification !== 'capacity_busy') {
|
|
246
289
|
this.onConnectionState({
|
|
247
290
|
state: 'unavailable',
|
|
248
|
-
provider: createdFrontend.provider.key,
|
|
291
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
249
292
|
message: error.message,
|
|
250
293
|
})
|
|
251
294
|
}
|
|
@@ -275,7 +318,8 @@ export class RealtimeProviderSession {
|
|
|
275
318
|
}
|
|
276
319
|
if (classification !== 'inactivity') {
|
|
277
320
|
this.logger.warn('realtime.provider_error', {
|
|
278
|
-
provider: createdFrontend.provider.key,
|
|
321
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
322
|
+
adapter: createdFrontend.provider.key,
|
|
279
323
|
classification,
|
|
280
324
|
error,
|
|
281
325
|
})
|
|
@@ -295,7 +339,8 @@ export class RealtimeProviderSession {
|
|
|
295
339
|
if (this.frontend !== createdFrontend) return
|
|
296
340
|
const connectedMs = this.connectedAt ? Date.now() - this.connectedAt : 0
|
|
297
341
|
this.logger.warn('realtime.closed', {
|
|
298
|
-
provider: createdFrontend.provider.key,
|
|
342
|
+
provider: createdFrontend.provider.provider || createdFrontend.provider.key,
|
|
343
|
+
adapter: createdFrontend.provider.key,
|
|
299
344
|
connectedMs,
|
|
300
345
|
blocked: Boolean(this.blockedError),
|
|
301
346
|
})
|