From 73712994c620094cfdd151f078d00d2d33c626f9 Mon Sep 17 00:00:00 2001 From: let5sne Date: Sat, 25 Jul 2026 23:58:19 +0800 Subject: [PATCH] fix(mobile): stop preloading answer TTS on native App On native App the eager TTS request delayed the answer bubble: the message was created in `preparing` state, so the text stayed behind a voice line that was still waiting on a round trip. Skip the preload when `isNativeAppRuntime()`, marking the voice `unavailable` so the text and citations render immediately. The existing `unavailable` branch already exposes a play button that calls `toggleAnswerSpeech`, so voice stays reachable on demand instead of being dropped. H5 keeps preloading. Co-Authored-By: Claude Opus 5 (1M context) --- mobile-uni/src/pages/user/sop/index.vue | 5 +++-- mobile-uni/tests/agent.test.mjs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mobile-uni/src/pages/user/sop/index.vue b/mobile-uni/src/pages/user/sop/index.vue index 6e8f98bf..624ed15c 100644 --- a/mobile-uni/src/pages/user/sop/index.vue +++ b/mobile-uni/src/pages/user/sop/index.vue @@ -993,6 +993,7 @@ const sendQuestion = async ( } retireEarlierMemoryCandidate(nextResult.memoryCandidate?.id); const spoken = (nextResult.answer || '').trim(); + const shouldPreloadVoice = Boolean(spoken) && !isNativeAppRuntime(); replaceMsg(pending.id, { id: pending.id, role: 'master', @@ -1004,12 +1005,12 @@ const sendQuestion = async ( feedbackReasonCodes: [], feedbackComment: '', citationsOpen: false, - voiceStatus: spoken ? 'preparing' : 'unavailable', + voiceStatus: shouldPreloadVoice ? 'preparing' : 'unavailable', voiceDuration: null, unread: Boolean(spoken), transcriptOpen: false }); - if (spoken) void prepareVoice(pending.id, spoken); + if (shouldPreloadVoice) void prepareVoice(pending.id, spoken); if (!nextResult.answer && !nextResult.snippets?.length && !nextResult.memoryCandidate) { pushSystem('未检索到可引用内容,换个问法试试'); } diff --git a/mobile-uni/tests/agent.test.mjs b/mobile-uni/tests/agent.test.mjs index bda1b3c9..21f115f6 100644 --- a/mobile-uni/tests/agent.test.mjs +++ b/mobile-uni/tests/agent.test.mjs @@ -38,6 +38,14 @@ test('Agent 响应按结构化状态渲染来源、澄清和确认动作', async assert.doesNotMatch(page, /result\.answer\.(?:includes|match|startsWith)/); }); +test('原生 App 立即显示 Agent 文字回答,语音仅按需生成', async () => { + const page = await source('../src/pages/user/sop/index.vue'); + + assert.match(page, /const shouldPreloadVoice = Boolean\(spoken\) && !isNativeAppRuntime\(\)/); + assert.match(page, /voiceStatus: shouldPreloadVoice \? 'preparing' : 'unavailable'/); + assert.match(page, /if \(shouldPreloadVoice\) void prepareVoice\(pending\.id, spoken\)/); +}); + test('Agent 确认卡通过不透明 draftId 调用动作端点', async () => { const [assistantService, card] = await Promise.all([ source('../src/services/personal-assistant.ts'),