import type { MouseEvent, ReactNode } from "react"; import { FileCode2 } from "lucide-react"; import { cn } from "@/lib/utils"; import type { WorkspaceFileRef } from "@paperclipai/shared"; import { useFileViewer } from "@/context/FileViewerContext"; export interface ArtifactFileChipProps { workspaceFileRef: WorkspaceFileRef; /** Override the rendered label. Defaults to the display path. */ label?: ReactNode; className?: string; /** Optional override if the consumer wants to customize activation. */ onOpen?: (ref: WorkspaceFileRef) => void; showIcon?: boolean; title?: string; } function artifactFileDisplay(ref: WorkspaceFileRef) { if (!ref.projectName) return ref.displayPath; const prefix = `${ref.projectName} / `; return ref.displayPath.startsWith(prefix) ? ref.displayPath : `${prefix}${ref.displayPath}`; } export function ArtifactFileChip({ workspaceFileRef, label, className, onOpen, showIcon = true, title, }: ArtifactFileChipProps) { const viewer = useFileViewer(); const display = typeof label !== "undefined" ? label : artifactFileDisplay(workspaceFileRef); const canOpen = !!(onOpen || viewer); const lineSuffix = workspaceFileRef.line ? ` line ${workspaceFileRef.line}${workspaceFileRef.column ? ` column ${workspaceFileRef.column}` : ""}` : ""; const ariaLabel = canOpen ? `Open ${workspaceFileRef.displayPath}${lineSuffix} in the file viewer` : `Workspace file ${workspaceFileRef.displayPath}${lineSuffix}`; const tooltip = title ?? (canOpen ? `Open ${workspaceFileRef.displayPath}${lineSuffix} in the file viewer` : `Workspace file ${workspaceFileRef.displayPath}${lineSuffix}`); const classNames = cn( "paperclip-artifact-file-chip inline-flex items-center gap-1 rounded-sm border border-border bg-muted/60 px-1.5 py-0.5 font-mono text-xs leading-tight text-foreground/90 align-middle no-underline hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1", canOpen ? "cursor-pointer" : null, className, ); const content = ( <> {showIcon ?