AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
"use client";
import { useExpertMap } from "@/app/(platform)/copilot/useExpertMap";
import { Text } from "@/components/atoms/Text/Text";
import type { Transition, Variants } from "framer-motion";
import { motion, useReducedMotion } from "framer-motion";
import { useEffect } from "react";
import { ArtifactsList } from "./components/ArtifactsList/ArtifactsList";
import { getEmptyState } from "./components/ArtifactsList/helpers";
import { ArtifactsSearchBar } from "./components/ArtifactsSearchBar/ArtifactsSearchBar";
import { ExpertFilter } from "./components/ExpertFilter/ExpertFilter";
import { NewMenu } from "./components/NewMenu/NewMenu";
import { OriginFilter } from "./components/OriginFilter/OriginFilter";
import { ViewToggle } from "./components/ViewToggle/ViewToggle";
import { FolderBreadcrumb } from "./components/WorkspaceFolders/FolderBreadcrumb";
import {
ancestorsOf,
childrenOf,
} from "./components/WorkspaceFolders/folderTree";
import { useArtifactsFolders } from "./useArtifactsFolders";
import { useArtifactsPage } from "./useArtifactsPage";
const EASE_OUT_SOFT: Transition["ease"] = [0.16, 1, 0.3, 1];
const SECTION_VARIANTS: Variants = {
hidden: { opacity: 0, y: 8, filter: "blur(8px)" },
show: {
opacity: 1,
y: 0,
filter: "blur(0px)",
transition: { duration: 0.45, ease: EASE_OUT_SOFT },
},
};
const REDUCED_SECTION_VARIANTS: Variants = {
hidden: { opacity: 0 },
show: { opacity: 1, transition: { duration: 0.2 } },
};
const MAIN_CLASS_NAME =
"mx-auto min-h-screen w-full max-w-7xl space-y-6 px-6 pb-20 pt-2 md:px-8";
export default function ArtifactsPage() {
const reduceMotion = useReducedMotion();
const {
folders,
isLoading: isFoldersLoading,
isError: isFoldersError,
error: foldersError,
} = useArtifactsFolders();
const {
files,
isLoading,
isError,
error,
searchTerm,
setSearchTerm,
debouncedSearch,
originFilter,
setOriginFilter,
selectedFolderId,
openFolder,
closeFolder,
expertFilter,
setExpertFilter,
view,
setView,
hasMore,
isLoadingMore,
loadMore,
} = useArtifactsPage({ folders, isFoldersLoading, isFoldersError });
const { activeExperts, expertsById } = useExpertMap();
const isSearching = searchTerm.length > 0;
const isInFolder = selectedFolderId !== null;
const selectedFolder = folders.find((f) => f.id === selectedFolderId);
// Folders are the container an expert filter narrows inside, so only a
// search — which spans every folder — replaces them with a flat list.
const showFolders = !isSearching;
const hasFolders =
showFolders && childrenOf(folders, selectedFolderId).length > 0;
// The empty state depends on whether child folders exist, so hold the
// loading state until both queries have settled.
const isListLoading = isLoading || (showFolders && isFoldersLoading);
// Until the folders query settles the open folder's name is unknown, so the
// crumb stands in with the generic label rather than flickering a wrong one.
const breadcrumbItems = isInFolder
? selectedFolder
? ancestorsOf(folders, selectedFolder.id).map((folder) => ({
id: folder.id,
name: folder.name,
}))
: [{ id: selectedFolderId, name: "Folder" }]
: [];
useEffect(() => {
document.title = "Files – AutoGPT Platform";
}, []);
const variants = reduceMotion ? REDUCED_SECTION_VARIANTS : SECTION_VARIANTS;
return (
<main className={MAIN_CLASS_NAME}>
{/* The chrome's inset header owns the title row and shows storage usage
beside it (see InsetHeaderActions). */}
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
<motion.div
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: 0 }}
>
<Text variant="large" className="max-w-prose text-zinc-600">
Find here every file generated by your team or uploaded by you.
</Text>
</motion.div>
<motion.div
className="flex items-center gap-3"
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: reduceMotion ? 0 : 0.08 }}
>
<ArtifactsSearchBar
searchTerm={searchTerm}
setSearchTerm={setSearchTerm}
/>
<NewMenu
selectedFolderId={selectedFolderId}
selectedFolderName={selectedFolder?.name}
/>
</motion.div>
</div>
<div className="flex flex-wrap items-center justify-between gap-4">
<motion.div
className="flex flex-wrap items-center gap-x-32 gap-y-2"
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: reduceMotion ? 0 : 0.16 }}
>
<OriginFilter value={originFilter} onChange={setOriginFilter} />
<ExpertFilter
experts={activeExperts}
value={expertFilter}
onChange={setExpertFilter}
/>
</motion.div>
<motion.div
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: reduceMotion ? 0 : 0.2 }}
>
<ViewToggle value={view} onChange={setView} />
</motion.div>
</div>
{isInFolder ? (
<motion.div
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: reduceMotion ? 0 : 0.24 }}
>
<FolderBreadcrumb
items={breadcrumbItems}
onNavigate={(folderId) =>
folderId === null ? closeFolder() : openFolder(folderId)
}
/>
</motion.div>
) : null}
<motion.div
variants={variants}
initial="hidden"
animate="show"
transition={{ delay: reduceMotion ? 0 : 0.28 }}
>
<ArtifactsList
files={files}
isLoading={isListLoading}
isError={isError || (showFolders && isFoldersError)}
error={isError ? error : showFolders ? foldersError : undefined}
emptyState={getEmptyState({
hasSearchTerm: isSearching,
isInFolder,
hasFolders,
folderId: selectedFolderId,
expert: expertFilter
? {
id: expertFilter,
name: expertsById.get(expertFilter)?.name ?? null,
}
: null,
})}
compactEmpty={hasFolders}
hasMore={hasMore}
isLoadingMore={isLoadingMore}
onLoadMore={loadMore}
listKey={`${originFilter}|${expertFilter ?? "everyone"}|${debouncedSearch}|${selectedFolderId ?? "root"}`}
view={view}
showFolders={showFolders}
folderParentId={selectedFolderId}
onSelectFolder={openFolder}
/>
</motion.div>
</main>
);
}