import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { type } from "@tauri-apps/plugin-os"; import { Button, HeaderSize } from "@yaakapp-internal/ui"; import classNames from "classnames"; import { createStore, Provider, useAtomValue } from "jotai"; import { StrictMode, useState } from "react"; import { createRoot } from "react-dom/client"; import "./main.css"; import { listen, rpc } from "./rpc"; import { applyChange, dataAtom, httpExchangesAtom } from "./store"; const queryClient = new QueryClient(); const jotaiStore = createStore(); // Subscribe to model change events from the backend listen("model_write", (payload) => { jotaiStore.set(dataAtom, (prev) => applyChange(prev, "http_exchange", payload.model, payload.change), ); }); function App() { const [status, setStatus] = useState("Idle"); const [port, setPort] = useState(null); const [busy, setBusy] = useState(false); const osType = type(); const exchanges = useAtomValue(httpExchangesAtom); async function startProxy() { setBusy(true); setStatus("Starting..."); try { const result = await rpc("proxy_start", { port: 9090 }); setPort(result.port); setStatus(result.alreadyRunning ? "Already running" : "Running"); } catch (err) { setStatus(`Failed: ${String(err)}`); } finally { setBusy(false); } } async function stopProxy() { setBusy(true); setStatus("Stopping..."); try { const stopped = await rpc("proxy_stop", {}); setPort(null); setStatus(stopped ? "Stopped" : "Not running"); } catch (err) { setStatus(`Failed: ${String(err)}`); } finally { setBusy(false); } } return (
Yaak Proxy
{status} {port != null && ` · :${port}`}
{exchanges.length === 0 ? (

No traffic yet

) : ( {exchanges.map((ex) => ( ))}
Method URL Status
{ex.method} {ex.url} {ex.resStatus ?? "—"}
)}
); } createRoot(document.getElementById("root") as HTMLElement).render( , );