All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 29s
- 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>
201 lines
13 KiB
TypeScript
201 lines
13 KiB
TypeScript
/**
|
|
* The generative UI catalog: components the AI may place inside a reply, written in OpenUI Lang
|
|
* (https://www.openui.com, MIT). The server turns this catalog into prompt instructions; the web
|
|
* app attaches a React renderer to each entry. Only names listed here can ever be drawn, so model
|
|
* output cannot inject markup or styles.
|
|
*
|
|
* Positional arguments follow the key order of each `props` object, so keys are never reordered.
|
|
*/
|
|
import { action, markReactive, tagSchemaId } from '@openuidev/lang-core';
|
|
import { z } from 'zod';
|
|
|
|
const reactive = <T extends z.ZodType>(schema: T): T => {
|
|
markReactive(schema);
|
|
return schema;
|
|
};
|
|
|
|
/** Any component, for container children. */
|
|
const Component = z.any();
|
|
tagSchemaId(Component, 'Component');
|
|
|
|
const Tone = z.enum(['neutral', 'accent', 'good', 'warn', 'bad']);
|
|
tagSchemaId(Tone, 'Tone');
|
|
|
|
/* ------------------------------ layout ------------------------------ */
|
|
|
|
const StackProps = z.object({
|
|
children: z.array(Component),
|
|
direction: z.enum(['column', 'row']).optional(),
|
|
gap: z.enum(['s', 'm', 'l']).optional(),
|
|
});
|
|
const CardProps = z.object({ children: z.array(Component), title: z.string().optional(), subtitle: z.string().optional(), tone: Tone.optional() });
|
|
const GridProps = z.object({ children: z.array(Component), columns: z.number().optional() });
|
|
const TabProps = z.object({ label: z.string(), children: z.array(Component) });
|
|
const TabsProps = z.object({ tabs: z.array(TabProps) });
|
|
const AccordionItemProps = z.object({ title: z.string(), children: z.array(Component) });
|
|
const AccordionProps = z.object({ items: z.array(AccordionItemProps) });
|
|
|
|
/* ------------------------------ content ------------------------------ */
|
|
|
|
const HeadingProps = z.object({ text: z.string(), size: z.enum(['s', 'm', 'l']).optional() });
|
|
const TextProps = z.object({ text: z.string(), tone: z.enum(['default', 'muted', 'small']).optional() });
|
|
const CalloutProps = z.object({ text: z.string(), tone: z.enum(['info', 'tip', 'warning', 'danger']).optional(), title: z.string().optional() });
|
|
const BadgeProps = z.object({ label: z.string(), tone: Tone.optional() });
|
|
const StatProps = z.object({ label: z.string(), value: z.union([z.string(), z.number()]), detail: z.string().optional(), tone: Tone.optional() });
|
|
const ProgressProps = z.object({ label: z.string(), value: z.number(), max: z.number().optional(), tone: Tone.optional() });
|
|
const TableProps = z.object({ columns: z.array(z.string()), rows: z.array(z.array(z.union([z.string(), z.number(), z.null()]))), caption: z.string().optional() });
|
|
const ListProps = z.object({ items: z.array(z.string()), ordered: z.boolean().optional() });
|
|
const StepProps = z.object({ title: z.string(), detail: z.string().optional() });
|
|
const StepsProps = z.object({ steps: z.array(StepProps) });
|
|
const DividerProps = z.object({});
|
|
|
|
/* ------------------------------ charts ------------------------------ */
|
|
|
|
const SeriesProps = z.object({ name: z.string(), values: z.array(z.number().nullable()) });
|
|
const SliceProps = z.object({ label: z.string(), value: z.number() });
|
|
const BarChartProps = z.object({
|
|
labels: z.array(z.string()),
|
|
series: z.array(SeriesProps),
|
|
title: z.string().optional(),
|
|
unit: z.string().optional(),
|
|
stacked: z.boolean().optional(),
|
|
horizontal: z.boolean().optional(),
|
|
});
|
|
const LineChartProps = z.object({ labels: z.array(z.string()), series: z.array(SeriesProps), title: z.string().optional(), unit: z.string().optional(), area: z.boolean().optional() });
|
|
const PieChartProps = z.object({ slices: z.array(SliceProps), title: z.string().optional(), unit: z.string().optional(), donut: z.boolean().optional() });
|
|
|
|
/* ------------------------------ interactive ------------------------------ */
|
|
|
|
const SliderProps = z.object({
|
|
name: z.string(),
|
|
label: z.string(),
|
|
min: z.number(),
|
|
max: z.number(),
|
|
step: z.number().optional(),
|
|
value: reactive(z.number().optional()),
|
|
unit: z.string().optional(),
|
|
});
|
|
const NumberInputProps = z.object({ name: z.string(), label: z.string(), value: reactive(z.number().optional()), unit: z.string().optional(), step: z.number().optional() });
|
|
const OptionProps = z.object({ value: z.string(), label: z.string() });
|
|
const SelectProps = z.object({ name: z.string(), label: z.string(), options: z.array(OptionProps), value: reactive(z.string().optional()) });
|
|
const ToggleProps = z.object({ name: z.string(), label: z.string(), value: reactive(z.boolean().optional()) });
|
|
const ButtonProps = z.object({ label: z.string(), action: action().optional(), variant: z.enum(['primary', 'secondary', 'ghost']).optional() });
|
|
const LinkProps = z.object({ label: z.string(), url: z.string() });
|
|
const FollowUpsProps = z.object({ prompts: z.array(z.string()) });
|
|
const QuestionProps = z.object({
|
|
stem: z.string(),
|
|
options: z.array(z.string()),
|
|
correct: z.array(z.number()),
|
|
rationale: z.string().optional(),
|
|
multi: z.boolean().optional(),
|
|
});
|
|
const FlashCardProps = z.object({ front: z.string(), back: z.string() });
|
|
const FlashcardsProps = z.object({ cards: z.array(FlashCardProps) });
|
|
|
|
export interface GenUiComponentSpec {
|
|
name: string;
|
|
description: string;
|
|
props: z.ZodObject<z.ZodRawShape>;
|
|
}
|
|
|
|
export const GENUI_COMPONENTS: GenUiComponentSpec[] = [
|
|
{ name: 'Stack', description: 'Root container. Lays children out in a column (default) or a row.', props: StackProps },
|
|
{ name: 'Card', description: 'A bordered panel grouping related content, with an optional title.', props: CardProps },
|
|
{ name: 'Grid', description: 'Children in equal columns (2-4); collapses to one column on phones.', props: GridProps },
|
|
{ name: 'Tabs', description: 'Tabbed sections; only one tab is visible at a time.', props: TabsProps },
|
|
{ name: 'Tab', description: 'One tab of Tabs.', props: TabProps },
|
|
{ name: 'Accordion', description: 'Collapsible sections, all closed at first.', props: AccordionProps },
|
|
{ name: 'AccordionItem', description: 'One section of an Accordion.', props: AccordionItemProps },
|
|
{ name: 'Heading', description: 'A short heading.', props: HeadingProps },
|
|
{ name: 'Text', description: 'A paragraph. Supports inline Markdown (**bold**, *italic*, lists).', props: TextProps },
|
|
{ name: 'Callout', description: 'Highlighted note: info, tip, warning (cautions) or danger (safety-critical, e.g. a contraindication).', props: CalloutProps },
|
|
{ name: 'Badge', description: 'A small coloured label.', props: BadgeProps },
|
|
{ name: 'Stat', description: 'A key number with a label, e.g. a score or a calculated dose.', props: StatProps },
|
|
{ name: 'Progress', description: 'A labelled progress bar (value out of max, default 100).', props: ProgressProps },
|
|
{ name: 'Table', description: 'A table with a header row. Good for comparisons (drug A vs B, normal vs abnormal values).', props: TableProps },
|
|
{ name: 'List', description: 'A bulleted or numbered list of short items.', props: ListProps },
|
|
{ name: 'Steps', description: 'A numbered sequence: procedures, pathophysiology chains, priorities.', props: StepsProps },
|
|
{ name: 'Step', description: 'One step of Steps.', props: StepProps },
|
|
{ name: 'Divider', description: 'A thin separator line.', props: DividerProps },
|
|
{ name: 'BarChart', description: 'Bar chart: one bar per label for each series. Use for comparing amounts or scores.', props: BarChartProps },
|
|
{ name: 'LineChart', description: 'Line chart over ordered labels (dates, attempts, hours). Use for trends.', props: LineChartProps },
|
|
{ name: 'PieChart', description: 'Parts of a whole. Use for 2-6 slices only.', props: PieChartProps },
|
|
{ name: 'Series', description: 'A named list of values, one per chart label.', props: SeriesProps },
|
|
{ name: 'Slice', description: 'One slice of a PieChart.', props: SliceProps },
|
|
{ name: 'Slider', description: 'A slider bound to a $variable. For calculators and what-if explorations.', props: SliderProps },
|
|
{ name: 'NumberInput', description: 'A number field bound to a $variable.', props: NumberInputProps },
|
|
{ name: 'Select', description: 'A dropdown bound to a $variable.', props: SelectProps },
|
|
{ name: 'Option', description: 'One choice of a Select.', props: OptionProps },
|
|
{ name: 'Toggle', description: 'An on/off switch bound to a $variable.', props: ToggleProps },
|
|
{ name: 'Button', description: 'A button that runs an action, usually @ToAssistant("message") to ask a follow-up.', props: ButtonProps },
|
|
{ name: 'Link', description: 'A link that opens a web page in a new tab.', props: LinkProps },
|
|
{ name: 'FollowUps', description: 'Up to 4 suggested next questions shown as chips; clicking one sends it as the user\'s message.', props: FollowUpsProps },
|
|
{
|
|
name: 'Question',
|
|
description: 'A practice question the user answers inline and checks themselves. correct lists the 0-based positions of the correct options. multi=true for select-all-that-apply.',
|
|
props: QuestionProps,
|
|
},
|
|
{ name: 'Flashcards', description: 'A small set of flip cards (2-12) to review inline.', props: FlashcardsProps },
|
|
{ name: 'FlashCard', description: 'One card of Flashcards.', props: FlashCardProps },
|
|
];
|
|
|
|
export const GENUI_GROUPS = [
|
|
{ name: 'Layout', components: ['Stack', 'Card', 'Grid', 'Tabs', 'Tab', 'Accordion', 'AccordionItem', 'Divider'] },
|
|
{ name: 'Content', components: ['Heading', 'Text', 'Callout', 'Badge', 'Stat', 'Progress', 'Table', 'List', 'Steps', 'Step'] },
|
|
{ name: 'Charts', components: ['BarChart', 'LineChart', 'PieChart', 'Series', 'Slice'], notes: ['- Chart numbers must come from real data: tool results, the student\'s scores, or the conversation. Never invent data to fill a chart.'] },
|
|
{
|
|
name: 'Interactive',
|
|
components: ['Slider', 'NumberInput', 'Select', 'Option', 'Toggle', 'Button', 'Link', 'FollowUps'],
|
|
notes: ['- For calculators, bind inputs to $variables and compute results with expressions, e.g. Stat("Dose", @Round($weight * $mgPerKg, 1) + " mg").'],
|
|
},
|
|
{ name: 'Study', components: ['Question', 'Flashcards', 'FlashCard'], notes: ['- Question options are plain strings; correct holds 0-based indexes into options.'] },
|
|
];
|
|
|
|
export const GENUI_ROOT = 'Stack';
|
|
|
|
export const GENUI_PREAMBLE = `## Interactive blocks in replies
|
|
|
|
Your replies are Markdown, and they can also contain interactive blocks: fenced code blocks tagged openui-lang, written in the small language described below. The app renders each block as a live component inside the reply. Use them actively; they are what makes this assistant better than a plain chat. Text outside the fences stays ordinary Markdown, so write your explanation before and after the block.
|
|
|
|
Reach for a block whenever the reply has one of these shapes:
|
|
- Two or more things compared (drugs, conditions, normal vs abnormal values, signs of left vs right heart failure): a Table.
|
|
- A sequence (a procedure, a pathophysiology chain, nursing priorities in order): Steps.
|
|
- Numbers about the student (scores, attempts, weak topics): a chart or Stat cards.
|
|
- Any calculation (doses, drip rates, fluid balance, BMI): a small calculator with Slider or NumberInput bound to $variables and a Stat showing the result.
|
|
- A safety-critical point (a contraindication, a black box warning, a priority action): a Callout with tone danger or warning.
|
|
- Teaching a concept the student can practise: end with a quick self-check Question and FollowUps.
|
|
|
|
Most teaching answers of more than a few sentences should include one block. Plain Markdown is right only for small talk, one-line answers and replies about the app itself. Use at most two blocks in one reply. Each block is a separate program and nothing else goes inside the fence.`;
|
|
|
|
/** Explain is a short explanation beside a question or card: information only, no practice. */
|
|
export const GENUI_EXPLAIN_RULES = [
|
|
'This is an explanation, not a practice session: never include a Question, Flashcards or anything else that quizzes the student.',
|
|
'Use a block only when it makes the explanation clearer: a Table comparing the choices or conditions, Steps for a mechanism, a Callout for a safety point.',
|
|
];
|
|
|
|
export const GENUI_RULES = [
|
|
'Fence each block as ```openui-lang … ``` and start it with root = Stack([...]).',
|
|
'Never put document citations like [c42] inside a block; cite in the Markdown around it.',
|
|
'Keep blocks compact: a chat column is about 600 pixels wide. Prefer Card, Table, Steps and one chart over large layouts.',
|
|
'Do not repeat the same content in the Markdown and in the block.',
|
|
];
|
|
|
|
export const GENUI_EXAMPLES = [
|
|
`Example: a weight-based dose calculator.
|
|
\`\`\`openui-lang
|
|
root = Stack([calc])
|
|
$weight = 70
|
|
$dose = 1
|
|
calc = Card([w, d, result, note], "Enoxaparin dose")
|
|
w = Slider("weight", "Weight", 30, 150, 1, $weight, "kg")
|
|
d = Slider("dose", "Dose", 0.5, 1.5, 0.5, $dose, "mg/kg")
|
|
result = Stat("Dose to give", @Round($weight * $dose, 1) + " mg", "every 12 hours", "accent")
|
|
note = Callout("Check platelets and renal function before giving.", "warning")
|
|
\`\`\``,
|
|
`Example: a self-check question and follow-ups.
|
|
\`\`\`openui-lang
|
|
root = Stack([q, more])
|
|
q = Question("Which finding needs immediate action in a client receiving furosemide?", ["Potassium 3.0 mEq/L", "Urine output 60 mL/h", "BP 128/80", "Weight down 0.5 kg"], [0], "Hypokalemia raises the risk of dysrhythmias, especially with digoxin.")
|
|
more = FollowUps(["Quiz me on loop diuretics", "Compare furosemide and spironolactone"])
|
|
\`\`\``,
|
|
];
|