Spaces:
Sleeping
Sleeping
multiple
Browse files- src/App.js +130 -0
- src/api.js +107 -0
src/App.js
CHANGED
|
@@ -12,11 +12,15 @@ import {
|
|
| 12 |
getMe,
|
| 13 |
registerUser,
|
| 14 |
listSessionLemmas,
|
|
|
|
| 15 |
clearSession,
|
| 16 |
exportSessionLemmas,
|
|
|
|
| 17 |
promoteSessionLemmas,
|
| 18 |
discoverMath,
|
| 19 |
proveGoal,
|
|
|
|
|
|
|
| 20 |
} from "./api";
|
| 21 |
import "./App.css";
|
| 22 |
|
|
@@ -87,9 +91,14 @@ function App() {
|
|
| 87 |
|
| 88 |
// Session Memory UI state
|
| 89 |
const [sessionLemmas, setSessionLemmas] = useState([]);
|
|
|
|
| 90 |
const [sessionPanelStatus, setSessionPanelStatus] = useState(null);
|
| 91 |
const [sessionPanelLoading, setSessionPanelLoading] = useState(false);
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
// ---------------------------
|
| 94 |
// Admin Register State
|
| 95 |
// ---------------------------
|
|
@@ -267,6 +276,62 @@ function App() {
|
|
| 267 |
try {
|
| 268 |
const res = await listSessionLemmas(sessionId, token);
|
| 269 |
setSessionLemmas(res.lemmas || []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
} catch (err) {
|
| 271 |
setSessionPanelStatus(`Error: ${err.message}`);
|
| 272 |
} finally {
|
|
@@ -370,6 +435,20 @@ function App() {
|
|
| 370 |
}
|
| 371 |
}
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
React.useEffect(() => {
|
| 374 |
if (showSessionPanel && token) {
|
| 375 |
refreshSessionMemory();
|
|
@@ -781,6 +860,50 @@ function App() {
|
|
| 781 |
✅ Promote (Bench-Gated)
|
| 782 |
</button>
|
| 783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
{sessionPanelStatus && (
|
| 785 |
<div className="status-message" style={{ marginTop: "10px" }}>
|
| 786 |
{sessionPanelStatus}
|
|
@@ -793,6 +916,13 @@ function App() {
|
|
| 793 |
{JSON.stringify(sessionLemmas || [], null, 2)}
|
| 794 |
</pre>
|
| 795 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
</aside>
|
| 797 |
)}
|
| 798 |
</div>
|
|
|
|
| 12 |
getMe,
|
| 13 |
registerUser,
|
| 14 |
listSessionLemmas,
|
| 15 |
+
listSessionDocs,
|
| 16 |
clearSession,
|
| 17 |
exportSessionLemmas,
|
| 18 |
+
rollbackSessionPromotion,
|
| 19 |
promoteSessionLemmas,
|
| 20 |
discoverMath,
|
| 21 |
proveGoal,
|
| 22 |
+
ingestArxivToSession,
|
| 23 |
+
ingestStoryToSession,
|
| 24 |
} from "./api";
|
| 25 |
import "./App.css";
|
| 26 |
|
|
|
|
| 91 |
|
| 92 |
// Session Memory UI state
|
| 93 |
const [sessionLemmas, setSessionLemmas] = useState([]);
|
| 94 |
+
const [sessionDocs, setSessionDocs] = useState({ papers: [], stories: [] });
|
| 95 |
const [sessionPanelStatus, setSessionPanelStatus] = useState(null);
|
| 96 |
const [sessionPanelLoading, setSessionPanelLoading] = useState(false);
|
| 97 |
|
| 98 |
+
// Ingestion UI state
|
| 99 |
+
const [arxivIdInput, setArxivIdInput] = useState("");
|
| 100 |
+
const [storyUrlInput, setStoryUrlInput] = useState("");
|
| 101 |
+
|
| 102 |
// ---------------------------
|
| 103 |
// Admin Register State
|
| 104 |
// ---------------------------
|
|
|
|
| 276 |
try {
|
| 277 |
const res = await listSessionLemmas(sessionId, token);
|
| 278 |
setSessionLemmas(res.lemmas || []);
|
| 279 |
+
try {
|
| 280 |
+
const docs = await listSessionDocs(sessionId, token);
|
| 281 |
+
setSessionDocs({ papers: docs.papers || [], stories: docs.stories || [] });
|
| 282 |
+
} catch {
|
| 283 |
+
// ignore
|
| 284 |
+
}
|
| 285 |
+
} catch (err) {
|
| 286 |
+
setSessionPanelStatus(`Error: ${err.message}`);
|
| 287 |
+
} finally {
|
| 288 |
+
setSessionPanelLoading(false);
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
async function handleIngestArxiv() {
|
| 293 |
+
if (!token) return;
|
| 294 |
+
setSessionPanelStatus(null);
|
| 295 |
+
setSessionPanelLoading(true);
|
| 296 |
+
try {
|
| 297 |
+
const id = (arxivIdInput || "").trim();
|
| 298 |
+
if (!id) {
|
| 299 |
+
setSessionPanelStatus("Error: Missing arXiv id (or URL). ");
|
| 300 |
+
return;
|
| 301 |
+
}
|
| 302 |
+
const res = await ingestArxivToSession(sessionId, token, id, 200, false);
|
| 303 |
+
const stagedParas = res.staged && typeof res.staged.paragraphs === "number" ? res.staged.paragraphs : null;
|
| 304 |
+
setSessionPanelStatus(
|
| 305 |
+
stagedParas !== null
|
| 306 |
+
? `Ingested ${res.arxiv_id || id} and staged ${stagedParas} paragraphs into this session.`
|
| 307 |
+
: `Ingested ${res.arxiv_id || id} into this session.`
|
| 308 |
+
);
|
| 309 |
+
await refreshSessionMemory();
|
| 310 |
+
} catch (err) {
|
| 311 |
+
setSessionPanelStatus(`Error: ${err.message}`);
|
| 312 |
+
} finally {
|
| 313 |
+
setSessionPanelLoading(false);
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
async function handleIngestStory() {
|
| 318 |
+
if (!token) return;
|
| 319 |
+
setSessionPanelStatus(null);
|
| 320 |
+
setSessionPanelLoading(true);
|
| 321 |
+
try {
|
| 322 |
+
const url = (storyUrlInput || "").trim();
|
| 323 |
+
if (!url) {
|
| 324 |
+
setSessionPanelStatus("Error: Missing story URL.");
|
| 325 |
+
return;
|
| 326 |
+
}
|
| 327 |
+
const res = await ingestStoryToSession(sessionId, token, url, "story", "", 200);
|
| 328 |
+
const stagedParas = res.staged && typeof res.staged.paragraphs === "number" ? res.staged.paragraphs : null;
|
| 329 |
+
setSessionPanelStatus(
|
| 330 |
+
stagedParas !== null
|
| 331 |
+
? `Ingested story and staged ${stagedParas} paragraphs into this session.`
|
| 332 |
+
: "Ingested story into this session."
|
| 333 |
+
);
|
| 334 |
+
await refreshSessionMemory();
|
| 335 |
} catch (err) {
|
| 336 |
setSessionPanelStatus(`Error: ${err.message}`);
|
| 337 |
} finally {
|
|
|
|
| 435 |
}
|
| 436 |
}
|
| 437 |
|
| 438 |
+
async function handleRollbackPromotion() {
|
| 439 |
+
if (!token) return;
|
| 440 |
+
setSessionPanelStatus(null);
|
| 441 |
+
setSessionPanelLoading(true);
|
| 442 |
+
try {
|
| 443 |
+
const res = await rollbackSessionPromotion(sessionId, token, false);
|
| 444 |
+
setSessionPanelStatus(`Rolled back promotion: ${res.file || "(unknown file)"}`);
|
| 445 |
+
} catch (err) {
|
| 446 |
+
setSessionPanelStatus(`Error: ${err.message}`);
|
| 447 |
+
} finally {
|
| 448 |
+
setSessionPanelLoading(false);
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
React.useEffect(() => {
|
| 453 |
if (showSessionPanel && token) {
|
| 454 |
refreshSessionMemory();
|
|
|
|
| 860 |
✅ Promote (Bench-Gated)
|
| 861 |
</button>
|
| 862 |
|
| 863 |
+
<button
|
| 864 |
+
className="btn-secondary"
|
| 865 |
+
onClick={handleRollbackPromotion}
|
| 866 |
+
style={{ marginTop: "10px", width: "100%" }}
|
| 867 |
+
disabled={sessionPanelLoading}
|
| 868 |
+
>
|
| 869 |
+
↩ Rollback Last Promotion
|
| 870 |
+
</button>
|
| 871 |
+
|
| 872 |
+
<div style={{ marginTop: "15px" }}>
|
| 873 |
+
<h4>📄 Ingest (Stage into session)</h4>
|
| 874 |
+
<input
|
| 875 |
+
type="text"
|
| 876 |
+
placeholder="arXiv id or URL (e.g., 1706.03762)"
|
| 877 |
+
value={arxivIdInput}
|
| 878 |
+
onChange={(e) => setArxivIdInput(e.target.value)}
|
| 879 |
+
style={{ width: "100%", marginTop: "10px" }}
|
| 880 |
+
/>
|
| 881 |
+
<button
|
| 882 |
+
className="btn-secondary"
|
| 883 |
+
onClick={handleIngestArxiv}
|
| 884 |
+
style={{ marginTop: "10px", width: "100%" }}
|
| 885 |
+
disabled={sessionPanelLoading}
|
| 886 |
+
>
|
| 887 |
+
📄 Ingest arXiv → Stage
|
| 888 |
+
</button>
|
| 889 |
+
|
| 890 |
+
<input
|
| 891 |
+
type="text"
|
| 892 |
+
placeholder="Story URL (e.g., Project Gutenberg .txt)"
|
| 893 |
+
value={storyUrlInput}
|
| 894 |
+
onChange={(e) => setStoryUrlInput(e.target.value)}
|
| 895 |
+
style={{ width: "100%", marginTop: "10px" }}
|
| 896 |
+
/>
|
| 897 |
+
<button
|
| 898 |
+
className="btn-secondary"
|
| 899 |
+
onClick={handleIngestStory}
|
| 900 |
+
style={{ marginTop: "10px", width: "100%" }}
|
| 901 |
+
disabled={sessionPanelLoading}
|
| 902 |
+
>
|
| 903 |
+
📚 Ingest Story → Stage
|
| 904 |
+
</button>
|
| 905 |
+
</div>
|
| 906 |
+
|
| 907 |
{sessionPanelStatus && (
|
| 908 |
<div className="status-message" style={{ marginTop: "10px" }}>
|
| 909 |
{sessionPanelStatus}
|
|
|
|
| 916 |
{JSON.stringify(sessionLemmas || [], null, 2)}
|
| 917 |
</pre>
|
| 918 |
</div>
|
| 919 |
+
|
| 920 |
+
<div className="query-results" style={{ marginTop: "15px" }}>
|
| 921 |
+
<h4>Staged docs</h4>
|
| 922 |
+
<pre style={{ fontSize: "0.85em", overflowX: "auto" }}>
|
| 923 |
+
{JSON.stringify(sessionDocs || { papers: [], stories: [] }, null, 2)}
|
| 924 |
+
</pre>
|
| 925 |
+
</div>
|
| 926 |
</aside>
|
| 927 |
)}
|
| 928 |
</div>
|
src/api.js
CHANGED
|
@@ -172,6 +172,30 @@ export async function listSessionLemmas(sessionId, token) {
|
|
| 172 |
}
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
export async function clearSession(sessionId, token) {
|
| 176 |
const res = await fetch(`${API_BASE}/session/clear`, {
|
| 177 |
method: "POST",
|
|
@@ -196,6 +220,89 @@ export async function clearSession(sessionId, token) {
|
|
| 196 |
}
|
| 197 |
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
export async function exportSessionLemmas(sessionId, token, note = null) {
|
| 200 |
const res = await fetch(`${API_BASE}/session/export`, {
|
| 201 |
method: "POST",
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
|
| 175 |
+
export async function listSessionDocs(sessionId, token) {
|
| 176 |
+
const res = await fetch(`${API_BASE}/session/docs`, {
|
| 177 |
+
method: "POST",
|
| 178 |
+
headers: {
|
| 179 |
+
"Content-Type": "application/json",
|
| 180 |
+
Authorization: `Bearer ${token}`,
|
| 181 |
+
},
|
| 182 |
+
body: JSON.stringify({ session_id: sessionId }),
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
if (!res.ok) {
|
| 186 |
+
const text = await res.text().catch(() => "");
|
| 187 |
+
throw new Error(`HTTP ${res.status}: ${text || "Request failed"}`);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
const json = await res.json();
|
| 191 |
+
if (!json.ok) {
|
| 192 |
+
throw new Error(json.error || "List session docs failed");
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
return json;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
|
| 199 |
export async function clearSession(sessionId, token) {
|
| 200 |
const res = await fetch(`${API_BASE}/session/clear`, {
|
| 201 |
method: "POST",
|
|
|
|
| 220 |
}
|
| 221 |
|
| 222 |
|
| 223 |
+
export async function ingestArxivToSession(sessionId, token, arxivIdOrUrl, maxParagraphs = 200, skipMarkitdown = false) {
|
| 224 |
+
const res = await fetch(`${API_BASE}/ingest/arxiv`, {
|
| 225 |
+
method: "POST",
|
| 226 |
+
headers: {
|
| 227 |
+
"Content-Type": "application/json",
|
| 228 |
+
Authorization: `Bearer ${token}`,
|
| 229 |
+
},
|
| 230 |
+
body: JSON.stringify({
|
| 231 |
+
session_id: sessionId,
|
| 232 |
+
arxiv_id: arxivIdOrUrl,
|
| 233 |
+
max_paragraphs: maxParagraphs,
|
| 234 |
+
skip_markitdown: skipMarkitdown,
|
| 235 |
+
}),
|
| 236 |
+
});
|
| 237 |
+
|
| 238 |
+
if (!res.ok) {
|
| 239 |
+
const text = await res.text().catch(() => "");
|
| 240 |
+
throw new Error(`HTTP ${res.status}: ${text || "Request failed"}`);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
const json = await res.json();
|
| 244 |
+
if (!json.ok) {
|
| 245 |
+
throw new Error(json.error || "Ingest arXiv failed");
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
return json;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
export async function ingestStoryToSession(sessionId, token, url, storyId = "story", title = "", maxParagraphs = 200) {
|
| 253 |
+
const res = await fetch(`${API_BASE}/ingest/story`, {
|
| 254 |
+
method: "POST",
|
| 255 |
+
headers: {
|
| 256 |
+
"Content-Type": "application/json",
|
| 257 |
+
Authorization: `Bearer ${token}`,
|
| 258 |
+
},
|
| 259 |
+
body: JSON.stringify({
|
| 260 |
+
session_id: sessionId,
|
| 261 |
+
url,
|
| 262 |
+
story_id: storyId,
|
| 263 |
+
title,
|
| 264 |
+
max_paragraphs: maxParagraphs,
|
| 265 |
+
}),
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
if (!res.ok) {
|
| 269 |
+
const text = await res.text().catch(() => "");
|
| 270 |
+
throw new Error(`HTTP ${res.status}: ${text || "Request failed"}`);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
const json = await res.json();
|
| 274 |
+
if (!json.ok) {
|
| 275 |
+
throw new Error(json.error || "Ingest story failed");
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
return json;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
export async function rollbackSessionPromotion(sessionId, token, deleteFile = false) {
|
| 283 |
+
const res = await fetch(`${API_BASE}/session/rollback`, {
|
| 284 |
+
method: "POST",
|
| 285 |
+
headers: {
|
| 286 |
+
"Content-Type": "application/json",
|
| 287 |
+
Authorization: `Bearer ${token}`,
|
| 288 |
+
},
|
| 289 |
+
body: JSON.stringify({ session_id: sessionId, delete_file: deleteFile }),
|
| 290 |
+
});
|
| 291 |
+
|
| 292 |
+
if (!res.ok) {
|
| 293 |
+
const text = await res.text().catch(() => "");
|
| 294 |
+
throw new Error(`HTTP ${res.status}: ${text || "Request failed"}`);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
const json = await res.json();
|
| 298 |
+
if (!json.ok) {
|
| 299 |
+
throw new Error(json.error || "Rollback failed");
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
return json;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
|
| 306 |
export async function exportSessionLemmas(sessionId, token, note = null) {
|
| 307 |
const res = await fetch(`${API_BASE}/session/export`, {
|
| 308 |
method: "POST",
|