The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAgent } from "agents/react"; |
| 2 | import { useState } from "react"; |
| 3 | import { createRoot } from "react-dom/client"; |
| 4 | import type { Counter, CounterState } from "./server.ts"; |
| 5 | import "./styles.css"; |
| 6 | |
| 7 | function App() { |
| 8 | const [state, setState] = useState<CounterState>({ count: 0, reminders: 0 }); |
| 9 | // Connects to the `Counter` agent named "demo" and mirrors its state. |
| 10 | const agent = useAgent<Counter, CounterState>({ |
| 11 | agent: "counter", |
| 12 | name: "demo", |
| 13 | onStateUpdate: setState, |
| 14 | }); |
| 15 | return ( |
| 16 | <main className="mx-auto max-w-md p-8 font-sans"> |
| 17 | <h1 className="text-3xl font-bold">Agents on Alchemy</h1> |
| 18 | <p className="mt-4">Count: {state.count}</p> |
| 19 | <button |
| 20 | className="mt-2 rounded bg-black px-4 py-2 text-white" |
| 21 | onClick={() => agent.stub.increment(1)} |
| 22 | > |
| 23 | Increment |
| 24 | </button> |
| 25 | </main> |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | createRoot(document.getElementById("root")!).render(<App />); |