Sdm0 commited on
Commit
7ff1786
·
verified ·
1 Parent(s): ea22328

Deploy 52dda08a

Browse files
Files changed (1) hide show
  1. frontend/src/main.jsx +4 -2
frontend/src/main.jsx CHANGED
@@ -30,7 +30,9 @@ function Ragas({ ragas }) { if (!ragas) return null; const text = ragas.status =
30
 
31
  function App() {
32
  const [repo, setRepo] = useState(""); const [pr, setPr] = useState(""); const [endpoint, setEndpoint] = useState("auto"); const [provider, setProvider] = useState(""); const [model, setModel] = useState(""); const [apiKey, setApiKey] = useState(""); const [baseUrl, setBaseUrl] = useState("");
33
- const [job, setJob] = useState(null); const [message, setMessage] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false);
 
 
34
  const isTerminal = useMemo(() => TERMINAL.has(job?.status), [job?.status]);
35
  useEffect(() => {
36
  if (!job?.id || isTerminal) return undefined; let stopped = false;
@@ -39,6 +41,6 @@ function App() {
39
  }, [job?.id, isTerminal]);
40
  async function startReview(e) { e.preventDefault(); setError(""); if (apiKey && (!provider || !model)) { setError("Choose a provider and model when using your own API key."); return; } if (!/^[-\w.]+\/[-\w.]+$/.test(repo.trim()) || !Number.isInteger(Number(pr)) || Number(pr) < 1) { setError("Enter a repository as owner/name and a valid PR number."); return; } setBusy(true); setJob(null); setMessage("Queueing review…"); try { const r = await fetch(apiUrl("/api/reviews"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo.trim(), pr_number: Number(pr), endpoint, provider: provider || undefined, model: model || undefined, api_key: apiKey || undefined, base_url: baseUrl || undefined }) }); const data = await r.json().catch(() => ({})); if (!r.ok) throw new Error(data.detail || `Request failed (${r.status})`); setJob(data); setMessage("Review queued. This page will update as analysis progresses."); } catch (e) { setError(API_BASE ? e.message : "Set VITE_REVIEW_API_URL to connect the review worker."); } finally { setBusy(false); } }
41
  async function decide(action) { if (!job?.id) return; setBusy(true); setError(""); setMessage(action === "approve" ? "Posting approved review…" : "Rejecting review…"); try { const r = await fetch(apiUrl(`/api/reviews/${job.id}/decision`), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action }) }); const data = await r.json().catch(() => ({})); if (!r.ok) throw new Error(data.detail || `Decision failed (${r.status})`); setJob(data); setMessage(action === "approve" ? "Review delivery finished." : "Review rejected. Nothing was posted to GitHub."); } catch (e) { setError(e.message); } finally { setBusy(false); } }
