@okhay-p/mivra 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,933 @@
1
+ // ../protocol/src/course.ts
2
+ import { z } from "zod";
3
+ var MAX_GOAL_CHARS = 300;
4
+ var CourseGoal = z.string().trim().min(1).max(MAX_GOAL_CHARS);
5
+ var StartCourse = z.object({ goal: CourseGoal }).strict();
6
+ var ConceptName = z.string().trim().min(1).max(80);
7
+ var PlacementQuestionSpec = z.object({
8
+ concept: ConceptName.describe(`The single concept this question probes, e.g. "chain rule". Reuse the exact name from the learner's record when it is there.`),
9
+ question: z.string().trim().min(1).max(1e3),
10
+ options: z.array(z.object({ text: z.string().trim().min(1).max(300) }).strict()).min(2).max(5).describe('2-5 options with distinct text. For true/false or yes/no use two options, e.g. "True" and "False". Never add a "Not sure" option: the UI always offers one.'),
11
+ correctOptionIndex: z.number().int().nonnegative().describe("0-based index of the single correct option."),
12
+ explanation: z.string().trim().min(1).max(600).describe("One or two sentences shown after answering: why the correct option is correct.")
13
+ }).strict().superRefine((spec, ctx) => {
14
+ if (spec.correctOptionIndex >= spec.options.length) {
15
+ ctx.addIssue({ code: "custom", path: ["correctOptionIndex"], message: "correctOptionIndex must point at one of the options" });
16
+ }
17
+ const seen = /* @__PURE__ */ new Map();
18
+ spec.options.forEach((option, i) => {
19
+ const key = option.text.normalize("NFC");
20
+ const first = seen.get(key);
21
+ if (first !== void 0) ctx.addIssue({ code: "custom", path: ["options", i, "text"], message: `duplicates option ${first}` });
22
+ else seen.set(key, i);
23
+ if (/^\s*(not sure|i don'?t know|unsure|skip)\W*$/i.test(option.text)) {
24
+ ctx.addIssue({ code: "custom", path: ["options", i, "text"], message: "Leave out Not sure / Skip: the UI always offers them" });
25
+ }
26
+ });
27
+ });
28
+ var PlacementQuestionPublic = z.object({ concept: z.string(), question: z.string(), options: z.array(z.object({ text: z.string() }).strict()) }).strict();
29
+ var toPlacementQuestionPublic = (spec) => ({
30
+ concept: spec.concept,
31
+ question: spec.question,
32
+ options: spec.options.map((o) => ({ text: o.text }))
33
+ });
34
+ var PlacementAnswer = z.union([
35
+ z.object({ optionIndex: z.number().int().nonnegative() }).strict(),
36
+ z.object({ unsure: z.literal(true) }).strict(),
37
+ z.object({ skipped: z.literal(true) }).strict()
38
+ ]);
39
+ var PlacementResult = z.enum(["correct", "incorrect", "unsure", "skipped"]);
40
+ var PlacementGrade = z.object({ result: PlacementResult, correctOptionIndex: z.number().int().nonnegative(), explanation: z.string() }).strict();
41
+ function gradePlacementQuestion(spec, answer) {
42
+ let result;
43
+ if ("optionIndex" in answer) {
44
+ if (!spec.options[answer.optionIndex]) throw new RangeError(`optionIndex ${answer.optionIndex} is not one of the ${spec.options.length} options`);
45
+ result = answer.optionIndex === spec.correctOptionIndex ? "correct" : "incorrect";
46
+ } else result = "unsure" in answer ? "unsure" : "skipped";
47
+ return { result, correctOptionIndex: spec.correctOptionIndex, explanation: spec.explanation };
48
+ }
49
+ var KnownSource = z.enum(["memory", "test", "guess"]);
50
+ var SyllabusTopicInput = z.object({
51
+ title: z.string().trim().min(1).max(120),
52
+ summary: z.string().trim().min(1).max(400).describe("What the lesson on this topic will cover, in one or two sentences."),
53
+ reason: z.string().trim().min(1).max(300).describe('Why this topic is here for this learner, e.g. "You missed the question on local minima".'),
54
+ requestedByLearner: z.boolean().describe("True if the learner explicitly asked for this topic. Such topics are never removed automatically."),
55
+ concepts: z.array(ConceptName).min(1).max(8).describe("Concept names this topic teaches; reuse names from the learner's record and the placement questions.")
56
+ }).strict();
57
+ var SyllabusInput = z.object({
58
+ topics: z.array(SyllabusTopicInput).min(1).max(20).describe("The ordered topics, first to learn first. Each topic gets one lesson."),
59
+ known: z.array(
60
+ z.object({
61
+ concept: ConceptName,
62
+ source: KnownSource.describe("memory = from their record or memories; test = from this placement interview; guess = your inference"),
63
+ note: z.string().trim().min(1).max(200)
64
+ }).strict()
65
+ ).max(20).describe("What the learner already knows or doesn't, each labelled with where that comes from. Shown to the learner.")
66
+ }).strict().superRefine((input, ctx) => {
67
+ const seen = /* @__PURE__ */ new Set();
68
+ input.topics.forEach((topic, i) => {
69
+ const key = topic.title.trim().toLowerCase();
70
+ if (seen.has(key)) ctx.addIssue({ code: "custom", path: ["topics", i, "title"], message: "Topic titles must be distinct" });
71
+ seen.add(key);
72
+ });
73
+ });
74
+ var SyllabusTopic = SyllabusTopicInput.extend({ id: z.string() }).strict();
75
+ var SyllabusView = z.object({
76
+ version: z.number().int().positive(),
77
+ source: z.enum(["interview", "tutor", "adaptive", "undo"]),
78
+ reason: z.string().nullable(),
79
+ changedTopicIds: z.array(z.string()),
80
+ /** Whether the learner can undo this version: an automatic change none of whose new topics has started. */
81
+ canUndo: z.boolean(),
82
+ topics: z.array(SyllabusTopic),
83
+ known: SyllabusInput.shape.known,
84
+ createdAt: z.string().datetime()
85
+ }).strict();
86
+ var CourseStatus = z.enum(["interviewing", "active", "complete"]);
87
+ var CourseView = z.object({
88
+ id: z.string(),
89
+ sessionId: z.string(),
90
+ goal: z.string(),
91
+ status: CourseStatus,
92
+ syllabus: SyllabusView.nullable(),
93
+ /** The tutor's reply that wrote the first syllabus, which ends the placement interview; null if unknown. */
94
+ interviewMessageId: z.string().nullable(),
95
+ createdAt: z.string().datetime()
96
+ }).strict();
97
+
98
+ // ../protocol/src/lesson.ts
99
+ import { z as z2 } from "zod";
100
+ var LessonSectionKind = z2.enum(["prose", "algorithm_trace", "graph", "multiple_choice", "set_diagram", "table", "worked_steps"]);
101
+ var MAX_LESSON_SECTIONS = 10;
102
+ var LessonOutlineInput = z2.object({
103
+ title: z2.string().trim().min(1).max(120),
104
+ sections: z2.array(
105
+ z2.object({
106
+ title: z2.string().trim().min(1).max(120),
107
+ kind: LessonSectionKind.describe("prose = write_lesson_text; multiple_choice = ask_multiple_choice (a check); the others = the matching show_* tool."),
108
+ purpose: z2.string().trim().min(1).max(300).describe("What this section does for the learner, in one sentence.")
109
+ }).strict()
110
+ ).min(2).max(MAX_LESSON_SECTIONS).describe(`2-${MAX_LESSON_SECTIONS} sections in reading order. Include at least one multiple_choice check, usually after the idea it checks.`)
111
+ }).strict().superRefine((outline, ctx) => {
112
+ if (!outline.sections.some((s) => s.kind === "multiple_choice")) {
113
+ ctx.addIssue({ code: "custom", path: ["sections"], message: "Include at least one multiple_choice check" });
114
+ }
115
+ });
116
+ var LessonTextInput = z2.object({
117
+ markdown: z2.string().trim().min(1).max(6e3).describe("The section's prose, as markdown with $...$ and $$...$$ maths. Don't repeat the section title as a heading."),
118
+ revisits: z2.array(z2.string().min(1)).max(5).optional().describe("sectionIds from <previous_lesson> this section revisits. The page links back to them, so don't write links yourself.")
119
+ }).strict();
120
+ var LessonStatus = z2.enum(["generating", "ready", "failed", "finished"]);
121
+ var LessonOutlineView = z2.object({
122
+ title: z2.string(),
123
+ sections: z2.array(z2.object({ title: z2.string(), kind: LessonSectionKind }).strict())
124
+ }).strict();
125
+ var LessonView = z2.object({
126
+ id: z2.string(),
127
+ courseId: z2.string(),
128
+ topicId: z2.string(),
129
+ topicTitle: z2.string(),
130
+ position: z2.number().int().nonnegative(),
131
+ status: LessonStatus,
132
+ version: z2.number().int().positive().nullable(),
133
+ outline: LessonOutlineView.nullable(),
134
+ sections: z2.array(
135
+ z2.discriminatedUnion("kind", [
136
+ z2.object({
137
+ id: z2.string(),
138
+ title: z2.string(),
139
+ kind: z2.literal("prose"),
140
+ markdown: z2.string(),
141
+ /** Earlier sections this one revisits, for links back to exactly what the learner saw. */
142
+ revisits: z2.array(z2.object({ lessonId: z2.string(), sectionId: z2.string(), title: z2.string(), lessonTitle: z2.string() }).strict())
143
+ }).strict(),
144
+ z2.object({ id: z2.string(), title: z2.string(), kind: z2.literal("artifact"), artifact: z2.unknown() }).strict()
145
+ ])
146
+ ),
147
+ checks: z2.object({ total: z2.number().int().nonnegative(), answered: z2.number().int().nonnegative() }).strict(),
148
+ /** The course's current syllabus version, so a page can notice a change made while it was open. */
149
+ syllabusVersion: z2.number().int().positive().nullable(),
150
+ /** Sections the latest version added or changed, highlighted for the learner, and why. */
151
+ changedSectionIds: z2.array(z2.string()),
152
+ changeReason: z2.string().nullable(),
153
+ /** Whether the learner can finish it now: fully written and every check answered. */
154
+ canFinish: z2.boolean(),
155
+ error: z2.string().nullable(),
156
+ createdAt: z2.string().datetime(),
157
+ finishedAt: z2.string().datetime().nullable()
158
+ }).strict();
159
+ var CourseLessonsView = z2.object({
160
+ topics: z2.array(
161
+ z2.object({
162
+ topicId: z2.string(),
163
+ title: z2.string(),
164
+ lesson: z2.object({ id: z2.string(), status: LessonStatus }).strict().nullable()
165
+ }).strict()
166
+ ),
167
+ /** The lesson to show: the first unfinished one, or the last one once all are finished. */
168
+ currentLessonId: z2.string().nullable(),
169
+ /** The next topic without a lesson, if the learner may start it now. */
170
+ nextTopicId: z2.string().nullable()
171
+ }).strict();
172
+ var SectionTitle = z2.string().trim().min(1).max(120);
173
+ var SectionMarkdown = z2.string().trim().min(1).max(6e3);
174
+ var Reason = z2.string().trim().min(1).max(300);
175
+ var ChangeLessonInput = z2.object({
176
+ reason: Reason.describe('What the learner asked for, in a few words, e.g. "Simpler intro with an example".'),
177
+ operations: z2.array(
178
+ z2.discriminatedUnion("op", [
179
+ z2.object({ op: z2.literal("rewrite"), sectionId: z2.string().min(1), markdown: SectionMarkdown, title: SectionTitle.optional() }).strict().describe("Replace a prose section's text (and optionally its title)."),
180
+ z2.object({ op: z2.literal("insert"), afterSectionId: z2.string().min(1).nullable(), title: SectionTitle, markdown: SectionMarkdown }).strict().describe("Add a prose section after the given section, or first if null."),
181
+ z2.object({ op: z2.literal("insert_artifact"), afterSectionId: z2.string().min(1).nullable(), title: SectionTitle, artifactId: z2.string().min(1) }).strict().describe("Add a card you created earlier in this reply (its artifactId) as a section."),
182
+ z2.object({ op: z2.literal("remove"), sectionId: z2.string().min(1) }).strict(),
183
+ z2.object({ op: z2.literal("move"), sectionId: z2.string().min(1), afterSectionId: z2.string().min(1).nullable() }).strict()
184
+ ])
185
+ ).min(1).max(10)
186
+ }).strict();
187
+ var ChangeSyllabusInput = z2.object({
188
+ reason: Reason.describe('What the learner asked for, e.g. "Add a topic on vectors before gradients".'),
189
+ operations: z2.array(
190
+ z2.discriminatedUnion("op", [
191
+ z2.object({
192
+ op: z2.literal("insert"),
193
+ afterTopicId: z2.string().min(1).nullable().describe("Insert after this topic; null to insert before the first future topic."),
194
+ title: SectionTitle,
195
+ summary: z2.string().trim().min(1).max(400),
196
+ reason: Reason,
197
+ concepts: z2.array(z2.string().trim().min(1).max(80)).min(1).max(8)
198
+ }).strict(),
199
+ z2.object({ op: z2.literal("edit"), topicId: z2.string().min(1), title: SectionTitle.optional(), summary: z2.string().trim().min(1).max(400).optional() }).strict(),
200
+ z2.object({ op: z2.literal("remove"), topicId: z2.string().min(1) }).strict(),
201
+ z2.object({ op: z2.literal("move"), topicId: z2.string().min(1), afterTopicId: z2.string().min(1).nullable() }).strict()
202
+ ])
203
+ ).min(1).max(10)
204
+ }).strict();
205
+ var AddToLesson = z2.object({
206
+ messageId: z2.string().min(1).max(128),
207
+ afterSectionId: z2.string().min(1).max(128).nullable(),
208
+ title: SectionTitle
209
+ }).strict();
210
+ var NewTopic = z2.object({
211
+ title: SectionTitle,
212
+ summary: z2.string().trim().min(1).max(400),
213
+ concepts: z2.array(z2.string().trim().min(1).max(80)).min(1).max(8)
214
+ }).strict();
215
+ var AdaptSyllabusInput = z2.object({
216
+ reason: Reason.describe('Shown to the learner, with the evidence, e.g. "Added a chain rule refresher: you missed 3 of 4 checks on derivatives".'),
217
+ operation: z2.discriminatedUnion("op", [
218
+ NewTopic.extend({ op: z2.literal("insert"), afterTopicId: z2.string().min(1).nullable().describe("null = straight after this lesson's topic") }).strict(),
219
+ z2.object({ op: z2.literal("split"), topicId: z2.string().min(1), into: z2.array(NewTopic).min(2).max(3) }).strict(),
220
+ z2.object({ op: z2.literal("move"), topicId: z2.string().min(1), afterTopicId: z2.string().min(1).nullable() }).strict()
221
+ ])
222
+ }).strict();
223
+
224
+ // ../protocol/src/memory.ts
225
+ import { z as z3 } from "zod";
226
+ var MemoryKind = z3.enum(["goal", "preference", "misconception"]);
227
+ var MemoryText = z3.string().trim().min(1).max(300);
228
+ var RememberInput = z3.object({
229
+ kind: MemoryKind.describe("goal = what they want to learn or do; preference = how they like to learn; misconception = something they believe that is wrong."),
230
+ text: MemoryText.describe("One short sentence about the learner. Never include the answer to a check they haven't answered."),
231
+ concept: z3.string().trim().min(1).max(80).optional().describe("Required for a misconception: the concept it is about. Use the exact name from the check or from their record, so it can be linked to their answers."),
232
+ replaces: z3.string().min(1).optional().describe("The id of a known memory this one corrects or updates.")
233
+ }).strict().superRefine((input, ctx) => {
234
+ if (input.kind === "misconception" && !input.concept) {
235
+ ctx.addIssue({ code: "custom", path: ["concept"], message: "A misconception needs a concept" });
236
+ }
237
+ });
238
+ var MemoryBasis = z3.enum(["wrong_answer", "chat"]);
239
+ var MemoryView = z3.object({
240
+ id: z3.string(),
241
+ kind: MemoryKind,
242
+ held: z3.boolean(),
243
+ text: z3.string().nullable(),
244
+ concept: z3.string().nullable(),
245
+ basis: MemoryBasis.nullable(),
246
+ createdAt: z3.string().datetime(),
247
+ editedAt: z3.string().datetime().nullable()
248
+ }).strict();
249
+ var MemoryEdit = z3.object({ text: MemoryText }).strict();
250
+
251
+ // ../protocol/src/document.ts
252
+ import { z as z4 } from "zod";
253
+ var MAX_DOCUMENT_BYTES = 25 * 1024 * 1024;
254
+ var DocumentView = z4.object({
255
+ id: z4.string(),
256
+ sessionId: z4.string(),
257
+ messageId: z4.string().nullable(),
258
+ filename: z4.string(),
259
+ kind: z4.enum(["pdf", "pptx"]),
260
+ byteSize: z4.number().int(),
261
+ pageCount: z4.number().int(),
262
+ pagesWithText: z4.number().int(),
263
+ status: z4.literal("ready"),
264
+ createdAt: z4.string().datetime()
265
+ });
266
+
267
+ // ../protocol/src/vault.ts
268
+ import { z as z5 } from "zod";
269
+ var MAX_VAULT_FILES = 1e4;
270
+ var MAX_NOTE_CHARS = 1e6;
271
+ var MAX_VAULT_BYTES = 64 * 1024 * 1024;
272
+ var MAX_PATH_CHARS = 512;
273
+ var VaultFile = z5.object({
274
+ /** The file's path inside the vault, with `/` between folders, e.g. `Maths/Recursion.md`. */
275
+ path: z5.string().min(1).max(MAX_PATH_CHARS),
276
+ text: z5.string().max(MAX_NOTE_CHARS)
277
+ }).strict();
278
+ var VaultFiles = z5.array(VaultFile).max(MAX_VAULT_FILES);
279
+ var VaultName = z5.string().trim().min(1).max(120);
280
+ var VaultImportInput = z5.object({ name: VaultName, files: VaultFiles }).strict();
281
+ var VaultSnapshotInput = z5.object({ files: VaultFiles }).strict();
282
+ var VaultImportView = z5.object({
283
+ id: z5.string(),
284
+ name: z5.string(),
285
+ source: z5.literal("obsidian"),
286
+ noteCount: z5.number().int(),
287
+ createdAt: z5.string().datetime(),
288
+ updatedAt: z5.string().datetime()
289
+ }).strict();
290
+ var SkipReason = z5.enum(["not_markdown", "hidden", "bad_path", "duplicate", "too_long", "symlink"]);
291
+ var VaultImportResult = z5.object({
292
+ import: VaultImportView,
293
+ added: z5.number().int(),
294
+ updated: z5.number().int(),
295
+ removed: z5.number().int(),
296
+ unchanged: z5.number().int(),
297
+ skippedCount: z5.number().int(),
298
+ skipped: z5.array(z5.object({ path: z5.string(), reason: SkipReason }).strict()),
299
+ /** Links or tags left out because a note or the vault had more than the limit. */
300
+ truncated: z5.boolean()
301
+ }).strict();
302
+ var NoteView = z5.object({
303
+ id: z5.string(),
304
+ importId: z5.string(),
305
+ path: z5.string(),
306
+ title: z5.string(),
307
+ aliases: z5.array(z5.string()),
308
+ tags: z5.array(z5.string()),
309
+ body: z5.string(),
310
+ updatedAt: z5.string().datetime()
311
+ }).strict();
312
+ var NoteGraph = z5.object({
313
+ notes: z5.array(z5.object({ id: z5.string(), path: z5.string(), title: z5.string(), tags: z5.array(z5.string()) }).strict()),
314
+ links: z5.array(z5.object({ from: z5.string(), to: z5.string().nullable(), target: z5.string(), kind: z5.enum(["link", "embed"]) }).strict())
315
+ }).strict();
316
+
317
+ // ../protocol/src/index.ts
318
+ import { z as z13 } from "zod";
319
+
320
+ // ../protocol/src/artifact-math-input.ts
321
+ import "zod";
322
+
323
+ // ../protocol/src/math-text.ts
324
+ var isSpace = (char) => char !== void 0 && /\s/.test(char);
325
+ var isDigit = (char) => char !== void 0 && char >= "0" && char <= "9";
326
+ function splitMath(source) {
327
+ const pieces = [];
328
+ let literal = "";
329
+ let i = 0;
330
+ while (i < source.length) {
331
+ const char = source[i];
332
+ if (char === "\\" && source[i + 1] === "$") {
333
+ literal += "$";
334
+ i += 2;
335
+ } else if (char !== "$") {
336
+ literal += char;
337
+ i += 1;
338
+ } else if (source[i + 1] === "$") {
339
+ while (source[i] === "$") {
340
+ literal += "$";
341
+ i += 1;
342
+ }
343
+ } else {
344
+ const close = closingDollar(source, i);
345
+ if (close === void 0) {
346
+ literal += "$";
347
+ i += 1;
348
+ } else {
349
+ if (literal) pieces.push({ text: literal });
350
+ literal = "";
351
+ pieces.push({ formula: source.slice(i + 1, close) });
352
+ i = close + 1;
353
+ }
354
+ }
355
+ }
356
+ if (literal) pieces.push({ text: literal });
357
+ return pieces;
358
+ }
359
+ function closingDollar(source, open) {
360
+ let close = open + 1;
361
+ while (close < source.length && source[close] !== "$") {
362
+ close += source[close] === "\\" && (source[close + 1] === "$" || source[close + 1] === "\\") ? 2 : 1;
363
+ }
364
+ if (close >= source.length || close === open + 1 || source[close + 1] === "$") return void 0;
365
+ if (isSpace(source[open + 1]) || isSpace(source[close - 1]) || isDigit(source[close + 1])) return void 0;
366
+ return /`|\n\s*\n/.test(source.slice(open, close)) ? void 0 : close;
367
+ }
368
+
369
+ // ../protocol/src/artifact-math-input.ts
370
+ var REPAIR = String.raw`Wrap LaTeX commands in single-dollar math delimiters, with no spaces inside: $\displaystyle\sum_{i=1}^{n} i$. Put \displaystyle inside the dollars. For literal backslashes followed by two or more letters (such as C:\Users), use forward slashes, Unicode symbols such as ∖, or describe them in words; backticks do not escape artifact math. Correct the affected field and retry this tool call.`;
371
+ function checkMathText(value, path, ctx) {
372
+ if (typeof value === "string" && splitMath(value).some((piece) => "text" in piece && /\\[a-zA-Z]{2,}/.test(piece.text))) {
373
+ ctx.addIssue({ code: "custom", path, message: REPAIR });
374
+ }
375
+ }
376
+ function artifactMathInput(schema, fields, extra) {
377
+ return schema.superRefine((spec, ctx) => {
378
+ const visit = (value, parts, path) => {
379
+ if (parts.length === 0) return checkMathText(value, path, ctx);
380
+ const [key, ...rest] = parts;
381
+ if (key === "*" && Array.isArray(value)) value.forEach((item, i) => visit(item, rest, [...path, i]));
382
+ else if (value && typeof value === "object" && key !== void 0) visit(value[key], rest, [...path, key]);
383
+ };
384
+ for (const field of fields) visit(spec, field.split("."), []);
385
+ extra?.(spec, ctx);
386
+ });
387
+ }
388
+
389
+ // ../protocol/src/algorithm-trace.ts
390
+ import { z as z7 } from "zod";
391
+ var MAX_VALUES = 64;
392
+ var MAX_STEPS = 200;
393
+ var Label = z7.string().trim().min(1).max(40);
394
+ var Cell = z7.union([z7.number(), z7.string().max(24)]);
395
+ var Index = z7.number().int().nonnegative();
396
+ var TracePointer = z7.object({
397
+ name: Label.describe('Pointer label shown under the cell, e.g. "left", "right", "mid", "i".'),
398
+ index: Index.describe("0-based index into the sequence as it is at this step.")
399
+ }).strict();
400
+ var TraceRange = z7.object({
401
+ start: Index.describe("0-based start index, inclusive, within the sequence as it is at this step."),
402
+ end: Index.describe("0-based end index, inclusive. Must be >= start and within the sequence."),
403
+ label: Label.optional().describe('Optional label, e.g. "window".'),
404
+ tone: z7.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished/sorted, muted = ruled out. Defaults to active.")
405
+ }).strict();
406
+ var TraceVariable = z7.object({
407
+ name: Label,
408
+ value: z7.union([z7.number(), z7.string().max(80), z7.boolean()])
409
+ }).strict();
410
+ var TraceStep = z7.object({
411
+ explanation: z7.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
412
+ values: z7.array(Cell).min(1).max(MAX_VALUES).optional().describe("The whole sequence after this step. Omit unless the values changed (e.g. a swap); omitted means unchanged."),
413
+ pointers: z7.array(TracePointer).max(8).optional().describe("All pointers to show at this step. Not carried over from earlier steps: repeat any that still apply."),
414
+ ranges: z7.array(TraceRange).max(8).optional().describe("All highlighted ranges at this step. Not carried over from earlier steps."),
415
+ variables: z7.array(TraceVariable).max(12).optional().describe("All running state at this step, e.g. current sum, best so far. Not carried over from earlier steps.")
416
+ }).strict();
417
+ var AlgorithmTraceSpec = z7.object({
418
+ title: z7.string().trim().min(1).max(120),
419
+ values: z7.array(Cell).min(1).max(MAX_VALUES).describe("The input sequence before the first step."),
420
+ steps: z7.array(TraceStep).min(1).max(MAX_STEPS)
421
+ }).strict().superRefine((spec, ctx) => {
422
+ let length = spec.values.length;
423
+ spec.steps.forEach((step, i) => {
424
+ if (step.values) length = step.values.length;
425
+ step.pointers?.forEach((p, j) => {
426
+ if (p.index >= length) {
427
+ ctx.addIssue({
428
+ code: "custom",
429
+ path: ["steps", i, "pointers", j, "index"],
430
+ message: `index ${p.index} is outside the sequence (length ${length})`
431
+ });
432
+ }
433
+ });
434
+ step.ranges?.forEach((r, j) => {
435
+ if (r.end >= length || r.start > r.end) {
436
+ ctx.addIssue({
437
+ code: "custom",
438
+ path: ["steps", i, "ranges", j],
439
+ message: `range ${r.start}..${r.end} is invalid for a sequence of length ${length}`
440
+ });
441
+ }
442
+ });
443
+ });
444
+ });
445
+
446
+ // ../protocol/src/graph.ts
447
+ import { z as z8 } from "zod";
448
+ var MAX_NODES = 60;
449
+ var MAX_EDGES = 200;
450
+ var MAX_STEPS2 = 200;
451
+ var Id = z8.string().trim().min(1).max(24);
452
+ var Text = z8.string().trim().min(1).max(24);
453
+ var GraphTone = z8.enum(["active", "done", "muted"]);
454
+ var ToneField = GraphTone.optional().describe(
455
+ "active = current focus, done = finished/visited, muted = ruled out. Defaults to active."
456
+ );
457
+ var GraphNode = z8.object({
458
+ id: Id.describe("Unique id, used by edges and steps. Shown on the node if it has no label."),
459
+ label: Text.optional().describe("Short text on the node. Only $...$ is a formula, e.g. $v_1$.")
460
+ }).strict();
461
+ var GraphEdge = z8.object({
462
+ from: Id.describe("Id of a node. In a tree, the parent."),
463
+ to: Id.describe("Id of a node, the same as `from` for a self-loop. In a tree, the child; children appear left to right in edge order unless they have a `side`."),
464
+ side: z8.enum(["left", "right"]).optional().describe(
465
+ "Only when kind is tree: which child this is of `from`, its parent. Set it on every edge of a binary search tree or binary tree traversal, because a lone left child and a lone right child are different trees. A node has at most one child per side, and either all of its children have a side or none do."
466
+ ),
467
+ weight: z8.number().optional().describe("Numeric weight shown on the edge. Give a weight or a label, not both."),
468
+ label: Text.optional().describe("Text shown on the edge. Only $...$ is a formula.")
469
+ }).strict();
470
+ var GraphNodeState = z8.object({ id: Id.describe("Id of a node."), tone: ToneField }).strict();
471
+ var GraphEdgeState = z8.object({
472
+ from: Id,
473
+ to: Id,
474
+ nth: z8.number().int().nonnegative().optional().describe("Only for parallel edges, and then required: which of the edges joining these nodes, 0-based in the order of `edges`."),
475
+ tone: ToneField
476
+ }).strict().describe("An edge of the graph. In an undirected graph, from and to may be in either order.");
477
+ var GraphStep = z8.object({
478
+ explanation: z8.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
479
+ nodeStates: z8.array(GraphNodeState).max(MAX_NODES).optional().describe("The state of every node that has one at this step, at most one each. Not carried over from earlier steps: repeat any that still apply."),
480
+ edgeStates: z8.array(GraphEdgeState).max(MAX_EDGES).optional().describe("The state of every edge that has one at this step, at most one each. Not carried over from earlier steps: repeat any that still apply."),
481
+ variables: z8.array(TraceVariable).max(12).optional().describe("All running state at this step, e.g. the queue or current distances. Not carried over from earlier steps.")
482
+ }).strict();
483
+ var pairKey = (from, to, directed) => JSON.stringify(directed || from <= to ? [from, to] : [to, from]);
484
+ function graphEdgeLookup(spec) {
485
+ const byPair = /* @__PURE__ */ new Map();
486
+ spec.edges.forEach((edge, i) => {
487
+ const key = pairKey(edge.from, edge.to, spec.directed);
488
+ const indices = byPair.get(key);
489
+ if (indices) indices.push(i);
490
+ else byPair.set(key, [i]);
491
+ });
492
+ return (ref) => {
493
+ const name = `${ref.from} ${spec.directed ? "->" : "--"} ${ref.to}`;
494
+ const indices = byPair.get(pairKey(ref.from, ref.to, spec.directed));
495
+ if (!indices) return { error: `there is no edge ${name}` };
496
+ if (ref.nth === void 0 && indices.length > 1) return { error: `${indices.length} edges match ${name}: set nth to pick one` };
497
+ const index = indices[ref.nth ?? 0];
498
+ return index === void 0 ? { error: `nth ${ref.nth} is out of range: ${indices.length} edges match ${name}` } : { index };
499
+ };
500
+ }
501
+ function graphTreeShape(spec) {
502
+ if (spec.edges.length !== spec.nodes.length - 1) return void 0;
503
+ const ids = spec.nodes.map((node) => node.id);
504
+ const adjacent = new Map(ids.map((id) => [id, []]));
505
+ for (const { from, to } of spec.edges) {
506
+ adjacent.get(from).push(to);
507
+ if (!spec.directed && from !== to) adjacent.get(to).push(from);
508
+ }
509
+ const roots = spec.directed ? ids.filter((id) => !spec.edges.some((edge) => edge.to === id)) : ids.slice(0, 1);
510
+ const root = roots[0];
511
+ if (roots.length !== 1 || root === void 0) return void 0;
512
+ const children = /* @__PURE__ */ new Map();
513
+ const pending = [root];
514
+ while (pending.length) {
515
+ const id = pending.pop();
516
+ const next = adjacent.get(id).filter((other) => !children.has(other));
517
+ children.set(id, next);
518
+ pending.push(...next);
519
+ }
520
+ return children.size === ids.length ? { root, children } : void 0;
521
+ }
522
+ function checkSides(spec, ctx) {
523
+ const sided = spec.edges.flatMap((edge, i) => edge.side ? [{ edge, side: edge.side, path: ["edges", i, "side"] }] : []);
524
+ const first = sided[0];
525
+ if (!first) return;
526
+ if (spec.kind !== "tree") {
527
+ for (const { path } of sided) ctx.addIssue({ code: "custom", path, message: 'side only applies when kind is "tree": remove it, or set kind' });
528
+ return;
529
+ }
530
+ const shape = graphTreeShape(spec);
531
+ if (!shape) {
532
+ ctx.addIssue({ code: "custom", path: first.path, message: "side needs a real tree: connected with no cycles, and when directed, edges going parent to child from one root" });
533
+ return;
534
+ }
535
+ const sideOf = /* @__PURE__ */ new Map();
536
+ for (const { edge, side, path } of sided) {
537
+ if (shape.children.get(edge.from).includes(edge.to)) sideOf.set(edge.to, side);
538
+ else ctx.addIssue({ code: "custom", path, message: `side needs from to be the parent, but ${edge.to} is the parent of ${edge.from} here: swap them` });
539
+ }
540
+ for (const [parent, children] of shape.children) {
541
+ const sides = children.flatMap((child) => sideOf.get(child) ?? []);
542
+ if (sides.length > 0 && sides.length < children.length) {
543
+ ctx.addIssue({ code: "custom", path: ["edges"], message: `node ${parent} mixes children with and without a side: give all of them one, or none` });
544
+ }
545
+ for (const side of ["left", "right"]) {
546
+ if (sides.filter((s) => s === side).length > 1) ctx.addIssue({ code: "custom", path: ["edges"], message: `node ${parent} has two ${side} children` });
547
+ }
548
+ }
549
+ }
550
+ var GraphSpec = z8.object({
551
+ title: z8.string().trim().min(1).max(120),
552
+ directed: z8.boolean().describe("True draws arrowheads from `from` to `to`."),
553
+ kind: z8.enum(["tree", "graph"]).optional().describe(
554
+ "Layout hint. tree draws a rooted tree top-down, and needs a real tree: connected with no cycles, and when directed, edges going parent to child from one root. When undirected, the first node is the root. Anything else falls back to the general layout, unless an edge has a `side`, which is then an error. Defaults to graph."
555
+ ),
556
+ nodes: z8.array(GraphNode).min(1).max(MAX_NODES),
557
+ edges: z8.array(GraphEdge).max(MAX_EDGES).describe("Self-loops and parallel edges are allowed."),
558
+ steps: z8.array(GraphStep).min(1).max(MAX_STEPS2).optional().describe("Omit to show the graph without stepping through it.")
559
+ }).strict().superRefine((spec, ctx) => {
560
+ const ids = /* @__PURE__ */ new Set();
561
+ spec.nodes.forEach((node, i) => {
562
+ if (ids.has(node.id)) ctx.addIssue({ code: "custom", path: ["nodes", i, "id"], message: `duplicate node id ${node.id}` });
563
+ ids.add(node.id);
564
+ });
565
+ spec.edges.forEach((edge, i) => {
566
+ for (const end of ["from", "to"]) {
567
+ if (!ids.has(edge[end])) ctx.addIssue({ code: "custom", path: ["edges", i, end], message: `no node has id ${edge[end]}` });
568
+ }
569
+ if (edge.weight !== void 0 && edge.label !== void 0) {
570
+ ctx.addIssue({ code: "custom", path: ["edges", i], message: "give a weight or a label, not both" });
571
+ }
572
+ });
573
+ if (spec.edges.every((edge) => ids.has(edge.from) && ids.has(edge.to))) checkSides(spec, ctx);
574
+ const lookup = graphEdgeLookup(spec);
575
+ spec.steps?.forEach((step, i) => {
576
+ const seenNodes = /* @__PURE__ */ new Set();
577
+ step.nodeStates?.forEach((state, j) => {
578
+ const path = ["steps", i, "nodeStates", j];
579
+ if (!ids.has(state.id)) ctx.addIssue({ code: "custom", path, message: `no node has id ${state.id}` });
580
+ if (seenNodes.has(state.id)) ctx.addIssue({ code: "custom", path, message: `node ${state.id} has two states in one step` });
581
+ seenNodes.add(state.id);
582
+ });
583
+ const seenEdges = /* @__PURE__ */ new Set();
584
+ step.edgeStates?.forEach((state, j) => {
585
+ const path = ["steps", i, "edgeStates", j];
586
+ const found = lookup(state);
587
+ if ("error" in found) return ctx.addIssue({ code: "custom", path, message: found.error });
588
+ if (seenEdges.has(found.index)) ctx.addIssue({ code: "custom", path, message: `edge ${found.index} has two states in one step` });
589
+ seenEdges.add(found.index);
590
+ });
591
+ });
592
+ });
593
+
594
+ // ../protocol/src/multiple-choice.ts
595
+ import { z as z9 } from "zod";
596
+ var MultipleChoiceOption = z9.object({
597
+ text: z9.string().trim().min(1).max(300),
598
+ feedback: z9.string().trim().min(1).max(500).optional().describe("Shown if the learner picks this option: why it is right or what misconception it reflects.")
599
+ }).strict();
600
+ var MultipleChoiceSpec = z9.object({
601
+ concept: z9.string().trim().min(1).max(80).describe('Short label for the concept being checked, e.g. "sliding window invariant". Used to track progress.'),
602
+ question: z9.string().trim().min(1).max(1e3),
603
+ options: z9.array(MultipleChoiceOption).min(2).max(6).describe("2-6 options with distinct text."),
604
+ correctOptionIndex: z9.number().int().nonnegative().describe("0-based index of the single correct option; must be less than the number of options."),
605
+ explanation: z9.string().trim().min(1).max(1e3).describe("Shown after answering: why the correct option is correct.")
606
+ }).strict().superRefine((spec, ctx) => {
607
+ if (spec.correctOptionIndex >= spec.options.length) {
608
+ ctx.addIssue({
609
+ code: "custom",
610
+ path: ["correctOptionIndex"],
611
+ message: "correctOptionIndex must point at one of the options"
612
+ });
613
+ }
614
+ const seen = /* @__PURE__ */ new Map();
615
+ spec.options.forEach((option, i) => {
616
+ const key = option.text.normalize("NFC");
617
+ const first = seen.get(key);
618
+ if (first !== void 0) {
619
+ ctx.addIssue({ code: "custom", path: ["options", i, "text"], message: `duplicates option ${first}` });
620
+ } else {
621
+ seen.set(key, i);
622
+ }
623
+ });
624
+ });
625
+ var MultipleChoicePublic = z9.object({
626
+ concept: z9.string(),
627
+ question: z9.string(),
628
+ options: z9.array(z9.object({ text: z9.string() }).strict())
629
+ }).strict();
630
+ function toMultipleChoicePublic(spec) {
631
+ return {
632
+ concept: spec.concept,
633
+ question: spec.question,
634
+ options: spec.options.map((o) => ({ text: o.text }))
635
+ };
636
+ }
637
+ var MultipleChoiceAnswer = z9.object({ optionIndex: z9.number().int().nonnegative() }).strict();
638
+ var MultipleChoiceGrade = z9.object({
639
+ correct: z9.boolean(),
640
+ correctOptionIndex: z9.number().int().nonnegative(),
641
+ explanation: z9.string(),
642
+ feedback: z9.string().optional()
643
+ }).strict();
644
+ function gradeMultipleChoice(spec, answer) {
645
+ const chosen = spec.options[answer.optionIndex];
646
+ if (!chosen) throw new RangeError(`optionIndex ${answer.optionIndex} is not one of the ${spec.options.length} options`);
647
+ return {
648
+ correct: answer.optionIndex === spec.correctOptionIndex,
649
+ correctOptionIndex: spec.correctOptionIndex,
650
+ explanation: spec.explanation,
651
+ ...chosen.feedback ? { feedback: chosen.feedback } : {}
652
+ };
653
+ }
654
+
655
+ // ../protocol/src/set-diagram.ts
656
+ import { z as z10 } from "zod";
657
+ var MAX_SETS = 3;
658
+ var MAX_REGIONS = 8;
659
+ var MAX_ELEMENTS = 30;
660
+ var MAX_STEPS3 = 40;
661
+ var SetId = z10.string().trim().min(1).max(24);
662
+ var ONE_LINE = /^[^\n\r\v\f\u0085\u2028\u2029]*$/;
663
+ var oneLine = (max) => z10.string().trim().min(1).max(max).regex(ONE_LINE, "must not contain line breaks");
664
+ var Element = z10.union([z10.number(), oneLine(24)]);
665
+ function setRegionKey(ids) {
666
+ return JSON.stringify([...ids].sort());
667
+ }
668
+ var RegionIn = z10.array(SetId).max(MAX_SETS);
669
+ var SetDiagramSet = z10.object({
670
+ id: SetId.describe('Short id used to refer to this set, e.g. "a". Unique within the diagram.'),
671
+ label: oneLine(32).describe('Shown next to the circle, e.g. "$A$" or "Multiples of 3", on one line. Only $...$ is a formula.')
672
+ }).strict();
673
+ var SetDiagramRegion = z10.object({
674
+ in: RegionIn.describe('Ids of the sets this region is inside. It is outside all the others: with sets a, b, c, ["a","b"] means in a and b, not c. [] means outside every set and needs `universe`. No id twice.'),
675
+ elements: z10.array(Element).max(MAX_ELEMENTS).describe('What the region contains, each short and on one line. No element may appear twice, in this list or across regions, and 1 and "1" count as the same element. Empty if you only know the count, or the region is empty.'),
676
+ count: z10.number().int().nonnegative().max(1e6).optional().describe("How many elements the region has, when that's more than you list, e.g. for inclusion-exclusion. At least the number of elements listed.")
677
+ }).strict();
678
+ var SetDiagramHighlight = z10.object({
679
+ in: RegionIn.describe("The region to highlight, named like a region's `in`, with no id twice. Any region of the diagram can be highlighted, listed or not."),
680
+ tone: z10.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished, muted = ruled out. Defaults to active.")
681
+ }).strict();
682
+ var SetDiagramStep = z10.object({
683
+ explanation: z10.string().trim().min(1).max(500).describe("What this step shows, in one or two sentences."),
684
+ highlights: z10.array(SetDiagramHighlight).max(MAX_REGIONS).optional().describe("All regions highlighted at this step, each at most once. They apply to this step only, not carried over: repeat any that still apply."),
685
+ variables: z10.array(TraceVariable).max(12).optional().describe("All running state at this step, e.g. |A \u222A B| so far. Not carried over from earlier steps.")
686
+ }).strict();
687
+ var SetDiagramSpec = z10.object({
688
+ title: z10.string().trim().min(1).max(120),
689
+ sets: z10.array(SetDiagramSet).min(1).max(MAX_SETS).describe("The circles, 1 to 3."),
690
+ universe: oneLine(24).optional().describe('Label of the rectangle around the sets, e.g. "$U$", on one line. Needed to show or highlight the region outside every set, such as a complement.'),
691
+ regions: z10.array(SetDiagramRegion).max(MAX_REGIONS).describe("What each region contains, each region at most once."),
692
+ steps: z10.array(SetDiagramStep).min(1).max(MAX_STEPS3).optional().describe("Optional walk through the diagram. Omit for a static diagram.")
693
+ }).strict().superRefine((spec, ctx) => {
694
+ const ids = spec.sets.map((s) => s.id);
695
+ spec.sets.forEach((set, i) => {
696
+ if (ids.indexOf(set.id) !== i) ctx.addIssue({ code: "custom", path: ["sets", i, "id"], message: `duplicate set id "${set.id}"` });
697
+ });
698
+ const checkRegions = (entries, path) => {
699
+ const seen = /* @__PURE__ */ new Set();
700
+ entries.forEach((entry, i) => {
701
+ const at = [...path, i, "in"];
702
+ entry.in.forEach((id, j) => {
703
+ if (!ids.includes(id)) ctx.addIssue({ code: "custom", path: [...at, j], message: `unknown set "${id}"` });
704
+ if (entry.in.indexOf(id) !== j) ctx.addIssue({ code: "custom", path: [...at, j], message: `set "${id}" is named twice` });
705
+ });
706
+ if (entry.in.length === 0 && spec.universe === void 0) {
707
+ ctx.addIssue({ code: "custom", path: at, message: "the region outside every set needs `universe`" });
708
+ }
709
+ const key = setRegionKey(entry.in);
710
+ if (seen.has(key)) ctx.addIssue({ code: "custom", path: at, message: `region ${key} appears more than once` });
711
+ seen.add(key);
712
+ });
713
+ };
714
+ checkRegions(spec.regions, ["regions"]);
715
+ spec.steps?.forEach((step, i) => checkRegions(step.highlights ?? [], ["steps", i, "highlights"]));
716
+ const placed = /* @__PURE__ */ new Set();
717
+ spec.regions.forEach((region, i) => {
718
+ region.elements.forEach((element, j) => {
719
+ if (placed.has(String(element))) {
720
+ ctx.addIssue({ code: "custom", path: ["regions", i, "elements", j], message: `element "${element}" appears more than once; regions don't overlap` });
721
+ }
722
+ placed.add(String(element));
723
+ });
724
+ if (region.count !== void 0 && region.count < region.elements.length) {
725
+ ctx.addIssue({ code: "custom", path: ["regions", i, "count"], message: `count ${region.count} is less than the ${region.elements.length} elements listed` });
726
+ }
727
+ });
728
+ });
729
+
730
+ // ../protocol/src/table.ts
731
+ import { z as z11 } from "zod";
732
+ var MAX_COLUMNS = 16;
733
+ var MAX_ROWS = 64;
734
+ var MAX_STEPS4 = 100;
735
+ var Header = z11.string().trim().min(1).max(80);
736
+ var CellValue = z11.union([z11.number(), z11.boolean(), z11.string().max(120)]);
737
+ var Index2 = z11.number().int().nonnegative();
738
+ var TableHighlight = z11.object({
739
+ row: Index2.optional().describe("0-based data row, below the number of rows. With no column, highlights the whole row. A highlight must give a row, a column or both."),
740
+ column: Index2.optional().describe("0-based data column, below the number of columns. With no row, highlights the whole column. With both, highlights one cell."),
741
+ tone: z11.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished, muted = ruled out. Defaults to active. Where highlights overlap, the later one wins.")
742
+ }).strict();
743
+ var TableCellChange = z11.object({
744
+ row: Index2.describe("0-based data row, below the number of rows."),
745
+ column: Index2.describe("0-based data column, below the number of columns."),
746
+ value: CellValue.describe("The cell's value from this step on.")
747
+ }).strict();
748
+ var TableStep = z11.object({
749
+ explanation: z11.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
750
+ highlight: z11.array(TableHighlight).max(32).optional().describe("All cells, rows and columns to highlight at this step. Not carried over from earlier steps."),
751
+ cells: z11.array(TableCellChange).max(64).optional().describe('Cells this step fills in or changes. They keep the new value on later steps. To reveal working, start a cell as "" and set it here.')
752
+ }).strict();
753
+ var TableSpec = z11.object({
754
+ title: z11.string().trim().min(1).max(120),
755
+ columns: z11.array(Header).min(1).max(MAX_COLUMNS).describe("Column headers, one per data column. Don't include a header for rowHeaders."),
756
+ rows: z11.array(z11.array(CellValue).min(1).max(MAX_COLUMNS)).min(1).max(MAX_ROWS).describe('Data rows, each with exactly one cell per column. A boolean shows as T or F; "" is a blank cell.'),
757
+ rowHeaders: z11.array(Header).max(MAX_ROWS).optional().describe("Optional label for each row, e.g. a relation matrix's elements. Exactly one per row."),
758
+ steps: z11.array(TableStep).min(1).max(MAX_STEPS4).optional().describe("Omit for a static table. With steps, the learner steps through them.")
759
+ }).strict().superRefine((spec, ctx) => {
760
+ const rowCount = spec.rows.length;
761
+ const columnCount = spec.columns.length;
762
+ spec.rows.forEach((row, i) => {
763
+ if (row.length !== columnCount) {
764
+ ctx.addIssue({ code: "custom", path: ["rows", i], message: `row has ${row.length} cells but there are ${columnCount} columns` });
765
+ }
766
+ });
767
+ if (spec.rowHeaders && spec.rowHeaders.length !== rowCount) {
768
+ ctx.addIssue({ code: "custom", path: ["rowHeaders"], message: `${spec.rowHeaders.length} row headers for ${rowCount} rows` });
769
+ }
770
+ const checkRow = (row, path) => {
771
+ if (row >= rowCount) ctx.addIssue({ code: "custom", path, message: `row ${row} is outside the table (${rowCount} rows)` });
772
+ };
773
+ const checkColumn = (column, path) => {
774
+ if (column >= columnCount) ctx.addIssue({ code: "custom", path, message: `column ${column} is outside the table (${columnCount} columns)` });
775
+ };
776
+ spec.steps?.forEach((step, i) => {
777
+ step.highlight?.forEach((h, j) => {
778
+ const path = ["steps", i, "highlight", j];
779
+ if (h.row === void 0 && h.column === void 0) ctx.addIssue({ code: "custom", path, message: "a highlight needs a row, a column or both" });
780
+ if (h.row !== void 0) checkRow(h.row, [...path, "row"]);
781
+ if (h.column !== void 0) checkColumn(h.column, [...path, "column"]);
782
+ });
783
+ step.cells?.forEach((c, j) => {
784
+ checkRow(c.row, ["steps", i, "cells", j, "row"]);
785
+ checkColumn(c.column, ["steps", i, "cells", j, "column"]);
786
+ });
787
+ });
788
+ });
789
+
790
+ // ../protocol/src/worked-steps.ts
791
+ import { z as z12 } from "zod";
792
+ var MAX_STEPS5 = 50;
793
+ var WorkedStep = z12.object({
794
+ label: z12.string().trim().min(1).max(40).optional().describe('Optional heading for this part of the working, e.g. "Base case", "Inductive step".'),
795
+ statement: z12.string().trim().min(1).max(1e3).describe("What this step establishes, mostly as a formula in $...$. For large sums and fractions, put \\displaystyle INSIDE the dollars, e.g. $\\displaystyle\\sum_{i=1}^{n} i$; $$ is not available."),
796
+ justification: z12.string().trim().min(1).max(500).describe('Why it follows, e.g. "by the inductive hypothesis".')
797
+ }).strict();
798
+ var WorkedStepsSpec = z12.object({
799
+ title: z12.string().trim().min(1).max(120),
800
+ goal: z12.string().trim().min(1).max(500).optional().describe("Optional statement of what is being shown, e.g. the claim to prove."),
801
+ steps: z12.array(WorkedStep).min(1).max(MAX_STEPS5)
802
+ }).strict();
803
+
804
+ // ../protocol/src/index.ts
805
+ var artifactKinds = {
806
+ algorithm_trace: {
807
+ version: 1,
808
+ toolName: "show_algorithm_trace",
809
+ description: "Show the learner an interactive step-by-step trace of an algorithm running over a sequence (e.g. sliding window, two pointers, binary search, a simple sort). The learner steps through it with play/pause/step controls. Use it when watching state change step by step will make the idea click. Keep traces short (roughly 5-20 steps) and make each step's explanation say what changed and why.",
810
+ spec: AlgorithmTraceSpec,
811
+ input: artifactMathInput(AlgorithmTraceSpec, ["title", "steps.*.explanation"])
812
+ },
813
+ graph: {
814
+ version: 1,
815
+ toolName: "show_graph",
816
+ description: "Show the learner a graph or tree, drawn for you, optionally with steps they can walk through. Use it for graphs, trees, BFS, DFS, shortest paths, spanning trees and tree traversals, whenever seeing the structure or watching an algorithm move over it will help. Never give coordinates: the layout is automatic. For a binary search tree or binary tree traversal, set kind to tree and give every edge a side, so a lone left child and a lone right child are drawn differently. The automatic layout may draw crossing edges that mean nothing, even when the graph is planar, so don't use this to show whether a graph is planar. Keep it small enough to read (roughly 4-15 nodes, 5-20 steps) and make each step's explanation say what changed and why.",
817
+ spec: GraphSpec,
818
+ input: artifactMathInput(GraphSpec, ["title", "nodes.*.label", "edges.*.label", "steps.*.explanation"], (spec, ctx) => {
819
+ spec.nodes.forEach((node, i) => {
820
+ if (node.label === void 0) checkMathText(node.id, ["nodes", i, "id"], ctx);
821
+ });
822
+ })
823
+ },
824
+ multiple_choice: {
825
+ version: 1,
826
+ toolName: "ask_multiple_choice",
827
+ description: "Ask the learner one multiple-choice question to check understanding of a concept you just taught. Exactly one option is correct. Write plausible wrong options that reflect real misconceptions, and give per-option feedback where useful. The learner answers in the UI; the result is reported back to you on the next turn, so do not reveal the answer in your reply.",
828
+ spec: MultipleChoiceSpec,
829
+ input: artifactMathInput(MultipleChoiceSpec, ["question", "options.*.text", "options.*.feedback", "explanation"])
830
+ },
831
+ placement_question: {
832
+ version: 1,
833
+ toolName: "ask_placement_question",
834
+ description: `Course placement interview only: ask the learner one quick question to find out what they already know about one concept, before the syllabus is written. Use multiple choice, true/false or yes/no. The UI always adds "Not sure" and "Skip", so never include those as options. The learner answers in the UI and the result is reported back to you, so don't reveal the answer.`,
835
+ spec: PlacementQuestionSpec,
836
+ input: artifactMathInput(PlacementQuestionSpec, ["question", "options.*.text", "explanation"])
837
+ },
838
+ set_diagram: {
839
+ version: 1,
840
+ toolName: "show_set_diagram",
841
+ description: "Show the learner a Venn diagram of 1 to 3 sets, with what each region contains. Use it for set operations (union, intersection, complement, difference) and inclusion-exclusion, not for more than 3 sets. Keep elements short, because they are drawn in their region. Add steps to walk through it: each step highlights exact regions (any of them, including outside every set, which needs `universe`) and says what changed and why.",
842
+ spec: SetDiagramSpec,
843
+ input: artifactMathInput(SetDiagramSpec, ["title", "universe", "sets.*.label", "regions.*.elements.*", "steps.*.explanation", "steps.*.variables.*.name", "steps.*.variables.*.value"])
844
+ },
845
+ table: {
846
+ version: 1,
847
+ toolName: "show_table",
848
+ description: "Show the learner a table: a truth table, a relation matrix or other tabular working. Use it whenever the content is really rows and columns. Add steps when filling it in or highlighting it one part at a time will help, such as working out a truth table column by column; leave them out for a table to read at a glance. Keep steps short and make each explanation say what changed and why.",
849
+ spec: TableSpec,
850
+ input: artifactMathInput(TableSpec, ["title", "columns.*", "rowHeaders.*", "rows.*.*", "steps.*.explanation", "steps.*.cells.*.value"])
851
+ },
852
+ worked_steps: {
853
+ version: 1,
854
+ toolName: "show_worked_steps",
855
+ description: "Show the learner a proof, an induction or combinatorics working as a sequence of steps they reveal one at a time, each a statement with its justification. Use it when the reasoning is the point and each line follows from the ones before. Use show_algorithm_trace instead for an algorithm's state changing over a sequence.",
856
+ spec: WorkedStepsSpec,
857
+ input: artifactMathInput(WorkedStepsSpec, ["title", "goal", "steps.*.label", "steps.*.statement", "steps.*.justification"])
858
+ }
859
+ };
860
+ var ArtifactKind = z13.enum(Object.keys(artifactKinds));
861
+ var ArtifactBase = { id: z13.string(), createdAt: z13.string().datetime() };
862
+ var MultipleChoiceAttempt = z13.object({ answer: MultipleChoiceAnswer, grade: MultipleChoiceGrade, createdAt: z13.string().datetime() }).strict();
863
+ var PlacementAttempt = z13.object({ answer: PlacementAnswer, grade: PlacementGrade, createdAt: z13.string().datetime() }).strict();
864
+ var ArtifactView = z13.discriminatedUnion("kind", [
865
+ z13.object({ ...ArtifactBase, kind: z13.literal("algorithm_trace"), version: z13.literal(1), spec: AlgorithmTraceSpec }).strict(),
866
+ z13.object({ ...ArtifactBase, kind: z13.literal("graph"), version: z13.literal(1), spec: GraphSpec }).strict(),
867
+ z13.object({
868
+ ...ArtifactBase,
869
+ kind: z13.literal("multiple_choice"),
870
+ version: z13.literal(1),
871
+ spec: MultipleChoicePublic,
872
+ latestAttempt: MultipleChoiceAttempt.optional()
873
+ }).strict(),
874
+ z13.object({
875
+ ...ArtifactBase,
876
+ kind: z13.literal("placement_question"),
877
+ version: z13.literal(1),
878
+ spec: PlacementQuestionPublic,
879
+ latestAttempt: PlacementAttempt.optional()
880
+ }).strict(),
881
+ z13.object({ ...ArtifactBase, kind: z13.literal("set_diagram"), version: z13.literal(1), spec: SetDiagramSpec }).strict(),
882
+ z13.object({ ...ArtifactBase, kind: z13.literal("table"), version: z13.literal(1), spec: TableSpec }).strict(),
883
+ z13.object({ ...ArtifactBase, kind: z13.literal("worked_steps"), version: z13.literal(1), spec: WorkedStepsSpec }).strict()
884
+ ]);
885
+ var CHATGPT_USAGE_LIMIT_ERROR = "ChatGPT usage limit reached. Review your plan or this app's limit in ChatGPT settings.";
886
+
887
+ export {
888
+ AlgorithmTraceSpec,
889
+ StartCourse,
890
+ PlacementQuestionSpec,
891
+ toPlacementQuestionPublic,
892
+ PlacementAnswer,
893
+ gradePlacementQuestion,
894
+ SyllabusInput,
895
+ CourseView,
896
+ GraphSpec,
897
+ MultipleChoiceSpec,
898
+ toMultipleChoicePublic,
899
+ MultipleChoiceAnswer,
900
+ gradeMultipleChoice,
901
+ SetDiagramSpec,
902
+ TableSpec,
903
+ WorkedStepsSpec,
904
+ LessonSectionKind,
905
+ MAX_LESSON_SECTIONS,
906
+ LessonOutlineInput,
907
+ LessonTextInput,
908
+ LessonView,
909
+ CourseLessonsView,
910
+ ChangeLessonInput,
911
+ ChangeSyllabusInput,
912
+ AddToLesson,
913
+ AdaptSyllabusInput,
914
+ RememberInput,
915
+ MemoryView,
916
+ MemoryEdit,
917
+ MAX_DOCUMENT_BYTES,
918
+ DocumentView,
919
+ MAX_VAULT_FILES,
920
+ MAX_NOTE_CHARS,
921
+ MAX_VAULT_BYTES,
922
+ VaultImportInput,
923
+ VaultSnapshotInput,
924
+ VaultImportView,
925
+ SkipReason,
926
+ VaultImportResult,
927
+ NoteView,
928
+ NoteGraph,
929
+ artifactKinds,
930
+ ArtifactView,
931
+ CHATGPT_USAGE_LIMIT_ERROR
932
+ };
933
+ //# sourceMappingURL=chunk-FBDML53R.js.map