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

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:
Elijah 2026-11-15 15:48:54 -07:00
parent 5ea61c882c
commit 031f7bec31
45 changed files with 2918 additions and 397 deletions

View file

@ -0,0 +1,94 @@
/**
* Browser previews of Word and PowerPoint uploads, so the original can be read next to the
* extracted text. The result is a self-contained HTML page (pictures inlined as data URIs)
* that the server sends with a sandboxing Content-Security-Policy.
*/
import { zipSync } from 'fflate';
import mammoth from 'mammoth';
import { pptxSlidesForPreview, WEB_IMAGE_MIME } from './pptx.ts';
import { ZipReader, type ZipLimits } from './zip.ts';
const LIMITS: ZipLimits = { maxEntryBytes: 64 * 1024 * 1024, maxTotalBytes: 300 * 1024 * 1024 };
const IMAGE_BUDGET = 40 * 1024 * 1024;
const escapeHtml = (text: string) => text.replace(/[&<>"']/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[ch]!);
const STYLE = `
:root { color-scheme: light dark; --ink: #1b1a17; --ink-2: #57534a; --line: #e4e0d6; --paper: #f7f5ef; --surface: #fffefa; }
@media (prefers-color-scheme: dark) { :root { --ink: #ece9e1; --ink-2: #a8a396; --line: #34322d; --paper: #161512; --surface: #1e1d19; } }
* { box-sizing: border-box; }
body { margin: 0; padding: 20px; background: var(--paper); color: var(--ink); font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }
img { max-width: 100%; height: auto; }
.page { max-width: 820px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px 32px; }
.page h1, .page h2, .page h3 { line-height: 1.25; }
.page table { border-collapse: collapse; width: 100%; }
.page td, .page th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.slide { max-width: 900px; margin: 0 auto 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; }
.slide-no { font: 600 11px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.slide h2 { margin: 8px 0 10px; font-size: 20px; }
.block { white-space: pre-wrap; margin: 0 0 8px; }
.pics { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.pics img { max-height: 420px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.notes { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); color: var(--ink-2); font-size: 13.5px; white-space: pre-wrap; }
.muted { color: var(--ink-2); font-size: 13px; }
`;
function page(title: string, body: string): string {
return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(title)}</title><style>${STYLE}</style></head><body>${body}</body></html>`;
}
function pptxHtml(bytes: Uint8Array, title: string): string {
const slides = pptxSlidesForPreview(bytes, LIMITS, IMAGE_BUDGET);
const body = slides
.map((s, i) => {
const blocks = s.blocks.map((b) => `<p class="block">${escapeHtml(b.replace(/^#{1,6}\s+/, ''))}</p>`).join('');
const pics = s.images.length ? `<div class="pics">${s.images.map((img) => `<img alt="" src="data:${img.mime};base64,${img.data}">`).join('')}</div>` : '';
const skipped = s.skippedImages ? `<p class="muted">${s.skippedImages} picture${s.skippedImages === 1 ? '' : 's'} on this slide can't be shown here.</p>` : '';
const notes = s.notes ? `<div class="notes"><strong>Notes</strong>\n${escapeHtml(s.notes)}</div>` : '';
return `<section class="slide"><div class="slide-no">Slide ${i + 1}</div>${s.title ? `<h2>${escapeHtml(s.title)}</h2>` : ''}${blocks}${pics}${skipped}${notes}</section>`;
})
.join('');
return page(title, body || '<p class="muted">This deck has no slides.</p>');
}
async function docxHtml(bytes: Uint8Array, title: string): Promise<string> {
// Re-pack through the size-limited reader (as extraction does), keeping pictures a browser can show.
const zip = new ZipReader(bytes, LIMITS);
const files: Record<string, Uint8Array> = {};
let budget = IMAGE_BUDGET;
for (const entry of zip.entries) {
const name = entry.name;
if (name.endsWith('/')) continue;
const isXml = /\.(xml|rels)$/i.test(name) && !/^(customXml|docProps\/thumbnail)/i.test(name);
const isImage = /^word\/media\//i.test(name) && WEB_IMAGE_MIME[name.slice(name.lastIndexOf('.') + 1).toLowerCase()];
if (!isXml && !isImage) continue;
const data = zip.read(name);
if (!data) continue;
if (isImage) {
if (data.byteLength > budget) continue;
budget -= data.byteLength;
}
files[name] = data;
}
const packed = zipSync(files, { level: 0 });
const converted = await mammoth.convertToHtml(
{ buffer: Buffer.from(packed.buffer, packed.byteOffset, packed.byteLength) },
{
ignoreEmptyParagraphs: true,
convertImage: mammoth.images.imgElement(async (image) => {
if (!Object.values(WEB_IMAGE_MIME).includes(image.contentType)) return { src: '' };
return { src: `data:${image.contentType};base64,${await image.read('base64')}` };
}),
},
);
// Links stay as text: the preview never navigates anywhere.
const html = converted.value.replace(/<a\b[^>]*>/gi, '<a>').replace(/<img src=""[^>]*>/gi, '');
return page(title, `<div class="page">${html || '<p class="muted">This document has no content to show.</p>'}</div>`);
}
export async function officePreviewHtml(kind: 'docx' | 'pptx', bytes: Uint8Array, title: string): Promise<string> {
return kind === 'pptx' ? pptxHtml(bytes, title) : docxHtml(bytes, title);
}
/** Served with the preview: no scripts, no network, only inline styles and data-URI pictures. */
export const PREVIEW_CSP = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; frame-ancestors 'self'; sandbox";