Second revision: MCP servers, shared-link AI, flashcard modes, document previews
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 30s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 30s
Generation - Every quiz is NCLEX style; "Practice exam" writes 50 questions. - Calculation questions only when the material involves calculations (max 5 per exam). - Broad topics: the class's topics are listed in the prompt, a quick grouping call maps narrow labels onto broad ones, and leftover variants are merged. - Exact select-all count per batch; option order shuffled. - Python check: at most 3 runs, fixed problems count as passed, cosmetic remarks ignored. Assistant - Text, tool steps and cards appear in the order they happen, with paragraph breaks between steps. - Optional thinking box: fixed height, follows the newest text, can be scrolled back. - "+" opens a material picker listing recent items; items can be dragged in from class pages; shorter placeholder. MCP servers - Streamable HTTP client; encrypted headers. - Per-server instructions and switches for chat, Explain, generation and the quiz check. - Settings UI. Share links - Optional "Explain this" and "Ask about this material" per link, off by default. - Items are loaded on the server and checked against the share; no tools; rate-limited. - Migration 4 stores the switches. Study and documents - Standard flashcard mode (optionally repeat missed cards until known) next to spaced repetition. - Streak visuals restyled in the app palette. - Side by side / Original document views, with sandboxed previews of Word and PowerPoint files. Other - Built-in embedding model baked into the image; sharp stubbed if it cannot load; real load error shown in Settings. - Python runner blocks network and process modules in JavaScript too. - "View questions and answers" removed from the quiz start screen. - Docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5ea61c882c
commit
031f7bec31
45 changed files with 2918 additions and 397 deletions
|
|
@ -9,6 +9,9 @@
|
|||
*
|
||||
* The library is imported lazily: the app starts (and tests run) without loading ONNX Runtime
|
||||
* until something actually needs an embedding.
|
||||
*
|
||||
* The Docker image ships the model in /app/models (LOCAL_MODELS_DIR), so nothing is downloaded
|
||||
* at runtime there. Elsewhere it is downloaded once into DATA_DIR/models.
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
|
@ -37,9 +40,9 @@ export function localModelDir(dataDir: string): string {
|
|||
return path.join(dataDir, 'models');
|
||||
}
|
||||
|
||||
/** True when the model files are already on disk (no download needed). */
|
||||
export function localModelDownloaded(dataDir: string): boolean {
|
||||
const dir = path.join(localModelDir(dataDir), ...LOCAL_EMBEDDING_MODEL.split('/'));
|
||||
function hasModel(root: string | undefined): boolean {
|
||||
if (!root) return false;
|
||||
const dir = path.join(root, ...LOCAL_EMBEDDING_MODEL.split('/'));
|
||||
try {
|
||||
return fs.existsSync(path.join(dir, 'onnx', 'model_quantized.onnx')) && fs.existsSync(path.join(dir, 'tokenizer.json'));
|
||||
} catch {
|
||||
|
|
@ -47,6 +50,39 @@ export function localModelDownloaded(dataDir: string): boolean {
|
|||
}
|
||||
}
|
||||
|
||||
/** A copy of the model shipped with the installation (the Docker image), if any. */
|
||||
function bundledModelDir(): string | undefined {
|
||||
const dir = process.env.LOCAL_MODELS_DIR?.trim();
|
||||
return dir && hasModel(dir) ? dir : undefined;
|
||||
}
|
||||
|
||||
/** True when the model files are already on disk (no download needed). */
|
||||
export function localModelDownloaded(dataDir: string): boolean {
|
||||
return Boolean(bundledModelDir()) || hasModel(localModelDir(dataDir));
|
||||
}
|
||||
|
||||
/**
|
||||
* transformers.js imports `sharp` (image processing) when it loads, although text embeddings
|
||||
* never use it. sharp's prebuilt binary needs a fairly recent x86-64 CPU; on hosts where it
|
||||
* cannot load, the whole library failed. Route `sharp` to an empty stand-in in that case.
|
||||
*/
|
||||
async function stubSharpIfBroken(): Promise<void> {
|
||||
try {
|
||||
await import('sharp');
|
||||
return;
|
||||
} catch {
|
||||
/* fall through */
|
||||
}
|
||||
const { registerHooks } = (await import('node:module')) as unknown as { registerHooks?: (hooks: unknown) => void };
|
||||
const stub = 'data:text/javascript,' + encodeURIComponent('export default function sharp(){throw new Error("Image processing is not available on this server.")}');
|
||||
registerHooks?.({
|
||||
resolve(specifier: string, context: unknown, next: (s: string, c: unknown) => unknown) {
|
||||
if (specifier === 'sharp') return { url: stub, shortCircuit: true, format: 'module' };
|
||||
return next(specifier, context);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function localModelStatus(dataDir: string) {
|
||||
return { model: LOCAL_EMBEDDING_MODEL, label: LOCAL_EMBEDDING_LABEL, dimensions: LOCAL_EMBEDDING_DIMS, downloaded: localModelDownloaded(dataDir), status: state.status, error: state.error };
|
||||
}
|
||||
|
|
@ -58,17 +94,20 @@ async function load(dataDir: string): Promise<Extractor> {
|
|||
state.status = 'loading';
|
||||
state.error = '';
|
||||
state.extractor = (async () => {
|
||||
fs.mkdirSync(cacheDir, { recursive: true });
|
||||
const bundled = bundledModelDir();
|
||||
if (!bundled) fs.mkdirSync(cacheDir, { recursive: true });
|
||||
let lib: typeof import('@huggingface/transformers');
|
||||
try {
|
||||
await stubSharpIfBroken();
|
||||
lib = await import('@huggingface/transformers');
|
||||
} catch (err) {
|
||||
throw new AIError('unsupported', 'The built-in embedding model is not available in this installation.', { cause: err });
|
||||
throw new AIError('unsupported', `The built-in embedding model could not start on this server: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
||||
}
|
||||
lib.env.cacheDir = cacheDir;
|
||||
lib.env.allowRemoteModels = true;
|
||||
lib.env.allowLocalModels = true;
|
||||
lib.env.localModelPath = cacheDir;
|
||||
lib.env.localModelPath = bundled ?? cacheDir;
|
||||
// With a bundled copy there is nothing to download.
|
||||
lib.env.allowRemoteModels = !bundled;
|
||||
const extractor = await lib.pipeline('feature-extraction', LOCAL_EMBEDDING_MODEL, { dtype: 'q8' });
|
||||
return extractor as unknown as Extractor;
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue