mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 04:39:31 +08:00
Remove course pages, APIs and the course_study capability. Add anchored note threads and reviewed learning-block generation, queued and withdrawable chat messages, quote attachments, side chats, and the calendar/favorites/navigation updates. Keep preview's existing backend architecture. Wire the new features through its Python application and existing chat engine, retain legacy selected-text requests, persist mid-turn messages in replay, and restore note context when regenerating. Leave stored user data intact. Validate frontend contracts, dependency boundaries, types, 1290 node tests, 840 rendered tests, lint, localization and the production build. Exercise session/notes/API regressions, 53 chat-engine tests and 20 Python/native integration tests with isolated runtime data.
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
function segment(value: string): string {
|
|
return encodeURIComponent(value.trim());
|
|
}
|
|
|
|
/**
|
|
* Decode a dynamic resource route parameter back to its stored identity.
|
|
*
|
|
* Next.js keeps dynamic values URL-encoded in the client router tree, so
|
|
* `useParams()` can return e.g. `%E5%9B%BD...` for a Chinese resource name.
|
|
*/
|
|
export function decodeResourceSegment(value?: string | null): string | null {
|
|
const candidate = value?.trim();
|
|
if (!candidate) return null;
|
|
try {
|
|
return decodeURIComponent(candidate).trim() || null;
|
|
} catch {
|
|
// Leave malformed external URLs usable instead of crashing the page.
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
export function notebookRoute(
|
|
notebookId?: string | null,
|
|
recordId?: string | null,
|
|
): string {
|
|
const pathname = notebookId?.trim()
|
|
? `/notebooks/${segment(notebookId)}`
|
|
: "/notebooks";
|
|
const query = [
|
|
recordId?.trim() ? `record=${segment(recordId)}` : "",
|
|
]
|
|
.filter(Boolean)
|
|
.join("&");
|
|
return query ? `${pathname}?${query}` : pathname;
|
|
}
|
|
|
|
export function knowledgeBaseRoute(name?: string | null): string {
|
|
return name?.trim()
|
|
? `/knowledge-bases/${segment(name)}`
|
|
: "/knowledge-bases";
|
|
}
|
|
|
|
/** A stable link back to an archived favorite, including after a move. */
|
|
export function favoriteRecordRoute(
|
|
collectionId: string,
|
|
recordId: string,
|
|
): string {
|
|
return notebookRoute(collectionId, recordId);
|
|
}
|