// Adapted from agentui (https://github.com/ashish200729/agentui), components/agents/file-diff.tsx // Copyright (c) 2026 Saurabh Chauhan. MIT License, see ./LICENSE-agentui.md // 改造:新增/删除行底色 emerald/rose → success/destructive 洗层(并保留 +/− 符号,不只靠颜色);不做语法高亮(去 shiki); // 折叠用 Disclosure;maxHeight 改 Tailwind 类;用于展示路径类变更(如整理记录的入库目标)。 import { ChevronDown, FileCode2 } from "lucide-react"; import { type ReactNode, useId, useState } from "react"; import { cn } from "~/lib/utils.ts"; import { CHEVRON_CLASS, Disclosure } from "./disclosure.tsx"; export type FileDiffLineType = "added" | "removed" | "context"; export interface FileDiffLine { id: string; type?: FileDiffLineType; content: ReactNode; /** 行尾附注(如状态) */ note?: ReactNode; } function Count({ value, type }: { value: number; type: "added" | "removed" }) { if (!value) return null; return ( {type === "added" ? "+" : "−"} {value} ); } export function FileDiff({ file, lines, defaultOpen = true, maxHeightClassName = "max-h-56", className, }: { file: ReactNode; lines: FileDiffLine[]; defaultOpen?: boolean; maxHeightClassName?: string; className?: string; }) { const id = useId(); const [open, setOpen] = useState(defaultOpen); const added = lines.filter((l) => l.type === "added").length; const removed = lines.filter((l) => l.type === "removed").length; return (
    {lines.map((l) => (
  • {l.type === "added" ? "+" : l.type === "removed" ? "−" : " "} {l.type === "added" ? "新增:" : l.type === "removed" ? "移除:" : ""} {l.content} {l.note ? {l.note} : null}
  • ))}
); }