Fifth revision: share-link AI safety, sturdier generation, cleaner UI
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 1m0s

- Malformed model JSON is sent back for repair, then retried; a failed job
  starts over once before it fails. Visitors can dismiss failed sets.
- Generated sets get a short distinct name and description; flashcards are
  atomic and have no hints; standard study shows known/learning counts.
- Share links: "In progress" list, finished sets join the normal lists with a
  "New" tag, plain progress steps, newest exam first.
- Share-link AI expires after a week, can be limited to the US or Arizona
  (DB-IP Lite or Cloudflare headers) and is locked by abuse protection
  (migration 8).
- The assistant never answers from general knowledge; MCP and web search
  tools load without a manual test.
- Plain-text copy, no question count in exam mode, filler text removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-16 09:17:50 -07:00
parent d8df5edf30
commit 85d5c9186d
46 changed files with 1242 additions and 283 deletions

View file

@ -34,6 +34,7 @@ import {
testMcpServer,
WEB_SEARCH_ID,
webSearchPatchSchema,
warmMcpServers,
} from '../ai/mcp.ts';
import type { ToolActivity } from '../ai/activity.ts';
import { genUiPrompt } from '../ai/genui.ts';
@ -160,8 +161,17 @@ export function aiRoutes(app: AppContext): Hono {
// MCP servers the assistant can call as tools.
r.get('/ai/mcp', (c) => c.json({ servers: listMcpServers(app) }));
r.post('/ai/mcp', async (c) => c.json({ server: saveMcpServer(app, null, await readBody(c, mcpServerInputSchema)) }, 201));
r.patch('/ai/mcp/:id', async (c) => c.json({ server: saveMcpServer(app, idParam(c), await readBody(c, mcpServerPatchSchema)) }));
// Saving (or signing in) connects in the background, so the tools are ready without a manual test.
r.post('/ai/mcp', async (c) => {
const server = saveMcpServer(app, null, await readBody(c, mcpServerInputSchema));
warmMcpServers(app);
return c.json({ server }, 201);
});
r.patch('/ai/mcp/:id', async (c) => {
const server = saveMcpServer(app, idParam(c), await readBody(c, mcpServerPatchSchema));
warmMcpServers(app);
return c.json({ server });
});
r.delete('/ai/mcp/:id', (c) => {
deleteMcpServer(app, idParam(c));
return c.json({ ok: true });
@ -188,6 +198,7 @@ export function aiRoutes(app: AppContext): Hono {
if (c.req.query('error')) return back('/settings/ai', 'error', c.req.query('error_description') || 'The sign-in was cancelled.');
try {
const done = await finishMcpOAuth(app, state, code);
warmMcpServers(app);
return back(done.returnTo, 'ok', `Signed in to ${done.name}.`);
} catch (err) {
app.log('warn', 'MCP sign-in failed', err instanceof Error ? err.message : err);
@ -198,7 +209,11 @@ export function aiRoutes(app: AppContext): Hono {
// The built-in web search.
r.get('/ai/web-search', (c) => c.json({ webSearch: getWebSearch(app) }));
r.patch('/ai/web-search', async (c) => c.json({ webSearch: saveWebSearch(app, await readBody(c, webSearchPatchSchema)) }));
r.patch('/ai/web-search', async (c) => {
const webSearch = saveWebSearch(app, await readBody(c, webSearchPatchSchema));
warmMcpServers(app);
return c.json({ webSearch });
});
r.post('/ai/web-search/test', async (c) => c.json({ result: await testMcpServer(app, WEB_SEARCH_ID), webSearch: getWebSearch(app) }));
/** Tool sources the chat may use, for the per-conversation switches. */