"use client"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Textarea } from "@/components/ui/textarea"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Upload, Github, Plug, FileText, Download, Copy, Check } from "lucide-react"; import { useState, useRef } from "react"; import { auth } from "@/lib/firebase/config"; import { toast } from "sonner"; import { GitHubRepoPicker } from "./github-repo-picker"; import { CursorIcon } from "@/components/icons/custom-icons"; interface CollectorActionsProps { projectId: string; className?: string; } export function CollectorActions({ projectId, className }: CollectorActionsProps) { const [uploading, setUploading] = useState(false); const [showGithubPicker, setShowGithubPicker] = useState(false); const [showPasteDialog, setShowPasteDialog] = useState(false); const [showCursorImportDialog, setShowCursorImportDialog] = useState(false); const [pasteTitle, setPasteTitle] = useState(""); const [pasteContent, setPasteContent] = useState(""); const [isPasting, setIsPasting] = useState(false); const [copiedConfig, setCopiedConfig] = useState(false); const [copiedCommand, setCopiedCommand] = useState(false); const fileInputRef = useRef(null); const handleFileSelect = async (event: React.ChangeEvent) => { const files = event.target.files; if (!files || files.length === 0) return; setUploading(true); try { const user = auth.currentUser; if (!user) { toast.error("Please sign in to upload files"); return; } const token = await user.getIdToken(); for (const file of Array.from(files)) { const formData = new FormData(); formData.append("file", file); const response = await fetch(`/api/projects/${projectId}/knowledge/upload-document`, { method: "POST", headers: { Authorization: `Bearer ${token}`, }, body: formData, }); if (!response.ok) { throw new Error(`Failed to upload ${file.name}`); } } toast.success(`Uploaded ${files.length} file(s)`); if (fileInputRef.current) { fileInputRef.current.value = ""; } } catch (error) { console.error("Upload error:", error); toast.error("Failed to upload files"); } finally { setUploading(false); } }; const handleExtensionClick = () => { window.open("https://chrome.google.com/webstore", "_blank"); toast.info("Install the Vibn browser extension and link it to this project"); }; const handleCopyConfig = () => { const vibnConfig = { projectId: projectId, version: "1.0.0" }; const content = JSON.stringify(vibnConfig, null, 2); navigator.clipboard.writeText(content); setCopiedConfig(true); toast.success("Configuration copied to clipboard!"); setTimeout(() => setCopiedConfig(false), 2000); }; const handleCopyCommand = () => { navigator.clipboard.writeText("Vibn: Import Historical Conversations"); setCopiedCommand(true); toast.success("Command copied to clipboard!"); setTimeout(() => setCopiedCommand(false), 2000); }; const handlePasteSubmit = async () => { if (!pasteTitle.trim() || !pasteContent.trim()) { toast.error("Please provide both title and content"); return; } setIsPasting(true); try { const user = auth.currentUser; if (!user) { toast.error("Please sign in to save content"); return; } const token = await user.getIdToken(); const response = await fetch(`/api/projects/${projectId}/knowledge/import-ai-chat`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, body: JSON.stringify({ title: pasteTitle, transcript: pasteContent, }), }); if (!response.ok) { throw new Error("Failed to import chat"); } toast.success("AI chat imported successfully!"); setShowPasteDialog(false); setPasteTitle(""); setPasteContent(""); } catch (error) { console.error("Paste error:", error); toast.error("Failed to import chat"); } finally { setIsPasting(false); } }; return ( <> {/* Upload Documents */} {/* Connect GitHub */} {/* Get Extension */} {/* Paste AI Chat */} {/* Import Cursor History */} {/* GitHub Picker Dialog */} {showGithubPicker && ( setShowGithubPicker(false)} /> )} {/* Paste AI Chat Dialog */} Import AI Chat Paste a conversation from ChatGPT, Claude, or any other AI tool
setPasteTitle(e.target.value)} className="mt-1" />