"use client"; import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Skeleton } from "ui/skeleton"; import { ScrollArea } from "ui/scroll-area"; import { toast } from "sonner"; import { Loader2, Plus, Play, Pause, AlertCircle } from "lucide-react"; import { cn } from "lib/utils"; import dynamic from "next/dynamic"; import { Label } from "ui/label"; import { Input } from "ui/input"; import { Textarea } from "ui/textarea"; const LightRays = dynamic(() => import("@/components/ui/light-rays"), { ssr: false, }); interface EternityProject { project_name: string; goal: string; deadline: string; current_mode: string; is_active: boolean; priority: string; latest_brief: string | null; created_at: string; time_remaining_str: string; } export default function EternityDashboard() { const [projects, setProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); const [isRefreshing, setIsRefreshing] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); // Form states const [projName, setProjName] = useState(""); const [projGoal, setProjGoal] = useState(""); const [projDeadline, setProjDeadline] = useState(1.0); const [projPriority, setProjPriority] = useState("low"); const [isSubmitting, setIsSubmitting] = useState(false); const fetchProjects = async (silent = false) => { if (!silent) setIsRefreshing(true); try { const res = await fetch("/api/eternity"); if (!res.ok) { throw new Error(await res.text()); } const data = await res.json(); setProjects(data.projects || []); } catch (err: any) { toast.error(`Failed to load projects: ${err.message}`); } finally { setIsLoading(false); setIsRefreshing(false); } }; useEffect(() => { fetchProjects(); const interval = setInterval(() => fetchProjects(true), 5000); return () => clearInterval(interval); }, []); const handleToggleActive = async (name: string, currentStatus: boolean) => { try { const res = await fetch("/api/eternity", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "toggle", project_name: name, is_active: !currentStatus, }), }); if (!res.ok) throw new Error("Failed to toggle status"); toast.success(`Project ${!currentStatus ? "resumed" : "paused"}`); fetchProjects(true); } catch (err: any) { toast.error(err.message); } }; const handleSetPriority = async (name: string, priority: string) => { try { const res = await fetch("/api/eternity", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "set-priority", project_name: name, priority: priority, }), }); if (!res.ok) throw new Error("Failed to set priority"); toast.success(`Priority updated to ${priority}`); fetchProjects(true); } catch (err: any) { toast.error(err.message); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!projGoal.trim()) { toast.error("Please enter a goal statement."); return; } setIsSubmitting(true); try { const res = await fetch("/api/eternity", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "init", project_name: projName.trim(), goal: projGoal.trim(), deadline_hours: projDeadline, priority: projPriority, }), }); if (!res.ok) throw new Error(await res.text()); toast.success("Eternity R&D Goal Started successfully!"); setIsModalOpen(false); setProjName(""); setProjGoal(""); fetchProjects(true); } catch (err: any) { toast.error(`Init failed: ${err.message}`); } finally { setIsSubmitting(false); } }; return ( <>

Eternity R&D Lab {isRefreshing && }

Autonomous multi-agent loop orchestrator panel

{isLoading ? (
) : projects.length === 0 ? (

No R&D goals configured

Click "New R&D Goal" to initialize your first eternity loop.

) : (
{projects.map((p) => { const isBuild = p.current_mode === "build"; return (

{p.project_name}

{p.is_active ? "ACTIVE" : "PAUSED"} {p.priority.toUpperCase()}

Started on {new Date(p.created_at).toLocaleString()}

Goal Description:
{p.goal}
Mode Status
{p.current_mode} Mode
Deadline Countdown
{p.time_remaining_str}
{p.latest_brief && (
📘 Latest Research Brief Summary
{p.latest_brief}
)}
); })}
)}
{/* MODAL */} {isModalOpen && (

Initialize R&D Goal

setProjName(e.target.value)} />