42
- return <div className="shell"><header className="topbar"><div className="brand"><span className="brand-mark">OC</span><span>OpenCodeReview</span></div><div><a className="status-dot" href={`${API_BASE}/api/auth/github/start`}>Sign in with GitHub</a><span className="status-dot">Human approval required</span></div></header><main className="content"><section className="hero"><p className="eyebrow">Pull request intelligence</p><h1>Review changes with<br /><em>evidence before action.</em></h1><p className="lede">Parallel analysis for correctness, security, and test coverage. Nothing is posted to GitHub until you approve it.</p></section><section className="workspace"><form className="panel form-panel" onSubmit={startReview} aria-busy={busy}><div className="panel-kicker">New review</div><h2>Inspect a pull request</h2><label htmlFor="repo">Repository<input id="repo" value={repo} onChange={e => setRepo(e.target.value)} placeholder="owner/repository" autoComplete="off" /></label><label htmlFor="pr">Pull request<input id="pr" value={pr} onChange={e => setPr(e.target.value)} placeholder="42" inputMode="numeric" /></label><label htmlFor="endpoint">LLM endpoint<select id="endpoint" value={endpoint} onChange={e => setEndpoint(e.target.value)}><option value="auto">Automatic fallback</option><option value="gemini">Gemini</option><option value="groq">Groq</option></select></label><details className="custom-provider"><summary>Use your own provider key (used only for this review)</summary><label htmlFor="provider">Provider<select id="provider" value={provider} onChange={e => setProvider(e.target.value)}><option value="">Choose provider</option><option value="openai">OpenAI-compatible</option><option value="anthropic">Anthropic</option><option value="google">Google</option></select></label><label htmlFor="model">Model<input id="model" value={model} onChange={e => setModel(e.target.value)} placeholder="model-name" autoComplete="off" /></label><label htmlFor="api-key">API key<input id="api-key" type="password" value={apiKey} onChange={e => setApiKey(e.target.value)} placeholder="Used only for this review" autoComplete="off" /></label><label htmlFor="base-url">Base URL <span>(optional)</span><input id="base-url" value={baseUrl} onChange={e => setBaseUrl(e.target.value)} placeholder="https://api.example.com/v1" autoComplete="off" /></label></details><button type="submit" disabled={busy}>{busy && !job ? "Queueing review…" : "Start review"}<span aria-hidden="true">↗</span></button>{(error || message) && <div className={`message ${error ? "error" : "success"}`} role="status" aria-live="polite">{error || message}</div>}{job && <div className="job-card"><div><strong>Review {job.id?.slice(0, 8)}</strong><small>{job.repo} · PR #{job.pr_number}</small></div><span className={`pill ${job.status}`}>{pretty(job.status)}</span></div>}{job && !isTerminal && <div className="progress" role="progressbar" aria-label={`Review ${pretty(job.status)}`}><span /><small>Analysis is running. This may take a few minutes.</small></div>}<div className="results"><Verdict job={job} /><Ragas ragas={job?.ragas} />{job?.findings && <Findings findings={job.findings} />}{job?.status === "awaiting_approval" && <div className="actions"><button type="button" onClick={() => decide("approve")} disabled={busy}>Approve &amp; post</button><button type="button" className="secondary" onClick={() => decide("reject")} disabled={busy}>Reject</button></div>}<Receipt result={job?.posting_result} />{job?.error && <div className="error detail">{job.error}</div>}</div></form><aside className="panel signal-panel"><div className="panel-kicker">What you receive</div><div className="signal"><strong>01</strong><span><b>Evidence-grounded findings</b><small>Code locations, severity, and confidence</small></span></div><div className="signal"><strong>02</strong><span><b>Human checkpoint</b><small>Approve or reject before GitHub comments</small></span></div><div className="signal"><strong>03</strong><span><b>Delivery receipt</b><small>See exactly what reached GitHub</small></span></div></aside></section></main><footer>OpenCodeReview <span>·</span> React review workspace <span>·</span> API keys stay server-side</footer></div>;
43
  }
44
  createRoot(document.getElementById("root")).render(<App />);
 
30
 
31
  function App() {
32
  const [repo, setRepo] = useState(""); const [pr, setPr] = useState(""); const [endpoint, setEndpoint] = useState("auto"); const [provider, setProvider] = useState(""); const [model, setModel] = useState(""); const [apiKey, setApiKey] = useState(""); const [baseUrl, setBaseUrl] = useState("");
33
+ const [job, setJob] = useState(null); const [message, setMessage] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const [user, setUser] = useState(null);
34
+ useEffect(() => { fetch(apiUrl("/api/auth/me"), { credentials: "include" }).then(r => r.ok ? r.json() : null).then(setUser).catch(() => setUser(null)); }, []);
35
+ async function logout() { await fetch(apiUrl("/api/auth/logout"), { method: "POST", credentials: "include" }); setUser(null); }
36
  const isTerminal = useMemo(() => TERMINAL.has(job?.status), [job?.status]);
37
  useEffect(() => {
38
  if (!job?.id || isTerminal) return undefined; let stopped = false;
 
41
  }, [job?.id, isTerminal]);
42
  async function startReview(e) { e.preventDefault(); setError(""); if (apiKey && (!provider || !model)) { setError("Choose a provider and model when using your own API key."); return; } if (!/^[-\w.]+\/[-\w.]+$/.test(repo.trim()) || !Number.isInteger(Number(pr)) || Number(pr) < 1) { setError("Enter a repository as owner/name and a valid PR number."); return; } setBusy(true); setJob(null); setMessage("Queueing review…"); try { const r = await fetch(apiUrl("/api/reviews"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo.trim(), pr_number: Number(pr), endpoint, provider: provider || undefined, model: model || undefined, api_key: apiKey || undefined, base_url: baseUrl || undefined }) }); const data = await r.json().catch(() => ({})); if (!r.ok) throw new Error(data.detail || `Request failed (${r.status})`); setJob(data); setMessage("Review queued. This page will update as analysis progresses."); } catch (e) { setError(API_BASE ? e.message : "Set VITE_REVIEW_API_URL to connect the review worker."); } finally { setBusy(false); } }
