























@@ -91,7 +91,6 @@ class TalkModeManager internal constructor(
9191private val context: Context,
9292private val scope: CoroutineScope,
9393private val session: GatewaySession,
94-private val supportsChatSubscribe: Boolean,
9594private val isConnected: () -> Boolean,
9695private val onBeforeSpeak: suspend () -> Unit = {},
9796private val onAfterSpeak: suspend () -> Unit = {},
@@ -104,8 +103,7 @@ class TalkModeManager internal constructor(
104103private const val realtimeSampleRateHz = 24_000
105104private const val realtimeAudioFrameMs = 100
106105private const val listenWatchdogMs = 12_000L
107-private const val chatFinalWaitWithSubscribeMs = 45_000L
108-private const val chatFinalWaitWithoutSubscribeMs = 6_000L
106+private const val chatFinalWaitMs = 45_000L
109107private const val maxCachedRunCompletions = 128
110108private const val maxConversationEntries = 40
111109private const val realtimePlaybackBufferMs = 240
@@ -158,7 +156,6 @@ class TalkModeManager internal constructor(
158156private val completedRunsLock = Any()
159157private val completedRunStates = LinkedHashMap<String, Boolean>()
160158private val completedRunTexts = LinkedHashMap<String, String>()
161-private var chatSubscribedSessionKey: String? = null
162159private var configLoaded = false
163160private var executionMode = TalkModeExecutionMode.Native
164161private val startGeneration = AtomicLong(0L)
@@ -216,11 +213,6 @@ class TalkModeManager internal constructor(
216213 }
217214 }
218215219-suspend fun ensureChatSubscribed() {
220- reloadConfig()
221- subscribeChatIfNeeded(session = session, sessionKey = mainSessionKey.ifBlank { "main" })
222- }
223-224216fun setMainSessionKey(sessionKey: String?) {
225217val trimmed = sessionKey?.trim().orEmpty()
226218if (trimmed.isEmpty()) return
@@ -372,7 +364,6 @@ class TalkModeManager internal constructor(
372364 scope.launch {
373365try {
374366 reloadConfig()
375- subscribeChatIfNeeded(session = session, sessionKey = mainSessionKey.ifBlank { "main" })
376367val startedAt = System.currentTimeMillis().toDouble() / 1000.0
377368val prompt = buildPrompt(command)
378369val runId = sendChat(prompt, session)
@@ -590,7 +581,6 @@ class TalkModeManager internal constructor(
590581_statusText.value = "Off"
591582 stopRealtimeRelay()
592583 stopSpeaking()
593- chatSubscribedSessionKey = null
594584 pendingRunId = null
595585 pendingFinal?.cancel()
596586 pendingFinal = null
@@ -1590,7 +1580,6 @@ class TalkModeManager internal constructor(
1590158015911581try {
15921582val startedAt = System.currentTimeMillis().toDouble() / 1000.0
1593- subscribeChatIfNeeded(session = session, sessionKey = mainSessionKey)
15941583Log.d(tag, "chat.send start sessionKey=${mainSessionKey.ifBlank { "main" }} chars=${prompt.length}")
15951584val runId = sendChat(prompt, session)
15961585Log.d(tag, "chat.send ok runId=$runId")
@@ -1649,23 +1638,6 @@ class TalkModeManager internal constructor(
16491638return payload
16501639 }
165116401652-private suspend fun subscribeChatIfNeeded(
1653-session: GatewaySession,
1654-sessionKey: String,
1655- ) {
1656-if (!supportsChatSubscribe) return
1657-val key = sessionKey.trim()
1658-if (key.isEmpty()) return
1659-if (chatSubscribedSessionKey == key) return
1660-val sent = session.sendNodeEvent("chat.subscribe", """{"sessionKey":"$key"}""")
1661-if (sent) {
1662- chatSubscribedSessionKey = key
1663-Log.d(tag, "chat.subscribe ok sessionKey=$key")
1664- } else {
1665-Log.w(tag, "chat.subscribe failed sessionKey=$key")
1666- }
1667- }
1668-16691641private fun buildPrompt(transcript: String): String {
16701642val lines =
16711643mutableListOf(
@@ -1719,10 +1691,9 @@ class TalkModeManager internal constructor(
1719169117201692 consumeRunCompletion(runId)?.let { return it }
172116931722-val timeoutMs = if (supportsChatSubscribe) chatFinalWaitWithSubscribeMs else chatFinalWaitWithoutSubscribeMs
17231694val result =
17241695try {
1725- withTimeout(timeoutMs) { deferred.await() }
1696+ withTimeout(chatFinalWaitMs) { deferred.await() }
17261697 } catch (_: TimeoutCancellationException) {
17271698false
17281699 }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。