import { useState } from "react" import { BookOpen, Copy, Download, Trash2, MessagesSquare } from "lucide-react" import { AppShell } from "~/components/layout/app-shell" import { Button } from "~/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "~/components/ui/card" import { Input } from "~/components/ui/input" import { pageTitle } from "~/lib/page-meta" import { deleteLibraryItem, useLibrary, type LibraryItem, } from "~/lib/library" export const meta = () => pageTitle("Library") export default function LibraryRoute() { const items = useLibrary() const [query, setQuery] = useState("") const [openId, setOpenId] = useState(null) const filtered = items.filter((it) => { if (!query.trim()) return true const q = query.toLowerCase() return ( it.title.toLowerCase().includes(q) || it.content.toLowerCase().includes(q) || it.tags.some((t) => t.toLowerCase().includes(q)) ) }) const open = items.find((x) => x.id === openId) ?? null return ( Library Saved items and templates. Save a chat from the Assistant via the ⋯ menu → "Save to Library". setQuery(e.target.value)} /> {items.length === 0 ? ( ) : (
    {filtered.length === 0 && (
  • No matches.
  • )} {filtered.map((it) => (
  • ))}
{open ? : }
)}
) } function EmptyState() { return (

Library is empty

Save a conversation from the Assistant via the ⋯ menu →{" "} Save to Library.

) } function PickAnItem() { return (
Pick an item to view.
) } function Detail({ item }: { item: LibraryItem }) { const copy = async () => { try { await navigator.clipboard.writeText(item.content) } catch { /* ignore */ } } const download = () => { const blob = new Blob([item.content], { type: "text/markdown;charset=utf-8", }) const url = URL.createObjectURL(blob) const a = document.createElement("a") a.href = url const slug = item.title.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 60) || "item" a.download = `${slug}.md` a.click() URL.revokeObjectURL(url) } const remove = () => { if (window.confirm(`Delete "${item.title}"?`)) deleteLibraryItem(item.id) } return (
{item.title} {item.agentName ? `${item.agentName} · ` : ""} {item.messageCount ? `${item.messageCount} msg · ` : ""} {new Date(item.createdAt).toLocaleString()}
        {item.content}
      
) }