import { DownloadIcon, LoaderIcon, PackageIcon } from "lucide-react"; import { useCallback, useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { urlOfArtifact } from "@/core/artifacts/utils"; import { useI18n } from "@/core/i18n/hooks"; import { installSkill } from "@/core/skills/api"; import { getFileExtensionDisplayName, getFileIcon, getFileName, } from "@/core/utils/files"; import { cn } from "@/lib/utils"; import { useArtifacts } from "./context"; export function ArtifactFileList({ className, files, threadId, }: { className?: string; files: string[]; threadId: string; }) { const { t } = useI18n(); const { select: selectArtifact, setOpen } = useArtifacts(); const [installingFile, setInstallingFile] = useState(null); const handleClick = useCallback( (filepath: string) => { selectArtifact(filepath); setOpen(true); }, [selectArtifact, setOpen], ); const handleInstallSkill = useCallback( async (e: React.MouseEvent, filepath: string) => { e.stopPropagation(); e.preventDefault(); if (installingFile) return; setInstallingFile(filepath); try { const result = await installSkill({ thread_id: threadId, path: filepath, }); if (result.success) { toast.success(result.message); } else { toast.error(result.message || "Failed to install skill"); } } catch (error) { console.error("Failed to install skill:", error); toast.error("Failed to install skill"); } finally { setInstallingFile(null); } }, [threadId, installingFile], ); return ( ); }