DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
perf(chat): load specialized teaching and handoff cards only when present
Bingxi Zhao (Frank)4b9b73a73f5c
diff --git a/web/features/chat/messages/ChatMessageList.tsx b/web/features/chat/messages/ChatMessageList.tsxindex c8e93ef37..6e3ef7f1f 100644--- a/web/features/chat/messages/ChatMessageList.tsx+++ b/web/features/chat/messages/ChatMessageList.tsx@@ -81,8 +81,6 @@ import {leadingTraceEvents,type MessageSegment,} from "@/components/chat/home/AskUserOptions";-import { MasteryQuestionCard } from "@/components/chat/home/MasteryQuestionCard";-import { MasterySourcePresentation } from "@/components/chat/home/MasterySourcePresentation";import {collectMasteryAnswerRejections,collectMasteryGrades,@@ -96,8 +94,6 @@ import { SetupCredentialCard } from "@/components/chat/home/SetupCredentialCard"import { extractSetupCredential } from "@/lib/setup-signals";import { PartnerDraftCard } from "@/components/chat/home/PartnerDraftCard";import { extractPartnerDraft } from "@/lib/partner-draft";-import { CourseHandoffCards } from "@/components/chat/home/CourseHandoffCard";-import { MasteryHandoffCards } from "@/components/chat/home/MasteryHandoffCard";import {extractCourseHandoffs,stripLeakedHandoffJson,@@ -127,6 +123,21 @@ const MathAnimatorViewer = dynamic(() => import("@/components/math-animator/MathAnimatorViewer"),{ ssr: false },);+const MasteryQuestionCard = dynamic(+ () => import("@/components/chat/home/MasteryQuestionCard"), { ssr: false },+);+const MasterySourcePresentation = dynamic(+ () => import("@/components/chat/home/MasterySourcePresentation").then(module => module.MasterySourcePresentation),+ { ssr: false },+);+const CourseHandoffCards = dynamic(+ () => import("@/components/chat/home/CourseHandoffCard").then(module => module.CourseHandoffCards),+ { ssr: false },+);+const MasteryHandoffCards = dynamic(+ () => import("@/components/chat/home/MasteryHandoffCard").then(module => module.MasteryHandoffCards),+ { ssr: false },+);const QuizViewer = dynamic(() => import("@/components/quiz/QuizViewer"), {ssr: false,});@@ -1188,7 +1199,11 @@ export const AssistantMessage = memo(function AssistantMessage({events={events}/>)}- <MasterySourcePresentation events={events} />+ {events.some(event => event.type === "sources" &&+ Array.isArray(event.metadata.sources) && event.metadata.sources.some(source =>+ source && typeof source === "object" &&+ (source.presentation === "teaching" || source.presentation === "reveal"))) &&+ <MasterySourcePresentation events={events} />}{/* Non-default branches (quiz, math animator, visualize) keep thecard below the body. The default branch inlines it via``messageSegments``; the research branch renders its own card@@ -1209,8 +1224,8 @@ export const AssistantMessage = memo(function AssistantMessage({{partnerDraft ? <PartnerDraftCard data={partnerDraft} /> : null}{/* Course Study's hand-offs sit last: they are what to do *after* readingthe answer, so they belong below it rather than competing with it. */}- <CourseHandoffCards handoffs={courseHandoffs} />- <MasteryHandoffCards handoffs={masteryHandoffs} />+ {courseHandoffs.length > 0 && <CourseHandoffCards handoffs={courseHandoffs} />}+ {masteryHandoffs.length > 0 && <MasteryHandoffCards handoffs={masteryHandoffs} />}</>);});diff --git a/web/tests/integration/mastery-teaching.spec.tsx b/web/tests/integration/mastery-teaching.spec.tsxindex 2e97d4e79..62999e876 100644--- a/web/tests/integration/mastery-teaching.spec.tsx+++ b/web/tests/integration/mastery-teaching.spec.tsx@@ -72,12 +72,12 @@ describe('mastery teaching beside a question', () => {{ extraTool: false, legacyCard: false },{ extraTool: true, legacyCard: false },{ extraTool: false, legacyCard: true },- ])('keeps teaching visible through completion and reload: %j', ({ extraTool, legacyCard }) => {+ ])('keeps teaching visible through completion and reload: %j', async ({ extraTool, legacyCard }) => {const live = lessonEvents(extraTool, legacyCard)const { rerender } = render(conversation(live, true))- const assertTeaching = () => {+ const assertTeaching = async () => {const prose = screen.getByText(teaching)- const card = screen.getByText(question)+ const card = await screen.findByText(question)// jsdom does not lay out the grid collapse. Check the actual fold// wrapper as well as visibility, so 0fr cannot produce a false pass.expect(prose.closest('.grid')).toBeNull()@@ -86,11 +86,11 @@ describe('mastery teaching beside a question', () => {expect(prose.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()expect(screen.getAllByText(teaching)).toHaveLength(1)}- assertTeaching()+ await assertTeaching()const completed = [...live, event('done', { status: 'completed' })]rerender(conversation(completed, false))- assertTeaching()+ await assertTeaching()expect(screen.getByText(preamble.trim()).closest('.opacity-0')).not.toBeNull()if (extraTool) {expect(screen.getByText('Record mastery grade').closest('.opacity-0')).not.toBeNull()@@ -100,7 +100,7 @@ describe('mastery teaching beside a question', () => {const preview = compactTracePreview(completed).eventsexpect(preview.some((item) => item.type === 'content')).toBe(false)rerender(conversation(preview, false))- assertTeaching()+ await assertTeaching()expect(screen.getByText(preamble.trim()).closest('.opacity-0')).not.toBeNull()})diff --git a/web/tests/mastery-question-group.spec.tsx b/web/tests/mastery-question-group.spec.tsxindex 4aebbda85..bbc907edb 100644--- a/web/tests/mastery-question-group.spec.tsx+++ b/web/tests/mastery-question-group.spec.tsx@@ -54,7 +54,7 @@ describe("grouped mastery assessment", () => {isStreaming={false} onCopyAssistantMessage={async () => undefined}onRegenerateMessage={() => undefined} onAnswerMasteryQuestion={() => true} />;const { rerender } = render(conversation(false));- await user.clear(screen.getByRole("textbox"));+ await user.clear(await screen.findByRole("textbox"));await user.type(screen.getByRole("textbox"), "Explicit revised explanation");await user.click(screen.getByRole("button", { name: "Submit" }));expect(screen.getByRole("button", { name: "Submit" })).toBeDisabled();diff --git a/web/tests/mastery-teaching-visibility.spec.tsx b/web/tests/mastery-teaching-visibility.spec.tsxindex da4ae2894..107352a55 100644--- a/web/tests/mastery-teaching-visibility.spec.tsx+++ b/web/tests/mastery-teaching-visibility.spec.tsx@@ -50,7 +50,7 @@ function lessonEvents(reloaded: boolean, bookkeeping = "mastery_note_explained")}describe("Mastery teaching visibility", () => {- it("keeps teaching visible while a quiz is pending and when the turn settles", () => {+ it("keeps teaching visible while a quiz is pending and when the turn settles", async () => {const events = lessonEvents(false);const props = (trace: StreamEvent[], streaming: boolean) => ({msg: { content: lesson + transition, capability: "mastery_path", events: trace },@@ -68,38 +68,38 @@ describe("Mastery teaching visibility", () => {view.rerender(<AssistantMessage {...props(events, false)} />);expect(screen.getByText(lesson)).toBeVisible();expect(screen.getByText(transition)).toBeVisible();- expect(screen.getByText(question.prompt)).toBeVisible();+ expect(await screen.findByText(question.prompt)).toBeVisible();});- it("keeps a teaching-only turn visible after its final bookkeeping tool", () => {+ it("keeps a teaching-only turn visible after its final bookkeeping tool", async () => {const events = lessonEvents(false).slice(0, 3);render(<AssistantMessage msg={{ content: lesson, capability: "mastery_path", events }} />);expect(screen.getByText(lesson)).toBeVisible();});- it.each([false, true])("keeps the lesson visible across bookkeeping (reloaded=%s)", (reloaded) => {+ it.each([false, true])("keeps the lesson visible across bookkeeping (reloaded=%s)", async (reloaded) => {render(<AssistantMessage msg={{ content: lesson + transition, capability: "mastery_path", events: lessonEvents(reloaded) }} />);expect(screen.getByText(lesson)).toBeVisible();expect(screen.getByText(transition)).toBeVisible();- expect(screen.getByText(question.prompt)).toBeVisible();+ expect(await screen.findByText(question.prompt)).toBeVisible();const reasoning = screen.queryByText("Internal assessment planning");if (reasoning) expect(reasoning).not.toBeVisible();});- it("does not hide an existing lesson when later work retrieves more sources", () => {+ it("does not hide an existing lesson when later work retrieves more sources", async () => {render(<AssistantMessage msg={{ content: lesson + transition, capability: "mastery_path", events: lessonEvents(false, "rag") }} />);expect(screen.getByText(lesson)).toBeVisible();expect(screen.getByText(transition)).toBeVisible();- expect(screen.getByText(question.prompt)).toBeVisible();+ expect(await screen.findByText(question.prompt)).toBeVisible();});- it("keeps ordinary chat commentary folded when no Mastery question is posed", () => {+ it("keeps ordinary chat commentary folded when no Mastery question is posed", async () => {const events = lessonEvents(false, "rag").filter((item) => !(item.type === "tool_result" && item.metadata?.tool_metadata));render(<AssistantMessage msg={{ content: lesson + transition, capability: "chat", events }} />);expect(screen.queryByText(lesson)).not.toBeVisible();});- it("does not promote the process before an earlier resolved clarification", () => {+ it("does not promote the process before an earlier resolved clarification", async () => {const planning = "First choose which source to use.";const events = [event("content", planning, { call_id: "planning-round", call_kind: "agent_loop_round" }),@@ -111,10 +111,10 @@ describe("Mastery teaching visibility", () => {render(<AssistantMessage msg={{ content: planning + lesson + transition, capability: "mastery_path", events }} />);expect(screen.queryByText(planning)).not.toBeVisible();expect(screen.getByText(lesson)).toBeVisible();- expect(screen.getByText(question.prompt)).toBeVisible();+ expect(await screen.findByText(question.prompt)).toBeVisible();});- it("does not restore a rejected answer as visible teaching", () => {+ it("does not restore a rejected answer as visible teaching", async () => {const rejected = "A rejected explanation that must not become lesson text.";const events = [event("content", rejected, { call_id: "rejected-round", call_kind: "agent_loop_round" }),@@ -125,6 +125,6 @@ describe("Mastery teaching visibility", () => {const rejectedText = screen.queryByText(rejected);if (rejectedText) expect(rejectedText).not.toBeVisible();expect(screen.getByText(lesson)).toBeVisible();- expect(screen.getByText(question.prompt)).toBeVisible();+ expect(await screen.findByText(question.prompt)).toBeVisible();});});