Skip to content
8 changes: 4 additions & 4 deletions frontend/src/components/message/FloatingTTSButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<button
onPointerDown={handlePointerDown}
onPointerUp={handlePointerUp}
onPointerLeave={handlePointerLeave}
className={`flex items-center transition-all duration-200 shadow-md backdrop-blur-md ring-1 ${buttonToneClasses} ${isLongPressVisual ? 'scale-95 opacity-80' : 'active:scale-95 hover:scale-105'} ${!hasContent && !autoPlay ? 'opacity-50 cursor-not-allowed' : ''}`}
className={`flex h-full w-full items-center justify-center rounded-lg transition-all duration-200 shadow-md ring-1 ${buttonToneClasses} ${isLongPressVisual ? 'scale-95 opacity-80' : 'active:scale-95'} ${!hasContent && !autoPlay ? 'opacity-50 cursor-not-allowed' : ''}`}
title={pillTitle}
aria-label={pillAriaLabel}
disabled={!hasContent && !autoPlay}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/message/PromptInput.command.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ describe('PromptInput command submission', () => {
const tokens = frame.className.split(/\s+/)

expect(tokens).not.toContain('transition-all')
expect(tokens.some((token) => token.startsWith('backdrop-blur'))).toBe(false)
expect(tokens.some((token) => token.includes('backdrop-blur'))).toBe(false)
expect(tokens.some((token) => token.startsWith('opacity-'))).toBe(false)
expect(tokens).toContain('before:backdrop-blur-md')
expect(tokens.some((token) => token.startsWith('before:bg-'))).toBe(false)
})

describe('mobile keybar', () => {
Expand Down
37 changes: 36 additions & 1 deletion frontend/src/components/message/PromptInput.composer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('PromptInput composer layout', () => {

expect(await screen.findByRole('button', { name: /^Session config/ })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Scroll to bottom' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Back to latest' })).not.toBeInTheDocument()
})

it('keeps the voice button and the session config in the input row', async () => {
Expand Down Expand Up @@ -308,6 +308,41 @@ describe('PromptInput composer layout', () => {
})
})

describe('trailing action slot', () => {
it('renders the trailing action as the last child of the input row', async () => {
await renderPromptInput({
trailingAction: <button type="button" aria-label="Read aloud">Read</button>,
})

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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 18 additions & 8 deletions frontend/src/components/message/PromptInput.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -132,6 +132,7 @@ interface PromptInputProps {
commandActions: PageCommandActions
onPromptChange?: (hasContent: boolean) => void
voiceConversation?: VoiceConversationFactory
trailingAction?: ReactNode
}

export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(function PromptInput({
Expand All @@ -145,7 +146,8 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
onScrollToBottom,
commandActions,
onPromptChange,
voiceConversation
voiceConversation,
trailingAction
}, ref) {
const [restoredDraft] = useState(() => useComposerDraftStore.getState().getDraft(sessionID))
const [prompt, setPrompt] = useState(restoredDraft.prompt)
Expand Down Expand Up @@ -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'}
>
<Mic className={isMobile ? 'w-6 h-6' : 'w-5 h-5'} />
</button>
Expand Down Expand Up @@ -1240,7 +1242,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
: ''

return (
<div className={`relative isolate border-t md:border border-border dark:border-border/30 rounded-t-xl md:rounded-xl p-2 pb-7 md:p-3 md:mb-3 w-full before:pointer-events-none before:absolute before:-inset-px before:-z-10 before:rounded-t-xl md:before:rounded-xl before:bg-background md:before:bg-background/95 before:backdrop-blur-md before:content-[''] ${hasPendingPermissionForSession ? 'border-highlight/50 ring-1 ring-highlight/30' : composerModeStyle?.frame ?? ''} ${isTakeoverOpen ? 'z-[60]' : ''}`}>
<div className={`relative isolate rounded-t-xl md:rounded-xl p-2 pb-7 md:p-3 md:mb-3 w-full ${hasPendingPermissionForSession ? 'ring-1 ring-highlight/30' : composerModeStyle?.frame ?? ''} ${isTakeoverOpen ? 'z-[60]' : ''}`}>
<div role="status" aria-live="polite" className="sr-only">
{sessionActivityAnnouncement}
</div>
Expand Down Expand Up @@ -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' : ''
Expand Down Expand Up @@ -1347,6 +1349,14 @@ return (
onChange={handleFileInputChange}
/>
{showVoiceMic && !hasPromptContent && !showStopButton && renderVoiceMic()}
{trailingAction !== undefined && (
<div
data-testid="composer-trailing-slot"
className="flex h-11 w-11 shrink-0 items-center justify-center md:h-10 md:w-10 @min-[86rem]/composer:absolute @min-[86rem]/composer:bottom-0 @min-[86rem]/composer:left-full @min-[86rem]/composer:ml-4 @min-[86rem]/composer:h-10 @min-[86rem]/composer:w-10"
>
{trailingAction}
</div>
)}
</div>

{imageAttachments.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/message/SessionConfigMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)}
>
Expand Down
54 changes: 53 additions & 1 deletion frontend/src/components/message/VoiceConversationBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const buildController = (
canStopAgent: false,
hasHeldReading: false,
isEndpointing: false,
readRepliesAloud: true,
canReadRepliesAloud: true,
notice: null,
start: vi.fn(),
exit: vi.fn(),
Expand All @@ -25,6 +27,7 @@ const buildController = (
pause: vi.fn(),
resume: vi.fn(),
stopAgent: vi.fn(),
toggleReadRepliesAloud: vi.fn(),
...overrides,
})

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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({
Expand Down
30 changes: 25 additions & 5 deletions frontend/src/components/message/VoiceConversationBar.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -7,28 +7,37 @@ 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'

interface BarIconButtonProps {
label: string
onClick: () => void
pressed?: boolean
children: ReactNode
}

function BarIconButton({ label, onClick, children }: BarIconButtonProps) {
function BarIconButton({ label, onClick, pressed, children }: BarIconButtonProps) {
return (
<button
type="button"
aria-label={label}
aria-pressed={pressed}
title={label}
onMouseDown={(event) => event.preventDefault()}
onClick={onClick}
className={BAR_ICON_BUTTON_CLASS}
className={pressed ? BAR_ICON_BUTTON_ACTIVE_CLASS : BAR_ICON_BUTTON_CLASS}
>
{children}
</button>
Expand All @@ -55,6 +64,8 @@ export function VoiceConversationBar({
canEditInTextBox,
canStopAgent,
hasHeldReading,
readRepliesAloud,
canReadRepliesAloud,
notice,
} = controller

Expand Down Expand Up @@ -99,7 +110,16 @@ export function VoiceConversationBar({
<div className="flex justify-center">
<VoiceConversationOrb phase={phase} label={orbLabel} onPress={controller.tapOrb} />
</div>
<div className="flex justify-end">
<div className="flex items-center justify-end gap-1">
{canReadRepliesAloud ? (
<BarIconButton
label="Read replies aloud"
onClick={controller.toggleReadRepliesAloud}
pressed={readRepliesAloud}
>
{readRepliesAloud ? <Volume2 className="size-5" /> : <VolumeX className="size-5" />}
</BarIconButton>
) : null}
{hasPendingApproval ? (
<Button
type="button"
Expand Down
Loading