mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 13:09:57 +08:00
Self-hostable PageIndex, a fileable question bank, and third-party plugins. - PageIndex: adds PageIndex OSS as its own knowledge-base type, bound to the base's local library and driven by the configured LLM rather than a PageIndex API key. Retrieval moves off the built-in MCP server (removed) onto a workflow-owned reading loop that walks the document tree. - Question bank: addEntryToCategory shipped in v1.3.6 and was never called from the frontend, so categories could be created but never filled. The quiz card now uses the shared CategoryMenu, the page is rebuilt around search / batch selection / an unfiled inbox, and a new question_bank tool lets the tutor file questions instead of misrouting them to write_note. - Plugins: deeptutor.plugins was imported behind a try/except but the module never existed — implemented, plus a deeptutor.loop_capabilities group so third-party packages can register chat-loop capabilities. Builtins win on name collisions; broken entry points are skipped. - Parsing: remote Apache Tika engine (TIKA_SERVER_URL), with no local package and no model download. - LightRAG: the three indexing knobs from #877 get inputs under their own Indexing divider; unsupported keywords are dropped with a warning. - Knowledge bases: uploads take a destination folder, same-named documents from different subtrees stop dropping one another, and linked folders keep their source-relative structure — closing #866. - Book: a learning-capture inbox with an explicit status lifecycle, and drift warnings scoped to the KB documents that actually changed. - Whisper: /whisper moves out of the primary nav into Learning Space → More Projects, credited to its contributor; the room needs its own capability package. The reusable half is CAPABILITY_COMPLETE forwarding of a capability-declared body and its declared extras. - README: a Collaborate badge beside the Docs badge, in all twelve languages. - Lint: nosec B608 on four false-positive question-bank queries (literal fragments only, every value bound), and three mypy fixes. Release notes: assets/releases/ver1-5-15.md
122 lines
4.3 KiB
TypeScript
122 lines
4.3 KiB
TypeScript
/**
|
|
* Bridge from a reading tool's result to the reader pane.
|
|
*
|
|
* The reading tools signal UI intent on their `ToolResult.metadata` under
|
|
* `reader_action` — `goto` to move the view, `annotate` to surface a mark the
|
|
* assistant just made. The chat forwards that as a DOM event and the reader pane
|
|
* listens; neither side imports the other, so the chat needs no knowledge of the
|
|
* reader and vice versa (the same seam the visualize-prompt bridge uses).
|
|
*
|
|
* The extraction is defensive because the metadata crosses the wire: anything
|
|
* unrecognised is dropped rather than dispatched.
|
|
*/
|
|
|
|
/** Event name the reader pane listens on. */
|
|
export const READER_ACTION_EVENT = "dt:reader-action";
|
|
/**
|
|
* Fired once a turn finishes, saying whether it ever moved the reader.
|
|
*
|
|
* The model is asked to call `reader_goto` for each passage it discusses, and
|
|
* mostly does — but not always, and a turn that cites `[p.5]` while the reader
|
|
* sits on page 1 looks broken regardless of whose fault it is. The pane uses
|
|
* this to fall back to the first citation in the answer, so the view follows the
|
|
* *answer* rather than the model's diligence.
|
|
*/
|
|
export const READER_TURN_END_EVENT = "dt:reader-turn-end";
|
|
|
|
/** Turns that have already moved the reader, so the fallback stays quiet. */
|
|
const movedTurns = new Set<string>();
|
|
/** Bound so a long session cannot accumulate ids forever. */
|
|
const MAX_TRACKED_TURNS = 64;
|
|
|
|
function rememberMoved(turnId: string): void {
|
|
if (!turnId) return;
|
|
if (movedTurns.size >= MAX_TRACKED_TURNS) movedTurns.clear();
|
|
movedTurns.add(turnId);
|
|
}
|
|
|
|
export interface ReaderActionPayload {
|
|
material_id?: string;
|
|
reader_action: "goto" | "annotate";
|
|
locator?: number;
|
|
quote?: string;
|
|
annotation?: Record<string, unknown>;
|
|
}
|
|
|
|
/**
|
|
* Extract a reader action from a stream event's metadata, or null.
|
|
*
|
|
* A tool's own `ToolResult.metadata` does not arrive at the top level of the
|
|
* event: the dispatcher nests it under `tool_metadata`, alongside its own trace
|
|
* keys (see `core/agentic/tool_dispatch.py`). Reading the top level only —
|
|
* which looks right and type-checks fine — silently finds nothing, so the
|
|
* reader never moves. The top level is still checked as a fallback in case a
|
|
* caller emits the event directly.
|
|
*/
|
|
export function readerActionFrom(event: {
|
|
type?: string;
|
|
metadata?: unknown;
|
|
}): ReaderActionPayload | null {
|
|
if (event?.type !== "tool_result") return null;
|
|
const metadata = event.metadata;
|
|
if (!metadata || typeof metadata !== "object") return null;
|
|
|
|
const outer = metadata as Record<string, unknown>;
|
|
const nested = outer.tool_metadata;
|
|
const raw = (nested && typeof nested === "object" ? nested : outer) as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
const action = raw.reader_action;
|
|
if (action !== "goto" && action !== "annotate") return null;
|
|
|
|
const payload: ReaderActionPayload = { reader_action: action };
|
|
if (typeof raw.material_id === "string" && raw.material_id) {
|
|
payload.material_id = raw.material_id;
|
|
}
|
|
const locator = Number(raw.locator);
|
|
if (Number.isInteger(locator) && locator >= 1) payload.locator = locator;
|
|
if (typeof raw.quote === "string" && raw.quote) payload.quote = raw.quote;
|
|
if (raw.annotation && typeof raw.annotation === "object") {
|
|
payload.annotation = raw.annotation as Record<string, unknown>;
|
|
}
|
|
return payload;
|
|
}
|
|
|
|
/**
|
|
* Dispatch whatever *event* means for the reader.
|
|
*
|
|
* Called for every stream event; almost all of them are neither a reader action
|
|
* nor a turn ending, and cost one string comparison.
|
|
*/
|
|
export function forwardReaderAction(event: {
|
|
type?: string;
|
|
metadata?: unknown;
|
|
turn_id?: string;
|
|
}): void {
|
|
if (typeof window === "undefined") return;
|
|
const turnId = String(event?.turn_id || "");
|
|
|
|
const payload = readerActionFrom(event);
|
|
if (payload) {
|
|
if (payload.reader_action === "goto") rememberMoved(turnId);
|
|
window.dispatchEvent(
|
|
new CustomEvent(READER_ACTION_EVENT, { detail: payload }),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (event?.type === "done") {
|
|
const moved = turnId ? movedTurns.has(turnId) : false;
|
|
movedTurns.delete(turnId);
|
|
window.dispatchEvent(
|
|
new CustomEvent(READER_TURN_END_EVENT, { detail: { moved } }),
|
|
);
|
|
}
|
|
}
|
|
|
|
/** Test seam: forget which turns have moved the reader. */
|
|
export function resetReaderActionTracking(): void {
|
|
movedTurns.clear();
|
|
}
|