mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 15:30:06 +08:00
A course held the right model — the syllabus that gives progress a
denominator, resources as references, conventions apart from the
assistant's own notes — but almost nothing crossed the edges between it
and the surfaces it was supposed to contain.
Getting in. Course Study was offered in the composer's mode menu while
the only way to bind a course was a link on the course page, so choosing
it there produced a conversation identical to an inert one, and the mode
advised pressing a button that did not exist. The composer now carries
the binding next to the mode: shown whenever there is one, and offered
as an unfinished field in Course Study when there is not. `_course_id`
rides every turn, so detaching detaches and the pill can never drift
from what the turn actually saw.
What a conversation inherits. `default_capability` and `default_persona`
were stored, validated and returned by the API while changing nothing:
`_apply_course_defaults` only fills fields a payload *omits*, and this
composer always sent all of them. They are applied client-side now,
along with the course's knowledge bases, where the learner can watch the
mode and material become the course's before they type. The dialog grows
the editor they never had.
Conventions. "Every conversation in this course starts knowing these" was
true only if the model happened to call `course_overview`. They ride in
the per-turn summary now, and — because the promise is not scoped to one
mode — in the system prompt of any course-bound turn.
Coming back. Mastery Path and Immersive Reading now read `?course=`,
scope themselves to it, and attach whatever is built there; the tiles and
hand-offs pass it; the picker offers to start one. A course could only
ever reference what already existed, so filling a new one meant leaving,
building, and remembering to return.
Hand-offs. A target with no ref stored an opening line for an index that
never consumes it, which then surfaced weeks later in an unrelated path.
An unresolvable ref was passed straight through: observed live, a
syllabus unit id ("u2") sent as a mastery path, producing a card pointing
at a page that does not exist. Refs are checked against the subsystem
that owns them — existence, not membership, since a path built outside
this course routes perfectly well.
Also: the sidebar groups conversations by course, so filing them is
finally readable; a course-scoped notebook console no longer shows
another course's notes beside a list saying there are none (the clear
raced an in-flight detail fetch that landed after it); a hand-off the
model also printed as prose is not rendered twice; a provider error is no
longer stored as a conversation's permanent title; `/space/courses` goes,
having been an unreferenced copy of `/courses`; and the Visualize mode
description gets its missing Chinese.
145 lines
5.1 KiB
TypeScript
145 lines
5.1 KiB
TypeScript
"use client";
|
|
|
|
import { memo, useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import {
|
|
BookOpen,
|
|
ClipboardList,
|
|
GraduationCap,
|
|
MessageSquare,
|
|
NotebookPen,
|
|
} from "lucide-react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
courseHandoffHref,
|
|
targetAcceptsPrompt,
|
|
type CourseHandoffPayload,
|
|
type CourseHandoffTarget,
|
|
} from "@/lib/course-handoff";
|
|
import { setPendingPrompt } from "@/lib/pending-prompt";
|
|
|
|
/**
|
|
* The card Course Study uses to hand the learner to the surface that teaches.
|
|
*
|
|
* Course Study reads the course's state and decides what is worth doing next;
|
|
* it does not teach. This is where that decision becomes an action the learner
|
|
* takes — the destination, the reason, and the opening message all visible
|
|
* before anything happens.
|
|
*
|
|
* The prompt is editable on purpose. It is the assistant's proposal for how to
|
|
* start, not an instruction: a learner who wants to arrive asking something
|
|
* slightly different should not have to first arrive, then clear the box, then
|
|
* retype. Taking the card is also the only thing that navigates — nothing here
|
|
* moves the page on its own.
|
|
*
|
|
* Mirrors `deeptutor.capabilities.course_study.tools`; the payload is read by
|
|
* `extractCourseHandoffs` in `lib/course-handoff.ts`.
|
|
*/
|
|
|
|
const TARGET_ICONS: Record<CourseHandoffTarget, typeof BookOpen> = {
|
|
immersive_reading: BookOpen,
|
|
mastery_path: GraduationCap,
|
|
question_bank: ClipboardList,
|
|
notebook: NotebookPen,
|
|
chat: MessageSquare,
|
|
};
|
|
|
|
const CourseHandoff = memo(function CourseHandoff({
|
|
data,
|
|
}: {
|
|
data: CourseHandoffPayload;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const router = useRouter();
|
|
const [draft, setDraft] = useState(data.prompt);
|
|
const Icon = TARGET_ICONS[data.target];
|
|
const acceptsPrompt = targetAcceptsPrompt(data.target, data.ref_id);
|
|
const needsSetup =
|
|
!data.ref_id.trim() &&
|
|
(data.target === "mastery_path" || data.target === "immersive_reading");
|
|
const place: string = {
|
|
immersive_reading: t("Immersive Reading"),
|
|
mastery_path: t("Mastery Path"),
|
|
question_bank: t("Question Bank"),
|
|
notebook: t("Notebooks"),
|
|
chat: t("Chat"),
|
|
}[data.target];
|
|
|
|
const go = () => {
|
|
const opening = draft.trim();
|
|
if (opening && acceptsPrompt) setPendingPrompt(opening, data.target);
|
|
router.push(courseHandoffHref(data));
|
|
};
|
|
|
|
return (
|
|
<div className="mt-3 rounded-2xl border border-[var(--border)] bg-[var(--card)] p-4 shadow-[0_1px_2px_rgba(0,0,0,0.04),0_4px_14px_rgba(0,0,0,0.04)]">
|
|
<div className="flex items-start gap-3">
|
|
<div className="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-[color-mix(in_srgb,var(--foreground)_8%,transparent)] text-[var(--foreground)]/70">
|
|
<Icon size={13} strokeWidth={1.8} />
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<div className="text-[13px] font-medium leading-snug text-[var(--foreground)]">
|
|
{data.reason || t("Worth doing next")}
|
|
</div>
|
|
<div className="mt-0.5 text-[11px] leading-relaxed text-[var(--muted-foreground)]">
|
|
{data.label ? `${place} · ${data.label}` : place}
|
|
{/* No resource named means this course has none of that kind yet.
|
|
Saying so beats letting the learner click through expecting the
|
|
tutor's opening line and finding an empty index instead. */}
|
|
{!data.label && needsSetup ? (
|
|
<span className="text-[var(--muted-foreground)]/75">
|
|
{" · "}
|
|
{t("nothing here yet — you'll set one up")}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
|
|
{data.prompt && acceptsPrompt ? (
|
|
<label className="mt-3 block">
|
|
<span className="text-[10.5px] text-[var(--muted-foreground)]/80">
|
|
{t("Opens with")}
|
|
</span>
|
|
<textarea
|
|
value={draft}
|
|
onChange={(event) => setDraft(event.target.value)}
|
|
rows={2}
|
|
className="mt-1 w-full resize-none rounded-xl border border-[var(--border)] bg-[var(--background)] px-2.5 py-2 text-[12px] leading-relaxed text-[var(--foreground)] outline-none transition-colors focus:border-[var(--ring)]"
|
|
/>
|
|
</label>
|
|
) : null}
|
|
|
|
<button
|
|
type="button"
|
|
onClick={go}
|
|
className="mt-3 inline-flex items-center gap-1.5 rounded-full border border-[var(--border)] bg-[var(--background)] px-3 py-1.5 text-[11.5px] font-medium text-[var(--foreground)] transition hover:bg-[color-mix(in_srgb,var(--foreground)_5%,transparent)]"
|
|
>
|
|
{place}
|
|
<span aria-hidden>→</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
});
|
|
CourseHandoff.displayName = "CourseHandoff";
|
|
|
|
export const CourseHandoffCards = memo(function CourseHandoffCards({
|
|
handoffs,
|
|
}: {
|
|
handoffs: CourseHandoffPayload[];
|
|
}) {
|
|
if (handoffs.length === 0) return null;
|
|
return (
|
|
<>
|
|
{handoffs.map((handoff) => (
|
|
<CourseHandoff
|
|
key={`${handoff.target}:${handoff.ref_id}`}
|
|
data={handoff}
|
|
/>
|
|
))}
|
|
</>
|
|
);
|
|
});
|
|
CourseHandoffCards.displayName = "CourseHandoffCards";
|