"use client"; import { useState, useRef, useEffect } from "react"; import { apiCall } from "@/lib/api"; import { Send } from "lucide-react"; export function Agent({ apiKey }: { apiKey: string }) { const [messages, setMessages] = useState<{role: string, content: string}[]>([]); const [input, setInput] = useState(""); const [threadId, setThreadId] = useState(null); const [loading, setLoading] = useState(false); const bottomRef = useRef(null); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages, loading]); const sendMessage = async () => { if (!input.trim() || !apiKey) return; const userMsg = input; setInput(""); setMessages(prev => [...prev, { role: "user", content: userMsg }]); setLoading(true); try { const payload = { prompt: userMsg, thread_id: threadId }; const response = await apiCall("POST", "/agent/run", apiKey, payload); setMessages(prev => [...prev, { role: "assistant", content: response.response }]); setThreadId(response.thread_id); } catch (e: any) { setMessages(prev => [...prev, { role: "assistant", content: `⚠ Error: ${e.message}` }]); } finally { setLoading(false); } }; return ( /* Full viewport height minus the mobile top-bar padding (pt-14 from page.tsx) */
{/* Header */}

Converse with Memory

An agent that remembers. Ask anything — it searches your temporal memory first.

{/* Message list */}
{messages.length === 0 ? (

Ready for your query.

) : ( messages.map((m, i) => (
{m.content}
)) )} {loading && (
)}
{/* Input bar — sticks to bottom */}
{!apiKey && (

⚠ Set your API key in API Keys to start chatting.

)}
setInput(e.target.value)} onKeyDown={e => e.key === 'Enter' && !e.shiftKey && sendMessage()} placeholder={apiKey ? "Ask your temporally-aware agent..." : "Add API key first"} disabled={loading || !apiKey} className="w-full bg-[#f5f5f5] border border-[#eaeaea] rounded-full py-3.5 pl-5 pr-14 text-sm focus:outline-none focus:border-black transition-colors text-black placeholder-[#aaa] disabled:opacity-50" />
); }