Study/server/ai/genui.ts
Elijah 25bc03ea75
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s
Fourth revision: OpenRouter, live tool stages, Explain layout, share sections
- Interactive blocks are encouraged by default; Explain gets a reduced library
  and never writes practice questions.
- Assistant tool steps breathe while running, show live stages from generation
  and the Python check, and read in the past tense when done.
- The assistant asks before searching the web when class materials do not
  cover a question; clarifying questions list every class's exams and never
  ask about format (always NCLEX).
- Explain opens beside the question from 900px wide, moving the question left
  while open and back on the next one.
- Generate dialog drops the practice set/exam switch (presets cover it) and the
  Generate buttons lose their icon.
- Python check notes are green when every check passed, applied fixes neutral.
- Share pages group by exam, then Quizzes, Flashcards, Notes, Class Materials,
  hiding empty groups; the class page uses the same order. "Documents" is now
  "Class Materials".
- OpenRouter provider replaces the Ollama type; migration 6 turns Ollama
  connections into OpenAI-compatible ones at /v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:54:39 -07:00

33 lines
1.7 KiB
TypeScript

/** Prompt instructions for interactive reply blocks, generated once per mode from the shared catalog. */
import { createLibrary, defineComponent } from '@openuidev/lang-core';
import { GENUI_COMPONENTS, GENUI_EXAMPLES, GENUI_EXPLAIN_RULES, GENUI_GROUPS, GENUI_PREAMBLE, GENUI_ROOT, GENUI_RULES } from '../../shared/genui.ts';
/** Components that quiz the student; Explain leaves them out. */
const PRACTICE = new Set(['Question', 'Flashcards', 'FlashCard']);
const cached = new Map<string, string>();
/**
* `chat`: the assistant and share-link chats. `explain`: Explain with AI, which gives information
* only (no practice questions or flashcards).
*/
export function genUiPrompt(mode: 'chat' | 'explain' = 'chat'): string {
let prompt = cached.get(mode);
if (prompt === undefined) {
const explain = mode === 'explain';
const library = createLibrary({
root: GENUI_ROOT,
components: GENUI_COMPONENTS.filter((c) => !explain || !PRACTICE.has(c.name)).map((c) => defineComponent({ ...c, component: null as never })),
componentGroups: GENUI_GROUPS.map((g) => (explain ? { ...g, components: g.components.filter((n) => !PRACTICE.has(n)) } : g)).filter((g) => g.components.length > 0),
});
const preamble = explain ? GENUI_PREAMBLE.replace(/\n- Teaching a concept the student can practise:[^\n]*/, '') : GENUI_PREAMBLE;
prompt = `\n\n${library.prompt({
preamble,
additionalRules: explain ? [...GENUI_RULES, ...GENUI_EXPLAIN_RULES] : GENUI_RULES,
examples: explain ? GENUI_EXAMPLES.filter((e) => !/Question\(|Flashcards\(/.test(e)) : GENUI_EXAMPLES,
bindings: true,
})}`;
cached.set(mode, prompt);
}
return prompt;
}