import { useEffect, useState } from "react" import { ChevronRightIcon, ExternalLinkIcon } from "lucide-react" import { toast } from "sonner" import type { Fix } from "@workspace/types" import { Alert, AlertDescription } from "@workspace/ui/components/alert" import { Button } from "@workspace/ui/components/button" import { Card, CardContent, CardHeader, CardTitle, CardAction } from "@workspace/ui/components/card" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@workspace/ui/components/collapsible" import { Input } from "@workspace/ui/components/input" import { Separator } from "@workspace/ui/components/separator" import { Textarea } from "@workspace/ui/components/textarea" import { useItemAction } from "@/lib/api" import { AgentMessage } from "./agent-message" import { DiffView } from "./diff-view" import { Screenshots } from "./screenshots" /** The fix, as the latest thing in the thread: live while it runs, then the diff and the approval. */ export function FixPanel({ itemId, fix }: { itemId: number; fix: Fix }) { const act = useItemAction(itemId) const [title, setTitle] = useState(fix.title) const [body, setBody] = useState(fix.body) // The agent proposes the text; take its latest proposal unless it was edited here. useEffect(() => setTitle(fix.title), [fix.title]) useEffect(() => setBody(fix.body), [fix.body]) if (fix.status === "working") { return fix.live ? ( ) : (

Preparing checkouts of {fix.repos.join(", ")} for the fix

) } const discard = ( ) if (fix.status === "failed") { return ( The fix in {fix.repos.join(", ")} failed {discard}

{fix.error}

) } const prRepos = fix.diffs.filter((d) => d.canOpenPr).map((d) => d.repo) const patchRepos = fix.diffs.filter((d) => !d.canOpenPr).map((d) => d.repo) const allOpen = prRepos.length > 0 && prRepos.every((r) => fix.prUrls[r]) return ( Fix in {fix.repos.join(", ")} {fix.branch} {Object.entries(fix.prUrls).map(([repo, url]) => ( Draft pull request in {repo} ))} {fix.error && ( {fix.error} )} {fix.diffs.length === 0 ? (

The fix agent made no changes.

) : (
{fix.diffs.map((d) => ( {d.repo} +{d.added} −{d.removed}
{d.stat.trim()}
))}
)} {fix.screenshots && } {fix.diffs.length > 0 && } {prRepos.length > 0 && (
{ e.preventDefault() act.mutate( { action: "pr", body: { title, body } }, { onSuccess: () => toast.success(allOpen ? "Pushed to the pull request" : "Draft pull request opened"), onError: (err) => toast.error(err.message), } ) }} > setTitle(e.target.value)} placeholder="Pull request title" aria-label="Pull request title" required />