diff --git a/frontend/src/components/message/FloatingTTSButton.tsx b/frontend/src/components/message/FloatingTTSButton.tsx index 2f67df556..cda4ba53c 100644 --- a/frontend/src/components/message/FloatingTTSButton.tsx +++ b/frontend/src/components/message/FloatingTTSButton.tsx @@ -91,17 +91,17 @@ export function FloatingTTSButton({ messageId, content, isScrolledUp, onSpeakVis : 'TTS controls' const pillAriaLabel = `${pillTitle}. ${autoPlay ? 'Auto-play enabled.' : 'Auto-play disabled.'} hold to toggle auto-play` const buttonToneClasses = showStop - ? 'justify-center px-3 py-1.5 rounded-lg bg-destructive border border-destructive/60 shadow-destructive/30 ring-destructive/20 hover:ring-destructive/40 text-destructive-foreground' + ? 'bg-destructive border border-destructive/60 shadow-destructive/30 ring-destructive/20 hover:ring-destructive/40 text-destructive-foreground' : autoPlay - ? 'justify-center px-3 py-1.5 rounded-lg bg-primary border border-primary/60 shadow-primary/30 ring-primary/20 hover:ring-primary/40 text-primary-foreground' - : 'justify-center px-3 py-1.5 rounded-lg bg-gradient-to-br from-warning to-highlight border border-warning/60 shadow-warning/30 ring-warning/20 hover:ring-warning/40 text-warning-foreground' + ? 'bg-primary border border-primary/60 shadow-primary/30 ring-primary/20 hover:ring-primary/40 text-primary-foreground' + : 'bg-gradient-to-br from-warning to-highlight border border-warning/60 shadow-warning/30 ring-warning/20 hover:ring-warning/40 text-warning-foreground' return ( , + }) + + await screen.findByPlaceholderText('Send a message...') + const slot = screen.getByTestId('composer-trailing-slot') + const action = screen.getByRole('button', { name: 'Read aloud' }) + + expect(inputRow().lastElementChild).toBe(slot) + expect(slot).toContainElement(action) + expect(action.parentElement).toBe(slot) + }) + + it('reserves the mic-sized slot when the action is null', async () => { + await renderPromptInput({ trailingAction: null }) + + await screen.findByPlaceholderText('Send a message...') + const slot = screen.getByTestId('composer-trailing-slot') + + expect(inputRow()).toContainElement(slot) + expect(inputRow().lastElementChild).toBe(slot) + expect(slot).toBeEmptyDOMElement() + expect(slot).toHaveClass('h-11', 'w-11', 'shrink-0', 'md:h-10', 'md:w-10') + }) + + it('omits the slot when no trailing action is provided', async () => { + await renderPromptInput() + + await screen.findByPlaceholderText('Send a message...') + expect(screen.queryByTestId('composer-trailing-slot')).toBeNull() + }) + }) + describe('control sizing', () => { it('keeps the mic at 44px before and after the prompt gains focus on mobile', async () => { await renderPromptInput({ mobile: true }) diff --git a/frontend/src/components/message/PromptInput.config.test.tsx b/frontend/src/components/message/PromptInput.config.test.tsx index 3f2d89a26..f32593da4 100644 --- a/frontend/src/components/message/PromptInput.config.test.tsx +++ b/frontend/src/components/message/PromptInput.config.test.tsx @@ -103,7 +103,7 @@ describe.each([ expect(trigger).not.toHaveClass('bg-highlight') expect(trigger).toHaveClass('size-11') } else { - expect(trigger).toHaveClass('size-9') + expect(trigger).toHaveClass('size-10') } await openConfig(user) diff --git a/frontend/src/components/message/PromptInput.tsx b/frontend/src/components/message/PromptInput.tsx index ec6481ae2..21124cc53 100644 --- a/frontend/src/components/message/PromptInput.tsx +++ b/frontend/src/components/message/PromptInput.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect, useMemo, useImperativeHandle, forwardRef, memo, useCallback, type KeyboardEvent } from 'react' +import { useState, useRef, useEffect, useMemo, useImperativeHandle, forwardRef, memo, useCallback, type KeyboardEvent, type ReactNode } from 'react' import { z } from 'zod' import { useSendPrompt, useInterruptSession, useSendShell, useAgents, useSkills } from '@/hooks/useOpenCode' import { useCommands } from '@/hooks/useCommands' @@ -88,19 +88,19 @@ const KEYBAR_KEYS: Array<{ id: KeybarKey, symbol: string, label: string }> = [ const COMPOSER_MODE_STYLES = { command: { label: 'COMMAND', - frame: 'border-primary/70 ring-1 ring-primary/40 shadow-lg shadow-primary/20', + frame: 'ring-1 ring-primary/40 shadow-lg shadow-primary/20', badge: 'bg-primary text-primary-foreground', key: 'bg-primary text-primary-foreground border-primary', }, mention: { label: 'MENTION', - frame: 'border-success/70 ring-1 ring-success/40 shadow-lg shadow-success/20', + frame: 'ring-1 ring-success/40 shadow-lg shadow-success/20', badge: 'bg-success text-success-foreground', key: 'bg-success text-success-foreground border-success', }, bash: { label: 'BASH', - frame: 'border-warning/70 ring-1 ring-warning/40 shadow-lg shadow-warning/20', + frame: 'ring-1 ring-warning/40 shadow-lg shadow-warning/20', badge: 'bg-warning text-warning-foreground', key: 'bg-warning text-warning-foreground border-warning', }, @@ -132,6 +132,7 @@ interface PromptInputProps { commandActions: PageCommandActions onPromptChange?: (hasContent: boolean) => void voiceConversation?: VoiceConversationFactory + trailingAction?: ReactNode } export const PromptInput = memo(forwardRef(function PromptInput({ @@ -145,7 +146,8 @@ export const PromptInput = memo(forwardRef( onScrollToBottom, commandActions, onPromptChange, - voiceConversation + voiceConversation, + trailingAction }, ref) { const [restoredDraft] = useState(() => useComposerDraftStore.getState().getDraft(sessionID)) const [prompt, setPrompt] = useState(restoredDraft.prompt) @@ -1175,7 +1177,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) }} className={isMobile ? 'min-h-11 min-w-11 px-0 rounded-lg transition-all duration-150 flex items-center justify-center border bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border active:bg-muted-foreground/30 active:scale-95' - : 'p-2 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border flex items-center justify-center bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border'} + : 'size-10 shrink-0 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border flex items-center justify-center bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border'} > @@ -1240,7 +1242,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) : '' return ( -
+
{sessionActivityAnnouncement}
@@ -1308,7 +1310,7 @@ return ( ? "Enter bash command..." : "Send a message..." } - className={`flex-1 min-w-0 bg-muted/50 pl-2 md:pl-3 pr-3 py-2 text-[16px] text-foreground placeholder-muted-foreground focus:outline-none focus:bg-muted/70 resize-none min-h-[40px] max-h-[120px] disabled:opacity-50 disabled:cursor-not-allowed md:text-sm rounded-lg [field-sizing:content] ${ + className={`flex-1 min-w-0 bg-muted/50 pl-2 md:pl-3 pr-3 py-2.5 md:py-2 text-[16px] text-foreground placeholder-muted-foreground focus:outline-none focus:bg-muted/70 resize-none min-h-11 md:min-h-[40px] max-h-[120px] disabled:opacity-50 disabled:cursor-not-allowed md:text-sm rounded-lg [field-sizing:content] ${ isBashMode ? 'border-warning/50 bg-warning/5 focus:bg-warning/10' : isDragging ? 'border-info/50 border-dashed bg-info/5' : '' @@ -1347,6 +1349,14 @@ return ( onChange={handleFileInputChange} /> {showVoiceMic && !hasPromptContent && !showStopButton && renderVoiceMic()} + {trailingAction !== undefined && ( +
+ {trailingAction} +
+ )}
{imageAttachments.length > 0 && ( diff --git a/frontend/src/components/message/SessionConfigMenu.tsx b/frontend/src/components/message/SessionConfigMenu.tsx index 6a5805fd5..a97a1b354 100644 --- a/frontend/src/components/message/SessionConfigMenu.tsx +++ b/frontend/src/components/message/SessionConfigMenu.tsx @@ -585,7 +585,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({ className={cn( getIconToggleButtonClassName(isAnySessionToggleActive), 'relative flex shrink-0 items-center justify-center overflow-hidden p-0', - isMobile ? 'size-11' : 'size-9', + isMobile ? 'size-11' : 'size-10', gutterCardClassName, )} > diff --git a/frontend/src/components/message/VoiceConversationBar.test.tsx b/frontend/src/components/message/VoiceConversationBar.test.tsx index 952da0dfe..80e226ab9 100644 --- a/frontend/src/components/message/VoiceConversationBar.test.tsx +++ b/frontend/src/components/message/VoiceConversationBar.test.tsx @@ -17,6 +17,8 @@ const buildController = ( canStopAgent: false, hasHeldReading: false, isEndpointing: false, + readRepliesAloud: true, + canReadRepliesAloud: true, notice: null, start: vi.fn(), exit: vi.fn(), @@ -25,6 +27,7 @@ const buildController = ( pause: vi.fn(), resume: vi.fn(), stopAgent: vi.fn(), + toggleReadRepliesAloud: vi.fn(), ...overrides, }) @@ -111,6 +114,34 @@ describe('VoiceConversationBar', () => { expect(controller.stopAgent).toHaveBeenCalledTimes(1) }) + it('toggles reading replies aloud from the bar', async () => { + const user = userEvent.setup() + const controller = buildController({ readRepliesAloud: true }) + renderBar(controller) + + const toggle = screen.getByRole('button', { name: 'Read replies aloud' }) + expect(toggle).toHaveAttribute('aria-pressed', 'true') + + await user.click(toggle) + + expect(controller.toggleReadRepliesAloud).toHaveBeenCalledTimes(1) + }) + + it('presents the read-aloud toggle as unpressed when reading is off', () => { + renderBar(buildController({ readRepliesAloud: false })) + + expect(screen.getByRole('button', { name: 'Read replies aloud' })).toHaveAttribute( + 'aria-pressed', + 'false', + ) + }) + + it('hides the read-aloud toggle when text-to-speech is not configured', () => { + renderBar(buildController({ canReadRepliesAloud: false })) + + expect(screen.queryByRole('button', { name: 'Read replies aloud' })).toBeNull() + }) + it('shows the approval control instead of pause while the session waits for approval', async () => { const user = userEvent.setup() const onViewApproval = vi.fn() @@ -192,18 +223,39 @@ describe('VoiceConversationBar', () => { renderBar( buildController({ phase: 'paused', - label: 'Microphone access denied. Please allow microphone permissions.', + label: 'Microphone problem', + notice: 'Microphone access denied. Please allow microphone permissions.', hint: 'Allow microphone access, then tap to retry', orbLabel: 'Resume voice conversation', }), ) + expect(screen.getByText('Microphone problem')).toBeInTheDocument() expect( screen.getByText('Microphone access denied. Please allow microphone permissions.'), ).toBeInTheDocument() expect(screen.getByText('Allow microphone access, then tap to retry')).toBeInTheDocument() }) + it('offers the edit control while paused with a failed message', async () => { + const user = userEvent.setup() + const controller = buildController({ + phase: 'paused', + label: "Couldn't send your message", + hint: 'Tap to resend', + notice: "Couldn't send: network down", + canEditInTextBox: true, + orbLabel: 'Resend message', + }) + renderBar(controller) + + expect(screen.queryByRole('button', { name: 'Exit voice conversation' })).toBeNull() + expect(screen.getByRole('button', { name: 'Resend message' })).toBeInTheDocument() + await user.click(screen.getByRole('button', { name: 'Edit in text box' })) + + expect(controller.editInTextBox).toHaveBeenCalledTimes(1) + }) + it('shows the notice when there is one and keeps the reserved hint line empty', () => { renderBar( buildController({ diff --git a/frontend/src/components/message/VoiceConversationBar.tsx b/frontend/src/components/message/VoiceConversationBar.tsx index 69e929896..b6f24aa12 100644 --- a/frontend/src/components/message/VoiceConversationBar.tsx +++ b/frontend/src/components/message/VoiceConversationBar.tsx @@ -1,4 +1,4 @@ -import { Pause, Pencil, Play, X } from 'lucide-react' +import { Pause, Pencil, Play, Volume2, VolumeX, X } from 'lucide-react' import type { ReactNode } from 'react' import { VoiceConversationOrb } from '@/components/message/VoiceConversationOrb' import { Button } from '@/components/ui/button' @@ -7,9 +7,16 @@ import { SquareFill } from '@/components/ui/square-fill' import type { VoiceConversationController } from '@/hooks/useVoiceConversation' import { cn } from '@/lib/utils' +const BAR_ICON_BUTTON_SIZE_CLASS = 'flex size-11 shrink-0 items-center justify-center p-0' + const BAR_ICON_BUTTON_CLASS = cn( getIconToggleButtonClassName(false), - 'flex size-11 shrink-0 items-center justify-center p-0', + BAR_ICON_BUTTON_SIZE_CLASS, +) + +const BAR_ICON_BUTTON_ACTIVE_CLASS = cn( + getIconToggleButtonClassName(true), + BAR_ICON_BUTTON_SIZE_CLASS, ) const RESERVED_LINE_CLASS = 'h-4 w-full truncate text-center leading-4' @@ -17,18 +24,20 @@ const RESERVED_LINE_CLASS = 'h-4 w-full truncate text-center leading-4' interface BarIconButtonProps { label: string onClick: () => void + pressed?: boolean children: ReactNode } -function BarIconButton({ label, onClick, children }: BarIconButtonProps) { +function BarIconButton({ label, onClick, pressed, children }: BarIconButtonProps) { return ( @@ -55,6 +64,8 @@ export function VoiceConversationBar({ canEditInTextBox, canStopAgent, hasHeldReading, + readRepliesAloud, + canReadRepliesAloud, notice, } = controller @@ -99,7 +110,16 @@ export function VoiceConversationBar({
-
+
+ {canReadRepliesAloud ? ( + + {readRepliesAloud ? : } + + ) : null} {hasPendingApproval ? ( )} {minimizedForm && ( @@ -965,7 +969,7 @@ export function SessionDetail() { onAskSideQuestion={() => handleAskSideQuestion('')} /> )} -
+
@@ -991,6 +995,7 @@ export function SessionDetail() { onScrollToBottom={scrollToBottom} commandActions={commandActions} onPromptChange={setHasPromptContent} + trailingAction={composerTrailingAction} />
diff --git a/frontend/src/pages/__tests__/SessionDetail.scroll-floating.test.tsx b/frontend/src/pages/__tests__/SessionDetail.scroll-floating.test.tsx index 4c9a853c3..d68bd19e8 100644 --- a/frontend/src/pages/__tests__/SessionDetail.scroll-floating.test.tsx +++ b/frontend/src/pages/__tests__/SessionDetail.scroll-floating.test.tsx @@ -5,11 +5,14 @@ import { installElementScrollMetrics, installMatchMedia, installResizeObserver, + installSpeechSynthesis, installWindowSize, } from '@/test/browserFakes' -import { makeUserMessage } from '@/test/fixtures/api' +import { makeSettingsResponse, makeUserMessage, makeUserPreferences } from '@/test/fixtures/api' import { promptTextarea } from '@/test/promptInput' import { renderSessionPage } from '@/test/sessionPage' +import { DEFAULT_TTS_CONFIG } from '@opencode-manager/shared/schemas' +import type { SessionMessageAssistant } from '@opencode-manager/shared/opencode' import type { ElementScrollMetricsFake, ResizeObserverFake } from '@/test/browserFakes' import type { FetchRouteResult } from '@/test/fetchFake' @@ -79,7 +82,7 @@ describe('SessionDetail scroll and composer affordances', () => { scrollUpInTranscript() - expect(screen.getByRole('button', { name: 'Jump to latest' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: 'Back to latest' })).toBeInTheDocument() }) it('keeps jump to latest visible while the composer has content', async () => { @@ -90,7 +93,7 @@ describe('SessionDetail scroll and composer affordances', () => { scrollUpInTranscript() expect(await screen.findByRole('button', { name: 'Clear' })).toBeInTheDocument() - expect(screen.getByRole('button', { name: 'Jump to latest' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: 'Back to latest' })).toBeInTheDocument() }) it('hides jump to latest while the transcript is at the bottom', async () => { @@ -98,7 +101,7 @@ describe('SessionDetail scroll and composer affordances', () => { await waitForComposer() scrollMetrics.setScrollTop(transcriptContainer(), TRANSCRIPT_SCROLL_HEIGHT) - expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Back to latest' })).not.toBeInTheDocument() }) it('scrolls the transcript back to the bottom when jump to latest is clicked', async () => { @@ -106,10 +109,10 @@ describe('SessionDetail scroll and composer affordances', () => { await waitForComposer() scrollUpInTranscript() - fireEvent.click(screen.getByRole('button', { name: 'Jump to latest' })) + fireEvent.click(screen.getByRole('button', { name: 'Back to latest' })) await waitFor(() => { - expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Back to latest' })).not.toBeInTheDocument() }) expect(transcriptScrollTop()).toBe(TRANSCRIPT_SCROLL_HEIGHT) }) @@ -128,6 +131,59 @@ describe('SessionDetail scroll and composer affordances', () => { }) }) + it('places the speaker button inside the composer input row', async () => { + installSpeechSynthesis() + const assistantReply: SessionMessageAssistant = { + id: 'msg_reply', + type: 'assistant', + agent: 'build', + model: { providerID: 'anthropic', id: 'claude-sonnet-4-5' }, + content: [{ type: 'text', text: 'A reply' }], + time: { created: 1, completed: 2 }, + } + const preferences = makeUserPreferences({ tts: { ...DEFAULT_TTS_CONFIG, enabled: true, provider: 'builtin' } }) + + renderSessionPage({ + messages: [assistantReply], + extraRoutes: [ + { method: 'GET', path: '/api/settings', respond: () => ({ json: makeSettingsResponse({ preferences }) }) }, + ], + }) + await waitForComposer() + + const speaker = await screen.findByRole('button', { name: /play latest reply/i }) + const slot = screen.getByTestId('composer-trailing-slot') + + expect(slot).toContainElement(speaker) + expect(screen.getByTestId('composer-input-row')).toContainElement(slot) + }) + + it('leaves the speaker button out of the composer on mobile', async () => { + installWindowSize(480) + installSpeechSynthesis() + const assistantReply: SessionMessageAssistant = { + id: 'msg_reply', + type: 'assistant', + agent: 'build', + model: { providerID: 'anthropic', id: 'claude-sonnet-4-5' }, + content: [{ type: 'text', text: 'A reply' }], + time: { created: 1, completed: 2 }, + } + const preferences = makeUserPreferences({ tts: { ...DEFAULT_TTS_CONFIG, enabled: true, provider: 'builtin' } }) + + renderSessionPage({ + messages: [assistantReply], + extraRoutes: [ + { method: 'GET', path: '/api/settings', respond: () => ({ json: makeSettingsResponse({ preferences }) }) }, + ], + }) + await waitForComposer() + await screen.findByText('A reply') + + expect(screen.queryByTestId('composer-trailing-slot')).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: /play latest reply/i })).not.toBeInTheDocument() + }) + it.each(VIEWPORTS)('interrupts the active session from the composer stop button on $name', async ({ width }) => { installWindowSize(width) const { fetchFake } = renderSessionPage({ activeSessions: ['session-1'] }) diff --git a/frontend/src/stores/voiceConversationStore.ts b/frontend/src/stores/voiceConversationStore.ts new file mode 100644 index 000000000..15808b2dd --- /dev/null +++ b/frontend/src/stores/voiceConversationStore.ts @@ -0,0 +1,20 @@ +import { create } from 'zustand' +import { persist } from 'zustand/middleware' + +interface VoiceConversationStore { + readRepliesAloud: boolean + setReadRepliesAloud: (readRepliesAloud: boolean) => void +} + +export const useVoiceConversationStore = create()( + persist( + (set) => ({ + readRepliesAloud: true, + setReadRepliesAloud: (readRepliesAloud: boolean) => set({ readRepliesAloud }), + }), + { + name: 'opencode-voice-conversation', + partialize: (state) => ({ readRepliesAloud: state.readRepliesAloud }), + }, + ), +) diff --git a/frontend/src/test/promptInput.tsx b/frontend/src/test/promptInput.tsx index 3862ab983..23071286f 100644 --- a/frontend/src/test/promptInput.tsx +++ b/frontend/src/test/promptInput.tsx @@ -52,6 +52,7 @@ export interface PromptInputFixture { onPromptChange?: (hasContent: boolean) => void onSuggestionsOpenChange?: (open: boolean) => void onVoiceConversationActiveChange?: (active: boolean) => void + trailingAction?: ReactNode } export function makeAgent(overrides: Partial & { id: string }): AgentInfo { @@ -153,6 +154,7 @@ export async function renderPromptInput(fixture: PromptInputFixture = {}) { onSuggestionsOpenChange={active.onSuggestionsOpenChange} onVoiceConversationActiveChange={active.onVoiceConversationActiveChange} voiceConversation={active.voiceConversation} + trailingAction={active.trailingAction} ref={active.promptRef} /> diff --git a/frontend/src/test/test-utils.tsx b/frontend/src/test/test-utils.tsx index ac753dc79..335a78e8e 100644 --- a/frontend/src/test/test-utils.tsx +++ b/frontend/src/test/test-utils.tsx @@ -22,6 +22,8 @@ export function createVoiceConversationControllerMock( canStopAgent: false, hasHeldReading: false, isEndpointing: false, + readRepliesAloud: true, + canReadRepliesAloud: true, notice: null, start: vi.fn(), exit: vi.fn(), @@ -30,6 +32,7 @@ export function createVoiceConversationControllerMock( pause: vi.fn(), resume: vi.fn(), stopAgent: vi.fn(), + toggleReadRepliesAloud: vi.fn(), ...overrides, } } diff --git a/shared/src/opencode/voiceConversation.ts b/shared/src/opencode/voiceConversation.ts index 697b2d765..f5a1722cf 100644 --- a/shared/src/opencode/voiceConversation.ts +++ b/shared/src/opencode/voiceConversation.ts @@ -18,7 +18,7 @@ export type VoicePhase = export type VoicePauseReason = 'user' | 'background' | 'no-speech' | 'error' -export type VoiceFailureSource = 'capture' | 'send' | 'playback' +export type VoiceFailureSource = 'capture' | 'send' | 'playback' | 'transcription' export type VoiceSessionStatus = SessionStatus['type'] @@ -46,6 +46,7 @@ export type VoiceConversationEvent = | { type: 'turn-sent'; baselineId: string | null } | { type: 'turn-started'; baselineId: string | null } | { type: 'send-failed'; message: string } + | { type: 'resend'; busy: boolean; baselineId: string | null } | { type: 'status'; busy: boolean } | { type: 'speak-start' } | { type: 'speech-ended' } @@ -83,6 +84,7 @@ export interface VoiceConversationLabelInput { error?: string | null failureSource?: VoiceFailureSource | null isStartingCapture?: boolean + canResend?: boolean } export function reduceVoiceConversation( @@ -129,6 +131,25 @@ export function reduceVoiceConversation( error: event.message, failureSource: 'send', } + case 'resend': + if (state.phase !== 'paused') return state + return event.busy + ? { + ...state, + phase: 'working', + sawBusy: true, + baselineId: event.baselineId, + pauseReason: null, + error: null, + failureSource: null, + } + : { + ...state, + phase: 'sending', + pauseReason: null, + error: null, + failureSource: null, + } case 'status': if (state.phase !== 'working') return state if (!event.busy || state.sawBusy) return state @@ -267,7 +288,7 @@ export function isVoiceTurnComplete(input: VoiceTurnCompletionInput): boolean { } export function voiceConversationLabel(input: VoiceConversationLabelInput): string { - const { phase, pauseReason, pendingApproval, error, isStartingCapture } = input + const { phase, pauseReason, pendingApproval, error, failureSource, isStartingCapture } = input switch (phase) { case 'listening': @@ -282,7 +303,13 @@ export function voiceConversationLabel(input: VoiceConversationLabelInput): stri return isStartingCapture ? 'Starting…' : 'Adding to queue' case 'paused': if (pauseReason === 'no-speech') return "Didn't catch that" - if (pauseReason === 'error') return error?.trim() || 'Something went wrong' + if (pauseReason === 'error') { + if (failureSource === 'send') return "Couldn't send your message" + if (failureSource === 'capture') return 'Microphone problem' + if (failureSource === 'playback') return "Couldn't read the reply" + if (failureSource === 'transcription') return "Transcription isn't working" + return error?.trim() || 'Something went wrong' + } return 'Paused' case 'off': return '' @@ -318,9 +345,10 @@ export function voiceConversationHint(input: VoiceConversationLabelInput): strin case 'paused': if (pauseReason === 'no-speech') return 'Tap to talk' if (pauseReason === 'error') { - return failureSource === 'capture' - ? 'Allow microphone access, then tap to retry' - : 'Tap to retry' + if (failureSource === 'capture') return 'Allow microphone access, then tap to retry' + if (failureSource === 'send') return input.canResend ? 'Tap to resend' : 'Tap to retry' + if (failureSource === 'transcription') return 'Tap to try again' + return 'Tap to retry' } return isPlaybackPaused ? 'Tap to continue' : 'Tap to talk' case 'off':