43
  async function decide(action) { if (!job?.id) return; setBusy(true); setError(""); setMessage(action === "approve" ? "Posting approved review…" : "Rejecting review…"); try { const r = await fetch(apiUrl(`/api/reviews/${job.id}/decision`), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action }) }); const data = await r.json().catch(() => ({})); if (!r.ok) throw new Error(data.detail || `Decision failed (${r.status})`); setJob(data); setMessage(action === "approve" ? "Review delivery finished." : "Review rejected. Nothing was posted to GitHub."); } catch (e) { setError(e.message); } finally { setBusy(false); } }
44
+ return <div className="shell"><header className="topbar"><div className="brand"><span className="brand-mark">OC</span><span>OpenCodeReview</span></div><div>{user ? <><span className="status-dot">Signed in as {user.login}</span><button className="auth-button" onClick={logout}>Sign out</button></> : <a className="status-dot" href={`${API_BASE}/api/auth/github/start`}>Sign in with GitHub</a>}<span className="status-dot">Human approval required</span></div></header><main className="content"><section className="hero"><p className="eyebrow">Pull request intelligence</p><h1>Review changes with<br /><em>evidence before action.</em></h1><p className="lede">Parallel analysis for correctness, security, and test coverage. Nothing is posted to GitHub until you approve it.</p></section><section className="workspace"><form className="panel form-panel" onSubmit={startReview} aria-busy={busy}><div className="panel-kicker">New review</div><h2>Inspect a pull request</h2><label htmlFor="repo">Repository<input id="repo" value={repo} onChange={e => setRepo(e.target.value)} placeholder="owner/repository" autoComplete="off" /></label><label htmlFor="pr">Pull request<input id="pr" value={pr} onChange={e => setPr(e.target.value)} placeholder="42" inputMode="numeric" /></label><label htmlFor="endpoint">LLM endpoint<select id="endpoint" value={endpoint} onChange={e => setEndpoint(e.target.value)}><option value="auto">Automatic fallback</option><option value="gemini">Gemini</option><option value="groq">Groq</option></select></label><details className="custom-provider"><summary>Use your own provider key (used only for this review)</summary><label htmlFor="provider">Provider<select id="provider" value={provider} onChange={e => setProvider(e.target.value)}><option value="">Choose provider</option><option value="openai">OpenAI-compatible</option><option value="anthropic">Anthropic</option><option value="google">Google</option></select></label><label htmlFor="model">Model<input id="model" value={model} onChange={e => setModel(e.target.value)} placeholder="model-name" autoComplete="off" /></label><label htmlFor="api-key">API key<input id="api-key" type="password" value={apiKey} onChange={e => setApiKey(e.target.value)} placeholder="Used only for this review" autoComplete="off" /></label><label htmlFor="base-url">Base URL <span>(optional)</span><input id="base-url" value={baseUrl} onChange={e => setBaseUrl(e.target.value)} placeholder="https://api.example.com/v1" autoComplete="off" /></label></details><button type="submit" disabled={busy}>{busy && !job ? "Queueing review…" : "Start review"}<span aria-hidden="true">↗</span></button>{(error || message) && <div className={`message ${error ? "error" : "success"}`} role="status" aria-live="polite">{error || message}</div>}{job && <div className="job-card"><div><strong>Review {job.id?.slice(0, 8)}</strong><small>{job.repo} · PR #{job.pr_number}</small></div><span className={`pill ${job.status}`}>{pretty(job.status)}</span></div>}{job && !isTerminal && <div className="progress" role="progressbar" aria-label={`Review ${pretty(job.status)}`}><span /><small>Analysis is running. This may take a few minutes.</small></div>}<div className="results"><Verdict job={job} /><Ragas ragas={job?.ragas} />{job?.findings && <Findings findings={job.findings} />}{job?.status === "awaiting_approval" && <div className="actions"><button type="button" onClick={() => decide("approve")} disabled={busy}>Approve &amp; post</button><button type="button" className="secondary" onClick={() => decide("reject")} disabled={busy}>Reject</button></div>}<Receipt result={job?.posting_result} />{job?.error && <div className="error detail">{job.error}</div>}</div></form><aside className="panel signal-panel"><div className="panel-kicker">What you receive</div><div className="signal"><strong>01</strong><span><b>Evidence-grounded findings</b><small>Code locations, severity, and confidence</small></span></div><div className="signal"><strong>02</strong><span><b>Human checkpoint</b><small>Approve or reject before GitHub comments</small></span></div><div className="signal"><strong>03</strong><span><b>Delivery receipt</b><small>See exactly what reached GitHub</small></span></div></aside></section></main><footer>OpenCodeReview <span>·</span> React review workspace <span>·</span> API keys stay server-side</footer></div>;
45
  }
46
  createRoot(document.getElementById("root")).render(<App />);