import { useAgent } from "agents/react"; import { useState } from "react"; import { createRoot } from "react-dom/client"; import type { Attempt, CFAgentState, MyAgent } from "./server"; function App() { const [description, setDescription] = useState(""); const [attempts, setAttempts] = useState([]); const [status, setStatus] = useState(); const [chosenSlogan, setChosenSlogan] = useState(); const [attemptsExpanded, setAttemptsExpanded] = useState(false); console.log("[Client] Current description:", description); const agent = useAgent({ agent: "my-agent", name: "slogan-generator", onStateUpdate(state, source) { console.log("[Client] onStateUpdate called ", source); setAttempts(state.attempts); setChosenSlogan(state.chosenSlogan); setStatus(state.status); } }); const handleGenerate = async () => { if (description) { console.log("[Client] Using agent stup to generate slogan:", description); await agent.stub.generateSlogan(description); } else { console.log( "[Client] Attempted to generateSlogan with empty description" ); } }; const handleDescriptionChange = (e: React.ChangeEvent) => { const newDescription = e.target.value; console.log("[Client] Description input changed:", newDescription); setDescription(newDescription); if (attempts.length > 0) { // Reset the run agent.stub.reset(); } }; return (

LLM As a Judge

{status &&
{status}
} {chosenSlogan && (

🎯 {chosenSlogan}

Selected Winner

)} {attempts.length > 0 && (
{attemptsExpanded && (
{attempts.map((attempt) => (
Slogan: {attempt.slogan}
Score:{" "} {attempt.score}
Feedback: {attempt.feedback}
))}
)}
)}
); } console.log("[Client] Initializing React app"); const root = createRoot(document.getElementById("root")!); root.render();