feat(schedules): add read aloud playback to scheduled run reports

This commit is contained in:
Chris Scott committed 2026-10-04 12:42:31 -04:00
1 parent 03500affe8
commit 092add1eb1
5 files changed
+107 -43

No files matched your search

+1 -1
View File
@@ -152,7 +152,7 @@ Each schedule stores a run history panel with:
- **Status** - Running, completed, failed, or cancelled (a running run can be stopped with **Cancel run**)
- **Trigger source** - Manual or scheduled
- **Log output** - Execution metadata and captured results
- **Assistant output** - Rendered markdown
- **Assistant output** - Rendered markdown, with a **Read aloud** button when Text-to-Speech is enabled
- **Errors** - Failure details when a run does not complete
This makes recurring jobs easy to review without digging through raw session data first.
@@ -1,5 +1,5 @@
import { memo, useCallback, useMemo, useState } from 'react'
import { Pencil, Loader2, Volume2, VolumeX } from 'lucide-react'
import { Pencil, Loader2 } from 'lucide-react'
import { assistantText } from '@opencode-manager/shared/opencode'
import type {
PromptAgentAttachment,
@@ -20,8 +20,8 @@ import { StepFileChanges } from './StepFileChanges'
import { UserMessageActionButtons } from './UserMessageActionButtons'
import { EditableUserMessage, ClickableUserMessage } from './EditableUserMessage'
import { useSettings } from '@/hooks/useSettings'
import { useTTS } from '@/hooks/useTTS'
import { CopyButton } from '@/components/ui/copy-button'
import { TTSButton } from '@/components/ui/tts-button'
import { backgroundShellID, collectBackgroundParts, type ShellNoticeOutcome } from '@/lib/backgroundWork'
function getMessageText(message: SessionMessageInfo): string {
@@ -147,46 +147,6 @@ function UserAttachments({ files: attachedFiles, agents: attachedAgents, skills:
)
}
interface TTSButtonProps {
messageId: string
content: string
}
function TTSButton({ messageId, content }: TTSButtonProps) {
const { speakMessage, stop, isEnabled, isPlaying, isLoading, activeMessageId } = useTTS()
if (!isEnabled || !content.trim()) {
return null
}
const isThisPlaying = (isPlaying || isLoading) && activeMessageId === messageId
const handleClick = () => {
if (isThisPlaying) {
stop()
} else {
speakMessage(messageId, content)
}
}
return (
<button
onClick={handleClick}
className={`p-1.5 rounded ${isThisPlaying ? 'bg-destructive/20 text-destructive hover:bg-destructive/30' : 'bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground'}`}
title={isThisPlaying ? 'Stop playback' : 'Read aloud'}
disabled={isLoading && !isThisPlaying}
>
{isLoading && isThisPlaying ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : isThisPlaying ? (
<VolumeX className="w-4 h-4" />
) : (
<Volume2 className="w-4 h-4" />
)}
</button>
)
}
function MessageDivider({ label }: { label: string }) {
return (
<div className="flex items-center gap-2 my-1 text-xs text-muted-foreground">
@@ -9,6 +9,20 @@ import type { ScheduleRun } from '@opencode-manager/shared/types'
const mocks = vi.hoisted(() => ({
getRepo: vi.fn(),
useMarkScheduleRunViewed: vi.fn(),
useTTS: vi.fn(),
}))
const tts = {
speakMessage: vi.fn(),
stop: vi.fn(),
isEnabled: true,
isPlaying: false,
isLoading: false,
activeMessageId: null as string | null,
}
vi.mock('@/hooks/useTTS', () => ({
useTTS: mocks.useTTS,
}))
const apiMocks = vi.hoisted(() => ({
@@ -109,6 +123,47 @@ function clickLink(name: string) {
return event
}
beforeEach(() => {
mocks.useTTS.mockReturnValue(tts)
})
describe('RunDetailPanel read aloud', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.useMarkScheduleRunViewed.mockReturnValue({ mutate: vi.fn(), isPending: false })
mocks.getRepo.mockResolvedValue(repo)
})
it('reads the run output aloud', () => {
mocks.useTTS.mockReturnValue(tts)
renderPanel()
fireEvent.click(screen.getByRole('button', { name: 'Read aloud' }))
expect(tts.speakMessage).toHaveBeenCalledWith('schedule-run-1', run.responseText)
})
it('stops playback when this run is playing', () => {
mocks.useTTS.mockReturnValue({ ...tts, isPlaying: true, activeMessageId: 'schedule-run-1' })
renderPanel()
fireEvent.click(screen.getByRole('button', { name: 'Stop playback' }))
expect(tts.stop).toHaveBeenCalled()
})
it('hides the button without output or when TTS is disabled', () => {
mocks.useTTS.mockReturnValue(tts)
const empty = renderPanel({ ...run, responseText: null })
expect(screen.queryByRole('button', { name: 'Read aloud' })).not.toBeInTheDocument()
empty.unmount()
mocks.useTTS.mockReturnValue({ ...tts, isEnabled: false })
renderPanel()
expect(screen.queryByRole('button', { name: 'Read aloud' })).not.toBeInTheDocument()
})
})
describe('RunDetailPanel local link handling', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'
import { Button } from '@/components/ui/button'
import { TTSButton } from '@/components/ui/tts-button'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { ScheduleRunMarkdown } from '@/components/schedules/ScheduleRunMarkdown'
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
@@ -102,6 +103,7 @@ export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancel
<TabsTrigger value="error" disabled={!activeRun.errorText} className="rounded-none border-b-2 border-transparent px-3 py-2 text-xs data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none">{activeRun.status === 'cancelled' ? 'Details' : 'Error'}</TabsTrigger>
</TabsList>
<div className="flex items-center gap-2 py-1">
{activeRun.responseText && <TTSButton messageId={`schedule-run-${activeRun.id}`} content={activeRun.responseText} />}
{(sessionId || opensNewRepoSession) && (
<Button variant="outline" size="sm" className="h-7 text-xs" onClick={() => { void handleOpenSession() }} disabled={openingSession || (opensNewRepoSession && !repo)}>
{openingSession ? <Loader2 className="mr-1 h-3.5 w-3.5 animate-spin" /> : null}
+47
View File
@@ -0,0 +1,47 @@
import { Loader2, Volume2, VolumeX } from 'lucide-react'
import { cn } from '@/lib/utils'
import { useTTS } from '@/hooks/useTTS'
interface TTSButtonProps {
messageId: string
content: string
className?: string
}
export function TTSButton({ messageId, content, className }: TTSButtonProps) {
const { speakMessage, stop, isEnabled, isPlaying, isLoading, activeMessageId } = useTTS()
if (!isEnabled || !content.trim()) {
return null
}
const isThisPlaying = (isPlaying || isLoading) && activeMessageId === messageId
const label = isThisPlaying ? 'Stop playback' : 'Read aloud'
const handleClick = () => {
if (isThisPlaying) {
stop()
} else {
speakMessage(messageId, content)
}
}
return (
<button
type="button"
onClick={handleClick}
className={cn('p-1.5 rounded', isThisPlaying ? 'bg-destructive/20 text-destructive hover:bg-destructive/30' : 'bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground', className)}
title={label}
aria-label={label}
disabled={isLoading && !isThisPlaying}
>
{isLoading && isThisPlaying ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : isThisPlaying ? (
<VolumeX className="w-4 h-4" />
) : (
<Volume2 className="w-4 h-4" />
)}
</button>
)
}