import type { GitFileDiff } from "@opengeni/sdk"; import { useState } from "react"; import { cn } from "../lib/cn"; import { useThemeType } from "../lib/use-theme-type"; import { PierreDiff } from "../components/pierre-diff"; import { useOpenGeniText } from "../messages/runtime"; /* ---------------------------------------------------------------------------- Tool diff Renders parsed `GitFileDiff[]` (from the V4A apply_patch parser) through the EXACT same diff stack the Files/Changes tabs use: `PierreDiff` (Shiki- highlighted), with a built-in plain-text degrade for a host without `@pierre/diffs` — one renderer, a single data contract. A per-block Unified/Split toggle sits in the header. -------------------------------------------------------------------------- */ export function ToolDiff({ files }: { files: GitFileDiff[] }) { const [layout, setLayout] = useState<"unified" | "split">("unified"); // Resolve the host theme (auto-detect via `data-og-theme`) with the SAME hook // the Files tab uses, then thread it into Pierre. Without it Pierre falls back // to its hard dark default and renders a github-dark slab inside a light page. const themeType = useThemeType(undefined); return (
); } function LayoutToggle({ layout, onChange, }: { layout: "unified" | "split"; onChange: (next: "unified" | "split") => void; }) { return (
{(["unified", "split"] as const).map((value) => ( ))}
); } /** Raw-patch fallback for a V4A hunk string the parser could not structure. */ export function RawPatch({ diff }: { diff: string }) { const t = useOpenGeniText(); const occurrences = new Map(); const lines = diff.split("\n").map((line) => { const occurrence = (occurrences.get(line) ?? 0) + 1; occurrences.set(line, occurrence); return { key: `${line}\u0000${occurrence}`, line }; }); return (

{t("timeline.toolDiff.rawPatchCouldNotParse")}

        {lines.map(({ key, line }) => (
          
            {line || " "}
          
        ))}
      
); }