fix(frontend): address CodeRabbit review findings on voice conversation mode

Report STT start and capture failures instead of staying on Listening, treat a failed reading as an error, skip replies with no readable text, stop auto-play replaying a reply voice mode already read, focus the text box after Edit in text box, and strip think blocks before text reaches TTS.
This commit is contained in:
Chris Scott committed 2026-10-22 20:36:01 -04:00
1 parent 5d8b2c9445
commit 73af7aec89
8 files changed
+292 -45

No files matched your search

@@ -27,7 +27,7 @@ interface MockTTSReturn {
activeMessageId: string | null
}
import { getLatestPlayableAssistantMessage, useAutoPlayLastResponse } from '../useAutoPlayLastResponse'
import { getAssistantText, getLatestPlayableAssistantMessage, useAutoPlayLastResponse } from '../useAutoPlayLastResponse'
const createMessage = (
id: string,
@@ -172,6 +172,114 @@ describe('useAutoPlayLastResponse', () => {
expect(mockQueueMessage).not.toHaveBeenCalled()
})
it('does NOT queue a reply that completed while voice mode owned playback when enabled turns back on', () => {
setup()
const baselineMessage = createMessage('0', Date.now())
const streamingMessage = createMessage('1')
const completedMessage = createMessage('1', Date.now())
const { rerender } = renderHook(
(props) => useAutoPlayLastResponse(props),
{
initialProps: {
sessionId: 'test-session',
lastAssistantMessage: baselineMessage,
lastAssistantText: 'Earlier reply',
enabled: true,
},
},
)
expect(mockQueueMessage).not.toHaveBeenCalled()
rerender({
sessionId: 'test-session',
lastAssistantMessage: streamingMessage,
lastAssistantText: 'Read by voice mode',
enabled: false,
})
rerender({
sessionId: 'test-session',
lastAssistantMessage: completedMessage,
lastAssistantText: 'Read by voice mode',
enabled: false,
})
expect(mockQueueMessage).not.toHaveBeenCalled()
rerender({
sessionId: 'test-session',
lastAssistantMessage: completedMessage,
lastAssistantText: 'Read by voice mode',
enabled: true,
})
expect(mockQueueMessage).not.toHaveBeenCalled()
})
it('queues a reply that was still streaming when voice mode handed playback back, once it completes', () => {
setup()
const streamingMessage = createMessage('1')
const { rerender } = renderHook(
(props) => useAutoPlayLastResponse(props),
{
initialProps: {
sessionId: 'test-session',
lastAssistantMessage: streamingMessage,
lastAssistantText: 'Test text',
enabled: false,
},
},
)
rerender({
sessionId: 'test-session',
lastAssistantMessage: streamingMessage,
lastAssistantText: 'Test text',
enabled: true,
})
expect(mockQueueMessage).not.toHaveBeenCalled()
rerender({
sessionId: 'test-session',
lastAssistantMessage: createMessage('1', Date.now()),
lastAssistantText: 'Test text',
enabled: true,
})
expect(mockQueueMessage).toHaveBeenCalledTimes(1)
expect(mockQueueMessage).toHaveBeenCalledWith('1', 'Test text')
})
it('queues a reply with its inline think block stripped', () => {
setup()
const streamingMessage = createMessage('1', undefined, 'The answer is ready <think>hidden reasoning</think> and verified')
const { rerender } = renderHook(
(props) => useAutoPlayLastResponse(props),
{
initialProps: {
sessionId: 'test-session',
lastAssistantMessage: streamingMessage,
lastAssistantText: getAssistantText(streamingMessage),
},
},
)
const completedMessage = createMessage('1', Date.now(), 'The answer is ready <think>hidden reasoning</think> and verified')
rerender({
sessionId: 'test-session',
lastAssistantMessage: completedMessage,
lastAssistantText: getAssistantText(completedMessage),
})
expect(mockQueueMessage).toHaveBeenCalledTimes(1)
expect(mockQueueMessage).toHaveBeenCalledWith('1', 'The answer is ready and verified')
})
it('does NOT call queueMessage on mount when last message was already time.completed', () => {
setup()