DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Block 7.5: i18n completion, WS reconnect with backoff, error retry button
unknown91dbafbe75c9
diff --git a/web/app/(workspace)/learning/[bookId]/page.tsx b/web/app/(workspace)/learning/[bookId]/page.tsxindex 6fced288c..b373ed733 100644--- a/web/app/(workspace)/learning/[bookId]/page.tsx+++ b/web/app/(workspace)/learning/[bookId]/page.tsx@@ -22,22 +22,6 @@ interface StageProgress {content: string;}-const STAGE_LABELS: Record<string, string> = {- diagnostic_phase1: "Diagnostic Phase 1",- diagnostic_phase2: "Diagnostic Phase 2",- metacognitive_intro: "Metacognitive Intro",- plan: "Study Plan",- pretest: "Pretest",- explain: "Explain",- feynman_check: "Feynman Check",- practice_quiz: "Practice Quiz",- practice: "Practice",- error_diagnosis: "Error Diagnosis",- module_test: "Module Test",- review: "Review",- completed: "Completed",-};-export default function LearningBookPage() {const params = useParams<{ bookId: string }>();const { t } = useTranslation();@@ -51,6 +35,9 @@ export default function LearningBookPage() {const activeTurnRetryRef = useRef<boolean>(false);const [toast, setToast] = useState("");const wsRef = useRef<WebSocket | null>(null);+ const reconnectAttemptsRef = useRef(0);+ const intentionalCloseRef = useRef(false);+ const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);interface ModuleData {id: string;@@ -86,12 +73,20 @@ export default function LearningBookPage() {const handleStreamEventRef = useRef<(evt: StreamEvent) => void>(() => {});const connect = useCallback(() => {+ // Clear any pending reconnect timer+ if (reconnectTimerRef.current) {+ clearTimeout(reconnectTimerRef.current);+ reconnectTimerRef.current = null;+ }+ intentionalCloseRef.current = false;+const ws = new WebSocket(wsUrl("/api/v1/ws"));wsRef.current = ws;ws.onopen = () => {setConnecting(false);setError(null);+ reconnectAttemptsRef.current = 0;ws.send(JSON.stringify({type: "start_turn",session_id: params.bookId,@@ -110,8 +105,19 @@ export default function LearningBookPage() {};ws.onerror = () => setError(t("guidedLearning.connectionError"));- ws.onclose = () => setConnecting(true);- }, [params.bookId]);+ ws.onclose = () => {+ if (intentionalCloseRef.current) return;+ setConnecting(true);+ if (reconnectAttemptsRef.current < 5) {+ const delay = Math.min(1000 * Math.pow(2, reconnectAttemptsRef.current), 10000);+ reconnectAttemptsRef.current += 1;+ reconnectTimerRef.current = setTimeout(() => connect(), delay);+ } else {+ setError(t("guidedLearning.connectionError"));+ setConnecting(false);+ }+ };+ }, [params.bookId, t]);const handleStreamEvent = (evt: StreamEvent) => {// Capture turn_id from any event that carries it@@ -244,7 +250,14 @@ export default function LearningBookPage() {useEffect(() => {connect();- return () => { wsRef.current?.close(); };+ return () => {+ intentionalCloseRef.current = true;+ if (reconnectTimerRef.current) {+ clearTimeout(reconnectTimerRef.current);+ reconnectTimerRef.current = null;+ }+ wsRef.current?.close();+ };}, [connect]);return (@@ -282,7 +295,7 @@ export default function LearningBookPage() {s.status === "completed" ? "✓" : s.status === "error" ? "✗" : "○"}</span><span className={s.status === "active" ? "text-[var(--foreground)]" : "text-[var(--muted-foreground)]"}>- {STAGE_LABELS[s.stage] || s.stage}+ {t(`guidedLearning.stage.${s.stage}`, s.stage)}</span></div>))}@@ -290,7 +303,21 @@ export default function LearningBookPage() {</div>{/* Content area */}<div className="flex-1 p-8 overflow-y-auto">- {error && <div className="text-red-500 mb-4">{error}</div>}+ {error && (+ <div className="text-red-500 mb-4 flex items-center gap-2">+ <span>{error}</span>+ <button+ onClick={() => {+ setError(null);+ reconnectAttemptsRef.current = 0;+ connect();+ }}+ className="px-3 py-1 text-sm rounded bg-[var(--primary)] text-[var(--primary-foreground)] hover:opacity-90"+ >+ {t("guidedLearning.reconnect", "Reconnect")}+ </button>+ </div>+ )}{(stages.find(s => s.status === "active") || stages.find(s => s.status === "completed" && s.content))?.content ? (<div className="prose dark:prose-invert max-w-none whitespace-pre-wrap">{(stages.find(s => s.status === "active") || stages.find(s => s.status === "completed" && s.content))?.content}diff --git a/web/components/learning/ModuleTree.tsx b/web/components/learning/ModuleTree.tsxindex 0f0fe3817..d38a7d6da 100644--- a/web/components/learning/ModuleTree.tsx+++ b/web/components/learning/ModuleTree.tsx@@ -2,6 +2,7 @@import { useState, useEffect } from "react";import { ChevronRight, ChevronDown, Circle } from "lucide-react";+import { useTranslation } from "react-i18next";interface KnowledgePoint {id: string;@@ -99,12 +100,13 @@ export default function ModuleTree({currentModuleId,currentStage,}: ModuleTreeProps) {+ const { t } = useTranslation();const sorted = [...modules].sort((a, b) => a.order - b.order);if (sorted.length === 0) {return (<div className="text-sm text-[var(--muted-foreground)] px-2 py-1">- No modules loaded+ {t("guidedLearning.noModulesLoaded")}</div>);}diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 383a15778..efaa4b356 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -1619,6 +1619,22 @@"guidedLearning.stageFailed": "Stage execution failed. Progress saved, will retry this stage.","guidedLearning.moduleProgress": "{{count}} knowledge point(s)","guidedLearning.masteredProgress": "{{mastered}}/{{total}} mastered",+ "guidedLearning.inputPlaceholder": "Type your answer...",+ "guidedLearning.submit": "Submit",+ "guidedLearning.noModulesLoaded": "No modules loaded",+ "guidedLearning.stage.diagnostic_phase1": "Diagnostic Phase 1",+ "guidedLearning.stage.diagnostic_phase2": "Diagnostic Phase 2",+ "guidedLearning.stage.metacognitive_intro": "Metacognitive Intro",+ "guidedLearning.stage.plan": "Learning Plan",+ "guidedLearning.stage.pretest": "Pretest",+ "guidedLearning.stage.explain": "Explain",+ "guidedLearning.stage.feynman_check": "Feynman Check",+ "guidedLearning.stage.practice_quiz": "Practice Quiz",+ "guidedLearning.stage.practice": "Practice",+ "guidedLearning.stage.error_diagnosis": "Error Diagnosis",+ "guidedLearning.stage.module_test": "Module Test",+ "guidedLearning.stage.review": "Review",+ "guidedLearning.stage.completed": "Completed","knowledgeType.memory": "Rote Memory","knowledgeType.concept": "Conceptual","knowledgeType.procedure": "Procedural",diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 09d91a49d..8fa5fdd1a 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -1619,6 +1619,22 @@"guidedLearning.stageFailed": "阶段执行失败。进度已保存,将重试该阶段。","guidedLearning.moduleProgress": "{{count}} 个知识点","guidedLearning.masteredProgress": "已掌握 {{mastered}}/{{total}}",+ "guidedLearning.inputPlaceholder": "输入你的答案...",+ "guidedLearning.submit": "提交",+ "guidedLearning.noModulesLoaded": "暂无模块",+ "guidedLearning.stage.diagnostic_phase1": "诊断阶段一",+ "guidedLearning.stage.diagnostic_phase2": "诊断阶段二",+ "guidedLearning.stage.metacognitive_intro": "元认知导入",+ "guidedLearning.stage.plan": "学习计划",+ "guidedLearning.stage.pretest": "预测试",+ "guidedLearning.stage.explain": "讲解",+ "guidedLearning.stage.feynman_check": "费曼检验",+ "guidedLearning.stage.practice_quiz": "练习测验",+ "guidedLearning.stage.practice": "练习",+ "guidedLearning.stage.error_diagnosis": "错因诊断",+ "guidedLearning.stage.module_test": "模块测试",+ "guidedLearning.stage.review": "复习",+ "guidedLearning.stage.completed": "已完成","knowledgeType.memory": "记忆型","knowledgeType.concept": "概念型","knowledgeType.procedure": "程序型",