/**
* WriteCell — renders a write tool call as a new-file view with added-line styling.
*/
import {
IconChevronDown,
IconFilePlus,
IconLoader2,
} from "@tabler/icons-react";
import { memo, useState } from "react";
import { AnimatedCollapse } from "../chat/tool-call-display.js";
import { cn } from "../utils.js";
export interface WriteCellMeta {
toolKind: "write";
filePath: string;
content?: string;
truncated?: boolean;
lineCount?: number;
}
interface WriteCellProps {
meta: WriteCellMeta;
isRunning: boolean;
}
const MAX_COLLAPSED_LINES = 40;
const FileContentView = memo(function FileContentView({
content,
maxLines,
}: {
content: string;
maxLines: number | null;
}) {
const lines = content.split("\n");
const visible = maxLines !== null ? lines.slice(0, maxLines) : lines;
return (
{visible.map((line, idx) => (
|
{idx + 1}
|
+
|
{line}
|
))}
);
});
export function WriteCell({ meta, isRunning }: WriteCellProps) {
const [expanded, setExpanded] = useState(false);
const [showAll, setShowAll] = useState(false);
const hasContent = Boolean(meta.content);
const lines = meta.content ? meta.content.split("\n") : [];
const totalLines = lines.length;
const maxCollapsed =
showAll || totalLines <= MAX_COLLAPSED_LINES ? null : MAX_COLLAPSED_LINES;
const hiddenLines =
maxCollapsed !== null ? totalLines - MAX_COLLAPSED_LINES : 0;
return (
{/* Header */}
{/* Content body */}
{meta.content && (
{hiddenLines > 0 && (
)}
)}
);
}