"use client"; import { ExternalLink, FileText } from "lucide-react"; import Link from "next/link"; import { useMemo } from "react"; import type { DocumentResponseSchema } from "@/client/types.gen"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { KNOWLEDGE_BASE_DOC_URL } from "@/constants/documentation"; interface DocumentSelectorProps { value: string[]; onChange: (uuids: string[]) => void; documents: DocumentResponseSchema[]; disabled?: boolean; label?: string; description?: string; showLabel?: boolean; } export const DocumentSelector = ({ value, onChange, documents, disabled = false, label = "Knowledge Base Documents", description = "Select documents that the agent can reference during conversations.", showLabel = true, }: DocumentSelectorProps) => { // Only show completed documents const completedDocuments = useMemo( () => documents.filter((doc) => doc.processing_status === "completed"), [documents] ); const handleToggle = (documentUuid: string, checked: boolean) => { if (checked) { onChange([...value, documentUuid]); } else { onChange(value.filter((uuid) => uuid !== documentUuid)); } }; const formatFileSize = (bytes: number): string => { if (bytes === 0) return "0 Bytes"; const k = 1024; const sizes = ["Bytes", "KB", "MB", "GB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return Math.round(bytes / Math.pow(k, i) * 100) / 100 + " " + sizes[i]; }; if (completedDocuments.length === 0) { return (
{value.length} {value.length === 1 ? "document" : "documents"} selected
)}