Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

feat(attachments): show PDF transfer before parser progress (#1523)

Bingxi Zhao (Frank)8f3689cdc6bc
diff --git a/web/components/chat/home/AttachmentProcessingStatus.tsx b/web/components/chat/home/AttachmentProcessingStatus.tsx
index 1420772ca..2263ee0bf 100644
--- a/web/components/chat/home/AttachmentProcessingStatus.tsx
+++ b/web/components/chat/home/AttachmentProcessingStatus.tsx
@@ -17,6 +17,8 @@ function phaseLabel(
t: (key: string) => string,
): string {
switch (phase) {
+ case "uploading":
+ return t("Sending to DeepTutor");
case "received":
return t("Uploaded to DeepTutor");
case "submitting":
diff --git a/web/features/chat/selectors/attachment-processing.ts b/web/features/chat/selectors/attachment-processing.ts
index bbb623f31..7c5664f22 100644
--- a/web/features/chat/selectors/attachment-processing.ts
+++ b/web/features/chat/selectors/attachment-processing.ts
@@ -1,6 +1,7 @@
import type { StreamEvent } from "@/features/chat/model/protocol";
export type AttachmentProcessingPhase =
+ | "uploading"
| "received"
| "submitting"
| "parsing"
@@ -19,6 +20,7 @@ export interface AttachmentProcessingItem {
interface MessageWithEvents {
role: string;
events?: StreamEvent[];
+ attachments?: Array<{ filename?: string; mime_type?: string }>;
}
const PHASES = new Set<AttachmentProcessingPhase>([
@@ -56,17 +58,43 @@ export function selectAttachmentProcessing(
messages: MessageWithEvents[],
isStreaming: boolean,
): AttachmentProcessingItem[] {
- const latest = [...messages]
- .reverse()
- .find((message) => message.role === "assistant");
- if (!latest) return [];
+ const userIndex = messages.findLastIndex((message) => message.role === "user");
+ const assistantIndex = messages.findLastIndex((message) => message.role === "assistant");
+ const latest = assistantIndex > userIndex ? messages[assistantIndex] : null;
+ if (!latest && !isStreaming) return [];
const byAttachment = new Map<string, AttachmentProcessingItem>();
- for (const event of latest.events ?? []) {
+ for (const event of latest?.events ?? []) {
const item = parsingEvent(event);
if (item) byAttachment.set(item.attachmentId, item);
}
const items = [...byAttachment.values()];
+ // Before the first server progress event the PDF is travelling in the
+ // start_turn WebSocket payload. This is a stage, not a byte percentage:
+ // browser WebSocket.send does not expose upload progress (#1523).
+ if (isStreaming && userIndex >= 0) {
+ const receivedByName = new Map<string, number>();
+ for (const item of items) {
+ receivedByName.set(item.filename, (receivedByName.get(item.filename) ?? 0) + 1);
+ }
+ for (const [index, attachment] of (messages[userIndex].attachments ?? []).entries()) {
+ const filename = attachment.filename ?? "";
+ if (attachment.mime_type !== "application/pdf" && !filename.toLowerCase().endsWith(".pdf")) {
+ continue;
+ }
+ const received = receivedByName.get(filename) ?? 0;
+ if (received) {
+ receivedByName.set(filename, received - 1);
+ } else {
+ items.push({
+ attachmentId: `uploading:${index}`,
+ filename,
+ phase: "uploading",
+ detail: "",
+ });
+ }
+ }
+ }
if (isStreaming) return items;
return items.filter(
(item) => item.phase === "failed" || item.phase === "fallback",
diff --git a/web/locales/de/app.json b/web/locales/de/app.json
index dc13a3d61..2b7cbcf41 100644
--- a/web/locales/de/app.json
+++ b/web/locales/de/app.json
@@ -55,6 +55,7 @@
"Attach": "Anhängen",
"Attach files": "Dateien anhängen",
"Uploaded to DeepTutor": "Zu DeepTutor hochgeladen",
+ "Sending to DeepTutor": "Wird an DeepTutor gesendet",
"Sending to document parser": "Wird an den Dokumenten-Parser gesendet",
"Document parser is processing": "Dokumenten-Parser verarbeitet",
"Retrieving parsed result": "Analysiertes Ergebnis wird abgerufen",
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index b5fdcd656..833df31c3 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -55,6 +55,7 @@
"Attach": "Attach",
"Attach files": "Attach files",
"Uploaded to DeepTutor": "Uploaded to DeepTutor",
+ "Sending to DeepTutor": "Sending to DeepTutor",
"Sending to document parser": "Sending to document parser",
"Document parser is processing": "Document parser is processing",
"Retrieving parsed result": "Retrieving parsed result",
diff --git a/web/locales/fr/app.json b/web/locales/fr/app.json
index 98b3730aa..5859ca4be 100644
--- a/web/locales/fr/app.json
+++ b/web/locales/fr/app.json
@@ -5457,6 +5457,7 @@
"Upload a PDF to mimic its question style.": "Envoyez un PDF pour imiter son style de questions.",
"Upload books in Reading before assigning them.": "Envoyez des livres dans Lecture avant de les attribuer.",
"Uploaded to DeepTutor": "Envoyé à DeepTutor",
+ "Sending to DeepTutor": "Envoi vers DeepTutor",
"Usage activity": "Activité d'utilisation",
"Usage by model": "Utilisation par modèle",
"Usage statistics": "Statistiques d'utilisation",
diff --git a/web/locales/uk/app.json b/web/locales/uk/app.json
index 7633102b2..9c1a6c9fa 100644
--- a/web/locales/uk/app.json
+++ b/web/locales/uk/app.json
@@ -4038,6 +4038,7 @@
"Review rebuild": "Огляд перебудови",
"Attachment processing": "Обробка вкладень",
"Uploaded to DeepTutor": "Завантажено в DeepTutor",
+ "Sending to DeepTutor": "Надсилання до DeepTutor",
"Sending to document parser": "Надсилання до аналізатора документів",
"Document parser is processing": "Аналізатор обробляє документ",
"Retrieving parsed result": "Отримання проаналізованого результату",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index aee79cd7c..63465a075 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -55,6 +55,7 @@
"Attach": "附件",
"Attach files": "上传附件",
"Uploaded to DeepTutor": "已上传到 DeepTutor",
+ "Sending to DeepTutor": "正在发送到 DeepTutor",
"Sending to document parser": "正在提交到文档解析器",
"Document parser is processing": "文档解析器正在处理",
"Retrieving parsed result": "正在获取解析结果",
diff --git a/web/tests/attachment-processing-status.spec.tsx b/web/tests/attachment-processing-status.spec.tsx
index 69832f9e2..dd8bee3ec 100644
--- a/web/tests/attachment-processing-status.spec.tsx
+++ b/web/tests/attachment-processing-status.spec.tsx
@@ -61,6 +61,27 @@ it("keeps one latest parser stage per attachment during a live turn", () => {
]);
});
+it("shows PDF transfer before server receipt and replaces it with confirmed progress", () => {
+ const user = {
+ role: "user",
+ attachments: [{ filename: "notes.pdf", mime_type: "application/pdf" }],
+ };
+ expect(selectAttachmentProcessing([user, { role: "assistant", events: [] }], true)).toEqual([
+ { attachmentId: "uploading:0", filename: "notes.pdf", phase: "uploading", detail: "" },
+ ]);
+
+ const confirmed = selectAttachmentProcessing([
+ user,
+ { role: "assistant", events: [progress("stored-a", "notes.pdf", "received", "Uploaded")] },
+ ], true);
+ expect(confirmed).toEqual([
+ { attachmentId: "stored-a", filename: "notes.pdf", phase: "received", detail: "Uploaded" },
+ ]);
+ render(<AttachmentProcessingStatus items={confirmed} />);
+ expect(screen.getByText("Uploaded to DeepTutor")).toBeVisible();
+ expect(selectAttachmentProcessing([user, { role: "assistant", events: [] }], false)).toEqual([]);
+});
+
it("hides settled success but preserves parser failure details", () => {
const items = selectAttachmentProcessing(
[