Files
DeepTutor/web/components/sidebar/BookRecent.tsx
Bingxi Zhao (Frank) 96d6df9eb1 release: v1.5.13
Book is the bulk of this one. Compilation outlives the request that
started it, so a bus owned by that request dropped every background event
and "watch your book being written" degraded into a frozen page; the
stream is now owned per book by the process and survives a refresh or a
reconnect. Reading progress is finally recorded — `visited_page_ids` and
`bookmarked_page_ids` had been declared but never written for the life of
the feature — and rolls up into a completion score and weak chapters. A
book can also leave the app now, as one self-contained Markdown document,
with non-ASCII titles surviving the download.

Two scheduling defects that were invisible in production are fixed: the
same page compiled twice concurrently (billed twice, one result
discarded), and a book grinding on through a provider outage until every
chapter was half-generated. The source sweep is bounded and allocated
round-robin rather than spent on the first few knowledge bases, and
retrieval now tells indexed bases from connected pointers, so an Obsidian
vault or a remote IMA library no longer contributes zero while looking
like a source with nothing relevant. Confirming a spine shows a live
per-chapter estimate derived from the Section Architect's own templates.

Also here: three home starter suggestions built from memory recall,
mastery-path handoff moved into one module that changes lease, session
preference, and live turn together, and account-level Tencent IMA
credentials with the per-KB pair still winning.

Notes: assets/releases/ver1-5-13.md

This commit also carries the README prose sync, the eleven translated
READMEs, the release-notes archive sweep, and the version bump. Two gate
fixes ride along: the `Stamped` protocol is declared read-only so the
frozen `EntityStamp` satisfies it, and six GraphRAG adapter tests that
reached a deep `graphrag` import without guarding it now skip like their
four neighbours instead of failing where the extra is not installed.
2026-08-17 11:22:26 +08:00

77 lines
2.4 KiB
TypeScript

"use client";
import Link from "next/link";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { bookApi } from "@/lib/book-api";
import type { Book } from "@/lib/book-types";
import { formatRelativeTime } from "@/lib/relative-time";
const STATUS_DOT: Record<string, string> = {
ready: "bg-emerald-400",
partial: "bg-amber-400",
generating: "bg-sky-400",
planning: "bg-sky-400",
pending: "bg-[var(--muted-foreground)]/30",
draft: "bg-[var(--muted-foreground)]/30",
spine_ready: "bg-violet-400",
error: "bg-rose-400",
};
interface BookRecentProps {
collapsed?: boolean;
limit?: number;
}
export function BookRecent({ collapsed = false, limit = 4 }: BookRecentProps) {
const { i18n } = useTranslation();
const [books, setBooks] = useState<Book[]>([]);
useEffect(() => {
let cancelled = false;
(async () => {
try {
const { books: items } = await bookApi.list();
// `list_books` already returns newest-first (engine sorts by
// updated_at desc), so this is presentation only.
if (!cancelled) setBooks(items.slice(0, limit));
} catch {
/* the sidebar is decoration; a failed fetch just shows nothing */
}
})();
return () => {
cancelled = true;
};
}, [limit]);
if (books.length === 0) return null;
if (collapsed) return null;
return (
<div className="ml-5 border-l border-[var(--border)]/30 py-1">
{books.map((book) => {
const dot =
STATUS_DOT[book.status] || "bg-[var(--muted-foreground)]/30";
return (
<Link
key={book.id}
href={`/book?book=${encodeURIComponent(book.id)}`}
className="group flex items-center gap-2 rounded-r-lg py-1 pl-3 pr-2 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--background)]/40 hover:text-[var(--foreground)]"
>
<span
className={`block h-1.5 w-1.5 shrink-0 rounded-full ${dot}`}
/>
<span className="min-w-0 flex-1 truncate text-[13px]">
{book.title || "Untitled book"}
</span>
<span className="shrink-0 text-[10px] tabular-nums text-[var(--muted-foreground)]/40">
{formatRelativeTime(Number(book.updated_at) || 0, i18n.language)}
</span>
</Link>
);
})}
</div>
);
}