mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
129 lines
6.8 KiB
TypeScript
129 lines
6.8 KiB
TypeScript
import { useState } from 'react'
|
|
import { useNavigate } from 'react-router-dom'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
|
import { ScheduleRunMarkdown } from '@/components/schedules/ScheduleRunMarkdown'
|
|
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
|
|
import { getRepo } from '@/api/repos'
|
|
import { getWorkspaceFilePath } from '@/lib/markdownLinks'
|
|
import { getSessionPath } from '@/lib/navigation'
|
|
import { getRepoDisplayName } from '@/lib/utils'
|
|
import { Loader2 } from 'lucide-react'
|
|
import type { ScheduleRun } from '@opencode-manager/shared/types'
|
|
|
|
interface RunDetailPanelProps {
|
|
repoId: number
|
|
activeRun: ScheduleRun | null
|
|
selectedRunLoading: boolean
|
|
onCancelRun: () => void
|
|
cancelRunPending: boolean
|
|
}
|
|
|
|
export function RunDetailPanel({ repoId, activeRun, selectedRunLoading, onCancelRun, cancelRunPending }: RunDetailPanelProps) {
|
|
const navigate = useNavigate()
|
|
const [selectedFilePath, setSelectedFilePath] = useState<string | null>(null)
|
|
const { data: repo, isPending: repoPending, isError: repoError, refetch: refetchRepo } = useQuery({
|
|
queryKey: ['repo', repoId],
|
|
queryFn: () => getRepo(repoId),
|
|
})
|
|
|
|
const handleOpenLocalPath = (linkPath: string) => {
|
|
if (!repo) return
|
|
setSelectedFilePath(getWorkspaceFilePath(linkPath, {
|
|
directory: activeRun?.worktreePath ?? repo.fullPath,
|
|
repoFullPath: repo.fullPath,
|
|
repoLocalPath: repo.localPath,
|
|
}))
|
|
}
|
|
|
|
if (selectedRunLoading && !activeRun) {
|
|
return (
|
|
<div className="flex h-full items-center justify-center">
|
|
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!activeRun) {
|
|
return <div className="flex h-full items-center justify-center text-sm text-muted-foreground">Select a run to inspect logs and output.</div>
|
|
}
|
|
|
|
const { sessionId } = activeRun
|
|
|
|
return (
|
|
<>
|
|
<Tabs key={`${activeRun.id}-${String(activeRun.responseText ? 'response' : activeRun.errorText ? 'error' : 'log')}`} defaultValue={activeRun.responseText ? 'response' : activeRun.errorText ? 'error' : 'log'} className="flex min-h-0 flex-1 flex-col overflow-hidden">
|
|
<div className="flex items-center justify-center gap-2 px-2 py-1.5">
|
|
<TabsList className="h-auto gap-0 rounded-none border-0 bg-transparent p-0">
|
|
<TabsTrigger value="log" className="rounded-none border-b-2 border-transparent px-3 py-1.5 text-xs data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none">Log</TabsTrigger>
|
|
<TabsTrigger value="response" disabled={!activeRun.responseText} className="rounded-none border-b-2 border-transparent px-3 py-1.5 text-xs data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none">Assistant Output</TabsTrigger>
|
|
<TabsTrigger value="error" disabled={!activeRun.errorText} className="rounded-none border-b-2 border-transparent px-3 py-1.5 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>
|
|
{(activeRun.status === 'running' || activeRun.sessionId) && (
|
|
<div className="flex items-center justify-between gap-2 px-3 py-2">
|
|
<div className="flex items-center gap-2">
|
|
{sessionId && (
|
|
<Button variant="outline" size="sm" onClick={() => navigate(getSessionPath(repoId, sessionId))}>
|
|
Open session
|
|
</Button>
|
|
)}
|
|
</div>
|
|
{activeRun.status === 'running' && (
|
|
<Button variant="outline" size="sm" onClick={onCancelRun} disabled={cancelRunPending}>
|
|
{cancelRunPending ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
|
Cancel run
|
|
</Button>
|
|
)}
|
|
</div>
|
|
)}
|
|
<TabsContent value="log" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 py-3 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
|
{selectedRunLoading && !activeRun ? (
|
|
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
|
) : (
|
|
<pre className="whitespace-pre-wrap break-words text-sm font-mono leading-6">{activeRun.logText ?? 'No log text captured.'}</pre>
|
|
)}
|
|
</TabsContent>
|
|
<TabsContent value="response" className="mt-0 min-h-0 flex-1 flex flex-col overflow-hidden">
|
|
{selectedRunLoading && !activeRun ? (
|
|
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
|
) : activeRun.responseText ? (
|
|
<>
|
|
{repoPending && (
|
|
<div role="status" className="px-3 pt-2 text-xs text-muted-foreground">Loading repository details for local links.</div>
|
|
)}
|
|
{repoError && (
|
|
<div role="alert" className="flex items-center gap-2 px-3 pt-2 text-xs text-destructive">
|
|
<span>Could not load repository details for local links.</span>
|
|
<Button variant="outline" size="sm" onClick={() => { void refetchRepo() }}>Retry</Button>
|
|
</div>
|
|
)}
|
|
<div className="min-h-0 flex-1 overflow-y-auto px-3 py-2 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
|
<ScheduleRunMarkdown content={activeRun.responseText} onOpenLocalPath={handleOpenLocalPath} />
|
|
</div>
|
|
</>
|
|
) : (
|
|
<div className="p-3"><pre className="whitespace-pre-wrap break-words text-sm font-mono leading-6">No assistant output captured.</pre></div>
|
|
)}
|
|
</TabsContent>
|
|
<TabsContent value="error" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 py-3 xl:[mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
|
{selectedRunLoading && !activeRun ? (
|
|
<div className="flex items-center justify-center p-4"><Loader2 className="h-6 w-6 animate-spin text-muted-foreground" /></div>
|
|
) : (
|
|
<pre className={`whitespace-pre-wrap break-words text-sm font-mono leading-6 ${activeRun.status === 'cancelled' ? 'text-muted-foreground' : 'text-destructive'}`}>{activeRun.errorText ?? 'No error recorded.'}</pre>
|
|
)}
|
|
</TabsContent>
|
|
</Tabs>
|
|
<FileBrowserSheet
|
|
isOpen={selectedFilePath !== null}
|
|
onClose={() => setSelectedFilePath(null)}
|
|
basePath={repo?.localPath}
|
|
repoName={repo ? getRepoDisplayName(repo) : undefined}
|
|
repoId={repoId}
|
|
initialSelectedFile={selectedFilePath ?? undefined}
|
|
/>
|
|
</>
|
|
)
|
|
}
|