"use client"; import { useState } from "react"; import { ChevronRight, ChevronDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { FileIcon } from "./FileIcon"; import { SyntaxHighlight, getLanguageFromPath } from "./SyntaxHighlight"; import { ToolUseBlock } from "./ToolUseBlock"; interface ToolFileReadProps { input: { file_path: string; offset?: number; limit?: number; }; result?: string; isError?: boolean; isRunning?: boolean; startedAt?: number; completedAt?: number; } function FileBreadcrumb({ filePath }: { filePath: string }) { const parts = filePath.replace(/^\//, "").split("/"); return (
{parts.map((part, i) => ( {i > 0 && } {part} ))}
); } const MAX_LINES_COLLAPSED = 40; export function ToolFileRead({ input, result, isError = false, isRunning = false, startedAt, completedAt, }: ToolFileReadProps) { const [showAll, setShowAll] = useState(false); const lang = getLanguageFromPath(input.file_path); const lines = result?.split("\n") ?? []; const isTruncated = !showAll && lines.length > MAX_LINES_COLLAPSED; const displayContent = isTruncated ? lines.slice(0, MAX_LINES_COLLAPSED).join("\n") : (result ?? ""); return ( {/* File path header */}
{(input.offset !== undefined || input.limit !== undefined) && ( {input.offset !== undefined && `offset: ${input.offset}`} {input.offset !== undefined && input.limit !== undefined && " · "} {input.limit !== undefined && `limit: ${input.limit}`} )}
{/* Content */} {isRunning ? (
Reading…
) : isError ? (
{result}
) : result ? (
{isTruncated && (
)}
) : null}
); }