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, replaceAll } from "./store"; const queryClient = new QueryClient(); const jotaiStore = createStore(); // Load initial models from the database rpc("list_models", {}).then((res) => { jotaiStore.set(dataAtom, (prev) => replaceAll(prev, "http_exchange", res.httpExchanges), ); }); // 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 [busy, setBusy] = useState(false); const osType = type(); const exchanges = useAtomValue(httpExchangesAtom); async function startProxy() { setBusy(true); setStatus("Starting..."); try { await rpc("execute_action", { scope: "global", action: "proxy_start" }); setStatus("Running"); } catch (err) { setStatus(`Failed: ${String(err)}`); } finally { setBusy(false); } } async function stopProxy() { setBusy(true); setStatus("Stopping..."); try { await rpc("execute_action", { scope: "global", action: "proxy_stop" }); setStatus("Stopped"); } catch (err) { setStatus(`Failed: ${String(err)}`); } finally { setBusy(false); } } return (
Yaak Proxy
{status}
{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( , );