Spaces:
Running
Running
Deploy 5e8f0b71
Browse files- frontend/src/main.jsx +2 -0
frontend/src/main.jsx
CHANGED
|
@@ -48,6 +48,7 @@ function App() {
|
|
| 48 |
}, [job?.id, isTerminal]);
|
| 49 |
useEffect(() => { localStorage.setItem("ocr-providers", JSON.stringify(savedProviders)); }, [savedProviders]);
|
| 50 |
const customProvider = endpoint === "custom" || endpoint.startsWith("saved:");
|
|
|
|
| 51 |
function addProvider() { if (!provider || !model || !apiKey) { setError("Enter a provider, model, and API key first."); return; } const name = `${provider} / ${model}`; setSavedProviders(current => current.some(item => item.name === name) ? current : [...current, { name, provider, model, apiKey, baseUrl }]); setError(""); setMessage(`${name} added for this review.`); }
|
| 52 |
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); } }
|
| 53 |
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); } }
|
|
@@ -68,3 +69,4 @@ createRoot(document.getElementById("root")).render(<App />);
|
|
| 68 |
|
| 69 |
|
| 70 |
|
|
|
|
|
|
| 48 |
}, [job?.id, isTerminal]);
|
| 49 |
useEffect(() => { localStorage.setItem("ocr-providers", JSON.stringify(savedProviders)); }, [savedProviders]);
|
| 50 |
const customProvider = endpoint === "custom" || endpoint.startsWith("saved:");
|
| 51 |
+
function testProvider() { if (!provider || !model || !apiKey) { setError("Enter provider, model, and API key before testing."); return; } setError(""); setMessage(`${provider} / ${model} is configured and ready to test.`); }
|
| 52 |
function addProvider() { if (!provider || !model || !apiKey) { setError("Enter a provider, model, and API key first."); return; } const name = `${provider} / ${model}`; setSavedProviders(current => current.some(item => item.name === name) ? current : [...current, { name, provider, model, apiKey, baseUrl }]); setError(""); setMessage(`${name} added for this review.`); }
|
| 53 |
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); } }
|
| 54 |
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); } }
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
+
|