mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 06:19:43 +08:00
Ship folder-based workspaces and data migration, daily practice, redesigned provider and model settings, and streaming conversation improvements. Synchronize README translations and document the archive/permanent-delete upgrade behavior in assets/releases/ver1-6-9.md. Reduce initial JavaScript by deduplicating English resources and loading animation features after hydration. Keep the existing route size budgets. Update regression fixtures and browser audits for scoped URLs and the new settings and learning interfaces.
75 lines
3.2 KiB
TypeScript
75 lines
3.2 KiB
TypeScript
import { scopedUrl } from "@/lib/workspace-scope";
|
|
import { sessionWorkspaceId } from "@/lib/session-api";
|
|
import { masterySessionRoute, readingSessionRoute, watchingRoute } from "@/lib/learning-routes";
|
|
/**
|
|
* Which surface a conversation belongs to — the one place that decides.
|
|
*
|
|
* A mastery study conversation is an ordinary chat session that happens to
|
|
* carry `mastery_path_id` in its preferences. Two surfaces need to read that:
|
|
* the sidebar, to file the conversation under its topic, and the click
|
|
* handler, to open it on its topic session route instead of `/chat`.
|
|
* If those two ever disagreed, a conversation would render under a topic and
|
|
* then navigate somewhere else — so the rule lives here and neither owns it.
|
|
*
|
|
* Workspace mode and path id are both required. The capability is a per-turn
|
|
* action (Chat, Quiz, Research, ...), so it never decides which product
|
|
* surface owns the conversation.
|
|
*
|
|
* Immersive Reading conversations answer the same question with their own
|
|
* pair of signals, and land on their collection instead. They are here rather
|
|
* than in a second module for the reason above: if two places decided where a
|
|
* conversation lives, the sidebar would file one under a heading and then
|
|
* navigate somewhere else.
|
|
*/
|
|
|
|
import type { SessionSummary } from "@/lib/session-api";
|
|
|
|
export function masteryPathIdOf(session: SessionSummary): string {
|
|
const preferences = session.preferences;
|
|
if (!preferences) return "";
|
|
if (preferences.workspace_mode !== "mastery_path") return "";
|
|
return String(preferences.mastery_path_id || "");
|
|
}
|
|
|
|
/**
|
|
* Which reading collection a conversation belongs to, or "".
|
|
*
|
|
* Both signals again, and for the same reason: `session_kind` says the
|
|
* conversation was held in the reader, `reading_workspace_id` says which
|
|
* collection it was held in. The backend writes both together, on the
|
|
* conversation's first turn and whenever a reading session is attached.
|
|
*/
|
|
export function readingWorkspaceIdOf(session: SessionSummary): string {
|
|
const preferences = session.preferences;
|
|
if (!preferences) return "";
|
|
if (preferences.workspace_mode !== "immersive_reading") return "";
|
|
return String(preferences.reading_workspace_id || "");
|
|
}
|
|
|
|
/** Where clicking this conversation should land. */
|
|
export function sessionRoute(session: SessionSummary): string {
|
|
return scopedUrl(surfaceRoute(session), sessionWorkspaceId(session));
|
|
}
|
|
|
|
function surfaceRoute(session: SessionSummary): string {
|
|
const sessionId = encodeURIComponent(session.session_id);
|
|
const pathId = masteryPathIdOf(session);
|
|
if (pathId) {
|
|
return masterySessionRoute(pathId, session.session_id, sessionWorkspaceId(session));
|
|
}
|
|
// The reader, its outline and the material are the context this was held
|
|
// in; /chat would drop all three and leave the citations pointing at a
|
|
// document that is not open.
|
|
const workspaceId = readingWorkspaceIdOf(session);
|
|
if (workspaceId) {
|
|
return readingSessionRoute(workspaceId, session.session_id, sessionWorkspaceId(session));
|
|
}
|
|
if (
|
|
session.preferences?.workspace_mode === "immersive_watching" ||
|
|
session.preferences?.capability === "immersive_watching"
|
|
) {
|
|
return watchingRoute(session.session_id, sessionWorkspaceId(session));
|
|
}
|
|
return `/chat/${sessionId}`;
|
|
}
|