Skip to content

Commit a614991

Browse files
committed
fix: poll API for document status, show processing state correctly
1 parent 338f5b2 commit a614991

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

rag/apps/ingest-service/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "bun --hot index.ts"
88
},
99
"dependencies": {
10-
"@rag-demo/shared": "workspace:*"
10+
"@rag-demo/shared": "workspace:*",
11+
"@superdoc-dev/cli": "latest"
1112
}
1213
}

rag/apps/web/components/FileSidebar.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,31 @@ export function FileSidebar({ activeDocId, onSelectDoc }: Props) {
2525
const docs = await listDocuments();
2626
setDocuments(docs);
2727
setEntries((prev) => {
28-
const processing = prev.filter(
29-
(e) => e.status !== "ready" && e.status !== "error",
28+
const uploading = prev.filter(
29+
(e) => e.status === "queued" && !docs.some((d) => d.id === e.docId),
3030
);
31-
const ready: FileEntry[] = docs
32-
.filter((d) => !processing.some((p) => p.docId === d.id))
33-
.map((d) => ({
34-
key: `doc-${d.id}`,
35-
filename: d.filename,
36-
docId: d.id,
37-
status: "ready",
38-
}));
39-
return [...processing, ...ready];
31+
const fromApi: FileEntry[] = docs.map((d) => ({
32+
key: `doc-${d.id}`,
33+
filename: d.filename,
34+
docId: d.id,
35+
status: d.status === "ready" ? "ready" : "extracting",
36+
}));
37+
return [...uploading, ...fromApi];
4038
});
4139
}, []);
4240

4341
useEffect(() => {
4442
refreshDocs();
4543
}, [refreshDocs]);
4644

45+
// Auto-poll while any documents are still processing
46+
useEffect(() => {
47+
const hasProcessing = entries.some((e) => e.status === "extracting");
48+
if (!hasProcessing) return;
49+
const interval = setInterval(refreshDocs, 3000);
50+
return () => clearInterval(interval);
51+
}, [entries, refreshDocs]);
52+
4753
function updateEntry(key: string, update: Partial<FileEntry>) {
4854
setEntries((prev) =>
4955
prev.map((e) => (e.key === key ? { ...e, ...update } : e)),
@@ -54,22 +60,9 @@ export function FileSidebar({ activeDocId, onSelectDoc }: Props) {
5460
try {
5561
updateEntry(key, { status: "extracting" });
5662
const result = await ingestDocument(file);
57-
const docId = result.documentId;
58-
updateEntry(key, { status: "extracting", docId });
59-
60-
// Poll until the document is ready (ingest service processes it async)
61-
const maxAttempts = 60;
62-
for (let i = 0; i < maxAttempts; i++) {
63-
await new Promise((r) => setTimeout(r, 3000));
64-
const docs = await listDocuments();
65-
const doc = docs.find((d) => d.id === docId);
66-
if (doc?.status === "ready") {
67-
updateEntry(key, { status: "ready", docId });
68-
setDocuments(docs);
69-
return;
70-
}
71-
}
72-
updateEntry(key, { status: "error", detail: "Timed out" });
63+
updateEntry(key, { status: "extracting", docId: result.documentId });
64+
// Auto-poll effect will pick up status changes
65+
refreshDocs();
7366
} catch (err) {
7467
updateEntry(key, {
7568
status: "error",

0 commit comments

Comments
 (0)