"use client"; import { memo } from "react"; import { IconCheck, IconX, IconFileCode2 } from "@tabler/icons-react"; import { GridSpinner } from "@/components/grid-spinner"; import { FilePathButton } from "./file-path-button"; import type { Message } from "@/lib/types/http"; import { ExpandableRow } from "./expandable-row"; import { useExpandState } from "./use-expand-state"; type ReadFileOutput = { content?: string; line_count?: number; truncated?: boolean; language?: string; }; type ReadFilePayload = { file_path?: string; offset?: number; limit?: number; output?: ReadFileOutput; }; type ToolReadMetadata = { tool_call_id?: string; title?: string; status?: "pending" | "running" | "complete" | "error"; normalized?: { read_file?: ReadFilePayload }; }; type ToolReadMessageProps = { comment: Message; worktreePath?: string; sessionId?: string; onOpenFile?: (path: string) => void; }; function ReadStatusIcon({ status }: { status: string | undefined }) { if (status === "complete") return ; if (status === "error") return ; if (status === "running") return ; return null; } function getReadSummary(lineCount: number | undefined): string { if (lineCount) return `Read ${lineCount} line${lineCount !== 1 ? "s" : ""}`; return "Read"; } function parseReadMetadata(comment: Message) { const metadata = comment.metadata as ToolReadMetadata | undefined; const status = metadata?.status; const readFile = metadata?.normalized?.read_file; const readOutput = readFile?.output; const filePath = readFile?.file_path; const hasOutput = !!readOutput?.content; const isSuccess = status === "complete"; return { status, readOutput, filePath, hasOutput, isSuccess }; } export const ToolReadMessage = memo(function ToolReadMessage({ comment, worktreePath, onOpenFile, }: ToolReadMessageProps) { const { status, readOutput, filePath, hasOutput, isSuccess } = parseReadMetadata(comment); const autoExpanded = status === "running"; const { isExpanded, handleToggle } = useExpandState(status, autoExpanded); return ( } header={
{getReadSummary(readOutput?.line_count)} {!isSuccess && } {filePath && ( )} {readOutput?.truncated && ( (truncated) )}
} hasExpandableContent={hasOutput} isExpanded={isExpanded} onToggle={handleToggle} > {readOutput?.content && (
            {readOutput.content}
          
)}
); });