mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 07:39:53 +08:00
Immersive Reading, self-configuration, and a two-way IMA library. - Immersive Reading: a new capability that opens a document beside the thread. New reading engine (PDF pages / slides / page-sized sections), five reading tools, a deterministic locate pre-pass that grounds the turn without a second LLM call, /api/v1/reading, and a reader pane with selection, highlights, notes, and export to an annotated PDF or Markdown. - Setup capability: inspect the install, apply a setting, install a parsing engine, or request a credential from a chat turn. New settings spec table; a candidate value is probed before it is committed, and API keys never enter the model's context. - Tencent IMA: pipeline split into transport/envelope/models/sources/ notes/media/inventory, an additive capability with five tools, and connected libraries that can finally be enumerated (bounded listings are reported as a lower bound). - Retrieval: supports_rag_retrieval() replaces is_connected_kb() for the "can I sweep this?" question, so linked / lightrag_server / ima sources stop being silently dropped from every book. - Notebooks: their own console at /notebook, per-notebook locks and atomic writes, copy / move / export routes, damaged files surfaced instead of dropped, and renaming a record no longer clears its knowledge-base link. - Settings persistence: one lock and one atomic replace shared by every writer of interface.json; the PUT endpoints stop writing the defaults-merged view back to disk. Release notes: assets/releases/ver1-5-14.md
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
/**
|
||
* Single place pdf.js is loaded and configured.
|
||
*
|
||
* The library and its worker are ~1.5 MB together, so they are imported
|
||
* dynamically: a user who never opens the reader never downloads them. The
|
||
* promise is memoised, so the many pages of one document share one module
|
||
* instance and one worker.
|
||
*
|
||
* The worker URL is built with `new URL(..., import.meta.url)` rather than a
|
||
* hand-written public path, which lets the bundler fingerprint and serve the
|
||
* worker file itself — a hard-coded `/pdf.worker.mjs` would have to be copied
|
||
* into `public/` by a build step and would break the moment the version bumps.
|
||
*/
|
||
|
||
import type * as PdfjsModule from "pdfjs-dist";
|
||
|
||
export type Pdfjs = typeof PdfjsModule;
|
||
export type PdfDocument = Awaited<
|
||
ReturnType<Pdfjs["getDocument"]>["promise"]
|
||
>;
|
||
export type PdfPageProxy = Awaited<ReturnType<PdfDocument["getPage"]>>;
|
||
|
||
let pending: Promise<Pdfjs> | null = null;
|
||
|
||
export function loadPdfjs(): Promise<Pdfjs> {
|
||
if (pending) return pending;
|
||
pending = (async () => {
|
||
const pdfjs = await import("pdfjs-dist");
|
||
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
|
||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||
"pdfjs-dist/build/pdf.worker.min.mjs",
|
||
import.meta.url,
|
||
).toString();
|
||
}
|
||
return pdfjs;
|
||
})().catch((error) => {
|
||
// Do not cache a failure: a transient chunk-load error must not disable the
|
||
// reader for the rest of the session.
|
||
pending = null;
|
||
throw error;
|
||
});
|
||
return pending;
|
||
}
|
||
|
||
/**
|
||
* Device-pixel scale for crisp canvas rendering, bounded.
|
||
*
|
||
* Uncapped DPR on a 3× phone screen makes a full-page canvas large enough to be
|
||
* dropped by mobile Safari's canvas memory limit, which shows as a blank page
|
||
* rather than an error — hence the cap.
|
||
*/
|
||
export function outputScale(): number {
|
||
if (typeof window === "undefined") return 1;
|
||
return Math.min(2, Math.max(1, window.devicePixelRatio || 1));
|
||
}
|