@okhay-p/mivra 0.1.2 → 0.1.4
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.
- package/README.md +1 -0
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/chunk-KE5ZEREE.js +212 -0
- package/dist/chunk-KE5ZEREE.js.map +7 -0
- package/dist/chunk-KUKQU7EQ.js +755 -0
- package/dist/chunk-KUKQU7EQ.js.map +7 -0
- package/dist/chunk-ODFBAPPH.js +489 -0
- package/dist/chunk-ODFBAPPH.js.map +7 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +7 -0
- package/dist/chunk-TBAR47I6.js +32 -0
- package/dist/chunk-TBAR47I6.js.map +7 -0
- package/dist/chunk-YACRW47X.js +1203 -0
- package/dist/chunk-YACRW47X.js.map +7 -0
- package/dist/cli.js +256 -11188
- package/dist/cli.js.map +4 -4
- package/dist/client-5YDLS4KV.js +12 -0
- package/dist/client-5YDLS4KV.js.map +7 -0
- package/dist/extract-child.js +107 -173
- package/dist/extract-child.js.map +3 -3
- package/dist/key-check-WJ4CVZV5.js +8 -0
- package/dist/key-check-WJ4CVZV5.js.map +7 -0
- package/dist/start-76LKE3DL.js +13906 -0
- package/dist/start-76LKE3DL.js.map +7 -0
- package/drizzle/0012_overconfident_the_santerians.sql +66 -0
- package/drizzle/0013_next_dormammu.sql +1 -0
- package/drizzle/0014_furry_inertia.sql +1 -0
- package/drizzle/0015_spotty_warstar.sql +1 -0
- package/drizzle/0016_fresh_wiccan.sql +1 -0
- package/drizzle/0017_amusing_james_howlett.sql +28 -0
- package/drizzle/0018_happy_hairball.sql +43 -0
- package/drizzle/meta/0012_snapshot.json +1741 -0
- package/drizzle/meta/0013_snapshot.json +1749 -0
- package/drizzle/meta/0014_snapshot.json +1756 -0
- package/drizzle/meta/0015_snapshot.json +1763 -0
- package/drizzle/meta/0016_snapshot.json +1770 -0
- package/drizzle/meta/0017_snapshot.json +1956 -0
- package/drizzle/meta/0018_snapshot.json +2280 -0
- package/drizzle/meta/_journal.json +49 -0
- package/package.json +2 -1
- package/web/assets/index-C_DsRKCc.css +1 -0
- package/web/assets/index-DbKDW1xS.js +413 -0
- package/web/assets/notes-graph.worker-DaVQvftJ.js +1 -0
- package/web/assets/render.worker-BAfybD27.js +416 -0
- package/web/index.html +2 -2
- package/web/assets/index-BfT-sp3_.js +0 -406
- package/web/assets/index-FIC4B_yh.css +0 -1
- package/web/assets/render.worker-Bw6rO7Qu.js +0 -413
|
@@ -0,0 +1,1203 @@
|
|
|
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 MAX_INTERVIEW_CONTEXT_CHARS = 2e3;
|
|
50
|
+
var InterviewContextSpec = z.object({
|
|
51
|
+
question: z.string().trim().min(1).max(300).describe(`The question, e.g. "Anything else you'd like us to know about what you already understand or what you want to explore?"`)
|
|
52
|
+
}).strict();
|
|
53
|
+
var InterviewContextAnswer = z.union([
|
|
54
|
+
z.object({ text: z.string().trim().max(MAX_INTERVIEW_CONTEXT_CHARS) }).strict(),
|
|
55
|
+
z.object({ skipped: z.literal(true) }).strict()
|
|
56
|
+
]);
|
|
57
|
+
var InterviewContextGrade = z.object({ result: z.enum(["answered", "skipped"]) }).strict();
|
|
58
|
+
var gradeInterviewContext = (answer) => ({
|
|
59
|
+
result: "text" in answer && answer.text.length > 0 ? "answered" : "skipped"
|
|
60
|
+
});
|
|
61
|
+
var KnownSource = z.enum(["memory", "test", "guess"]);
|
|
62
|
+
var SyllabusTopicInput = z.object({
|
|
63
|
+
title: z.string().trim().min(1).max(120),
|
|
64
|
+
summary: z.string().trim().min(1).max(400).describe("What the lesson on this topic will cover, in one or two sentences."),
|
|
65
|
+
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".'),
|
|
66
|
+
requestedByLearner: z.boolean().describe("True if the learner explicitly asked for this topic. Such topics are never removed automatically."),
|
|
67
|
+
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.")
|
|
68
|
+
}).strict();
|
|
69
|
+
var courseIcons = [
|
|
70
|
+
"sigma",
|
|
71
|
+
"calculator",
|
|
72
|
+
"code",
|
|
73
|
+
"terminal",
|
|
74
|
+
"cpu",
|
|
75
|
+
"database",
|
|
76
|
+
"network",
|
|
77
|
+
"shield",
|
|
78
|
+
"flask-conical",
|
|
79
|
+
"atom",
|
|
80
|
+
"dna",
|
|
81
|
+
"leaf",
|
|
82
|
+
"telescope",
|
|
83
|
+
"globe",
|
|
84
|
+
"landmark",
|
|
85
|
+
"book-open",
|
|
86
|
+
"pen-tool",
|
|
87
|
+
"languages",
|
|
88
|
+
"music",
|
|
89
|
+
"palette",
|
|
90
|
+
"camera",
|
|
91
|
+
"brain",
|
|
92
|
+
"users",
|
|
93
|
+
"chart-line",
|
|
94
|
+
"briefcase",
|
|
95
|
+
"scale",
|
|
96
|
+
"stethoscope",
|
|
97
|
+
"heart-pulse",
|
|
98
|
+
"wrench",
|
|
99
|
+
"dumbbell"
|
|
100
|
+
];
|
|
101
|
+
var CourseIcon = z.enum(courseIcons);
|
|
102
|
+
var COURSE_TITLE_MAX = 60;
|
|
103
|
+
var SyllabusInput = z.object({
|
|
104
|
+
// Bad values parse as missing rather than failing the call: a syllabus is worth more than its label (#58).
|
|
105
|
+
title: z.string().trim().min(1).max(COURSE_TITLE_MAX).optional().catch(void 0).describe('A short name for the course, 2-5 words, shown in the sidebar, e.g. "Discrete Math: Induction". Name what the syllabus covers, not the request.'),
|
|
106
|
+
icon: CourseIcon.optional().catch(void 0).describe("The subject icon that best fits the course: sigma = maths, calculator = arithmetic or accounting, code/terminal = programming, cpu = hardware, flask-conical = chemistry, atom = physics, dna = biology, leaf = ecology, telescope = astronomy, globe = geography, landmark = history, book-open = literature, pen-tool = writing, languages = languages, palette = art, brain = psychology, users = sociology, chart-line = economics or statistics, briefcase = business, scale = law, stethoscope/heart-pulse = medicine, wrench = engineering, dumbbell = sport."),
|
|
107
|
+
topics: z.array(SyllabusTopicInput).min(1).max(20).describe("The ordered topics, first to learn first. Each topic gets one lesson."),
|
|
108
|
+
known: z.array(
|
|
109
|
+
z.object({
|
|
110
|
+
concept: ConceptName,
|
|
111
|
+
source: KnownSource.describe("memory = from their record or memories; test = from this placement interview; guess = your inference"),
|
|
112
|
+
note: z.string().trim().min(1).max(200)
|
|
113
|
+
}).strict()
|
|
114
|
+
).max(20).describe("What the learner already knows or doesn't, each labelled with where that comes from. Shown to the learner.")
|
|
115
|
+
}).strict().superRefine((input, ctx) => {
|
|
116
|
+
const seen = /* @__PURE__ */ new Set();
|
|
117
|
+
input.topics.forEach((topic, i) => {
|
|
118
|
+
const key = topic.title.trim().toLowerCase();
|
|
119
|
+
if (seen.has(key)) ctx.addIssue({ code: "custom", path: ["topics", i, "title"], message: "Topic titles must be distinct" });
|
|
120
|
+
seen.add(key);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
var SyllabusTopic = SyllabusTopicInput.extend({ id: z.string() }).strict();
|
|
124
|
+
var SyllabusView = z.object({
|
|
125
|
+
version: z.number().int().positive(),
|
|
126
|
+
source: z.enum(["interview", "tutor", "adaptive", "undo"]),
|
|
127
|
+
reason: z.string().nullable(),
|
|
128
|
+
changedTopicIds: z.array(z.string()),
|
|
129
|
+
/** Whether the learner can undo this version: an automatic change none of whose new topics has started. */
|
|
130
|
+
canUndo: z.boolean(),
|
|
131
|
+
topics: z.array(SyllabusTopic),
|
|
132
|
+
known: SyllabusInput.shape.known,
|
|
133
|
+
createdAt: z.string().datetime()
|
|
134
|
+
}).strict();
|
|
135
|
+
var CourseStatus = z.enum(["interviewing", "active", "complete"]);
|
|
136
|
+
var CourseView = z.object({
|
|
137
|
+
id: z.string(),
|
|
138
|
+
sessionId: z.string(),
|
|
139
|
+
goal: z.string(),
|
|
140
|
+
status: CourseStatus,
|
|
141
|
+
syllabus: SyllabusView.nullable(),
|
|
142
|
+
/** The tutor's reply that wrote the first syllabus, which ends the placement interview; null if unknown. */
|
|
143
|
+
interviewMessageId: z.string().nullable(),
|
|
144
|
+
createdAt: z.string().datetime()
|
|
145
|
+
}).strict();
|
|
146
|
+
|
|
147
|
+
// ../protocol/src/lesson.ts
|
|
148
|
+
import { z as z2 } from "zod";
|
|
149
|
+
var LessonSectionKind = z2.enum(["prose", "algorithm_trace", "code_walkthrough", "graph", "multiple_choice", "set_diagram", "table", "worked_steps"]);
|
|
150
|
+
var MAX_LESSON_SECTIONS = 10;
|
|
151
|
+
var LessonOutlineInput = z2.object({
|
|
152
|
+
title: z2.string().trim().min(1).max(120),
|
|
153
|
+
sections: z2.array(
|
|
154
|
+
z2.object({
|
|
155
|
+
title: z2.string().trim().min(1).max(120),
|
|
156
|
+
kind: LessonSectionKind.describe("prose = write_lesson_text; multiple_choice = ask_multiple_choice (a check); the others = the matching show_* tool."),
|
|
157
|
+
purpose: z2.string().trim().min(1).max(300).describe("What this section does for the learner, in one sentence.")
|
|
158
|
+
}).strict()
|
|
159
|
+
).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.`)
|
|
160
|
+
}).strict().superRefine((outline, ctx) => {
|
|
161
|
+
if (!outline.sections.some((s) => s.kind === "multiple_choice")) {
|
|
162
|
+
ctx.addIssue({ code: "custom", path: ["sections"], message: "Include at least one multiple_choice check" });
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
var LessonTextInput = z2.object({
|
|
166
|
+
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."),
|
|
167
|
+
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.")
|
|
168
|
+
}).strict();
|
|
169
|
+
var LessonStatus = z2.enum(["generating", "ready", "failed", "finished"]);
|
|
170
|
+
var LessonOutlineView = z2.object({
|
|
171
|
+
title: z2.string(),
|
|
172
|
+
sections: z2.array(z2.object({ title: z2.string(), kind: LessonSectionKind }).strict())
|
|
173
|
+
}).strict();
|
|
174
|
+
var LessonView = z2.object({
|
|
175
|
+
id: z2.string(),
|
|
176
|
+
courseId: z2.string(),
|
|
177
|
+
topicId: z2.string(),
|
|
178
|
+
topicTitle: z2.string(),
|
|
179
|
+
position: z2.number().int().nonnegative(),
|
|
180
|
+
status: LessonStatus,
|
|
181
|
+
version: z2.number().int().positive().nullable(),
|
|
182
|
+
outline: LessonOutlineView.nullable(),
|
|
183
|
+
sections: z2.array(
|
|
184
|
+
z2.discriminatedUnion("kind", [
|
|
185
|
+
z2.object({
|
|
186
|
+
id: z2.string(),
|
|
187
|
+
title: z2.string(),
|
|
188
|
+
kind: z2.literal("prose"),
|
|
189
|
+
markdown: z2.string(),
|
|
190
|
+
/** Earlier sections this one revisits, for links back to exactly what the learner saw. */
|
|
191
|
+
revisits: z2.array(z2.object({ lessonId: z2.string(), sectionId: z2.string(), title: z2.string(), lessonTitle: z2.string() }).strict())
|
|
192
|
+
}).strict(),
|
|
193
|
+
z2.object({ id: z2.string(), title: z2.string(), kind: z2.literal("artifact"), artifact: z2.unknown() }).strict()
|
|
194
|
+
])
|
|
195
|
+
),
|
|
196
|
+
checks: z2.object({ total: z2.number().int().nonnegative(), answered: z2.number().int().nonnegative() }).strict(),
|
|
197
|
+
/** The course's current syllabus version, so a page can notice a change made while it was open. */
|
|
198
|
+
syllabusVersion: z2.number().int().positive().nullable(),
|
|
199
|
+
/** Sections the latest version added or changed, highlighted for the learner, and why. */
|
|
200
|
+
changedSectionIds: z2.array(z2.string()),
|
|
201
|
+
changeReason: z2.string().nullable(),
|
|
202
|
+
/** Whether the learner can finish it now: fully written and every check answered. */
|
|
203
|
+
canFinish: z2.boolean(),
|
|
204
|
+
error: z2.string().nullable(),
|
|
205
|
+
/** A failure the learner fixes elsewhere: "lesson-model" means the lesson model chosen in Settings can't be used. */
|
|
206
|
+
errorAction: z2.enum(["lesson-model"]).nullable(),
|
|
207
|
+
createdAt: z2.string().datetime(),
|
|
208
|
+
finishedAt: z2.string().datetime().nullable()
|
|
209
|
+
}).strict();
|
|
210
|
+
var CourseLessonsView = z2.object({
|
|
211
|
+
topics: z2.array(
|
|
212
|
+
z2.object({
|
|
213
|
+
topicId: z2.string(),
|
|
214
|
+
title: z2.string(),
|
|
215
|
+
lesson: z2.object({ id: z2.string(), status: LessonStatus }).strict().nullable()
|
|
216
|
+
}).strict()
|
|
217
|
+
),
|
|
218
|
+
/** The lesson to show: the first unfinished one, or the last one once all are finished. */
|
|
219
|
+
currentLessonId: z2.string().nullable(),
|
|
220
|
+
/** The next topic without a lesson, if the learner may start it now. */
|
|
221
|
+
nextTopicId: z2.string().nullable()
|
|
222
|
+
}).strict();
|
|
223
|
+
var SectionTitle = z2.string().trim().min(1).max(120);
|
|
224
|
+
var SectionMarkdown = z2.string().trim().min(1).max(6e3);
|
|
225
|
+
var Reason = z2.string().trim().min(1).max(300);
|
|
226
|
+
var ChangeLessonInput = z2.object({
|
|
227
|
+
reason: Reason.describe('What the learner asked for, in a few words, e.g. "Simpler intro with an example".'),
|
|
228
|
+
operations: z2.array(
|
|
229
|
+
z2.discriminatedUnion("op", [
|
|
230
|
+
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)."),
|
|
231
|
+
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."),
|
|
232
|
+
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."),
|
|
233
|
+
z2.object({ op: z2.literal("remove"), sectionId: z2.string().min(1) }).strict(),
|
|
234
|
+
z2.object({ op: z2.literal("move"), sectionId: z2.string().min(1), afterSectionId: z2.string().min(1).nullable() }).strict()
|
|
235
|
+
])
|
|
236
|
+
).min(1).max(10)
|
|
237
|
+
}).strict();
|
|
238
|
+
var ChangeSyllabusInput = z2.object({
|
|
239
|
+
reason: Reason.describe('What the learner asked for, e.g. "Add a topic on vectors before gradients".'),
|
|
240
|
+
operations: z2.array(
|
|
241
|
+
z2.discriminatedUnion("op", [
|
|
242
|
+
z2.object({
|
|
243
|
+
op: z2.literal("insert"),
|
|
244
|
+
afterTopicId: z2.string().min(1).nullable().describe("Insert after this topic; null to insert before the first future topic."),
|
|
245
|
+
title: SectionTitle,
|
|
246
|
+
summary: z2.string().trim().min(1).max(400),
|
|
247
|
+
reason: Reason,
|
|
248
|
+
concepts: z2.array(z2.string().trim().min(1).max(80)).min(1).max(8)
|
|
249
|
+
}).strict(),
|
|
250
|
+
z2.object({ op: z2.literal("edit"), topicId: z2.string().min(1), title: SectionTitle.optional(), summary: z2.string().trim().min(1).max(400).optional() }).strict(),
|
|
251
|
+
z2.object({ op: z2.literal("remove"), topicId: z2.string().min(1) }).strict(),
|
|
252
|
+
z2.object({ op: z2.literal("move"), topicId: z2.string().min(1), afterTopicId: z2.string().min(1).nullable() }).strict()
|
|
253
|
+
])
|
|
254
|
+
).min(1).max(10)
|
|
255
|
+
}).strict();
|
|
256
|
+
var AddToLesson = z2.object({
|
|
257
|
+
messageId: z2.string().min(1).max(128),
|
|
258
|
+
afterSectionId: z2.string().min(1).max(128).nullable(),
|
|
259
|
+
title: SectionTitle
|
|
260
|
+
}).strict();
|
|
261
|
+
var NewTopic = z2.object({
|
|
262
|
+
title: SectionTitle,
|
|
263
|
+
summary: z2.string().trim().min(1).max(400),
|
|
264
|
+
concepts: z2.array(z2.string().trim().min(1).max(80)).min(1).max(8)
|
|
265
|
+
}).strict();
|
|
266
|
+
var AdaptSyllabusInput = z2.object({
|
|
267
|
+
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".'),
|
|
268
|
+
operation: z2.discriminatedUnion("op", [
|
|
269
|
+
NewTopic.extend({ op: z2.literal("insert"), afterTopicId: z2.string().min(1).nullable().describe("null = straight after this lesson's topic") }).strict(),
|
|
270
|
+
z2.object({ op: z2.literal("split"), topicId: z2.string().min(1), into: z2.array(NewTopic).min(2).max(3) }).strict(),
|
|
271
|
+
z2.object({ op: z2.literal("move"), topicId: z2.string().min(1), afterTopicId: z2.string().min(1).nullable() }).strict()
|
|
272
|
+
])
|
|
273
|
+
}).strict();
|
|
274
|
+
|
|
275
|
+
// ../protocol/src/memory.ts
|
|
276
|
+
import { z as z3 } from "zod";
|
|
277
|
+
var MemoryKind = z3.enum(["goal", "preference", "misconception", "known"]);
|
|
278
|
+
var RememberKind = z3.enum(["goal", "preference", "misconception"]);
|
|
279
|
+
var MemoryText = z3.string().trim().min(1).max(300);
|
|
280
|
+
var RememberInput = z3.object({
|
|
281
|
+
kind: RememberKind.describe("goal = what they want to learn or do; preference = how they like to learn; misconception = something they believe that is wrong."),
|
|
282
|
+
text: MemoryText.describe("One short sentence about the learner. Never include the answer to a check they haven't answered."),
|
|
283
|
+
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."),
|
|
284
|
+
replaces: z3.string().min(1).optional().describe("The id of a known memory this one corrects or updates.")
|
|
285
|
+
}).strict().superRefine((input, ctx) => {
|
|
286
|
+
if (input.kind === "misconception" && !input.concept) {
|
|
287
|
+
ctx.addIssue({ code: "custom", path: ["concept"], message: "A misconception needs a concept" });
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
var MemoryBasis = z3.enum(["wrong_answer", "chat", "import"]);
|
|
291
|
+
var MemoryView = z3.object({
|
|
292
|
+
id: z3.string(),
|
|
293
|
+
kind: MemoryKind,
|
|
294
|
+
held: z3.boolean(),
|
|
295
|
+
text: z3.string().nullable(),
|
|
296
|
+
concept: z3.string().nullable(),
|
|
297
|
+
basis: MemoryBasis.nullable(),
|
|
298
|
+
/** For basis `import`, the note it was drawn from. Null otherwise, and while held. */
|
|
299
|
+
source: z3.object({ noteId: z3.string(), importId: z3.string(), importName: z3.string(), path: z3.string(), title: z3.string() }).strict().nullable(),
|
|
300
|
+
createdAt: z3.string().datetime(),
|
|
301
|
+
editedAt: z3.string().datetime().nullable()
|
|
302
|
+
}).strict();
|
|
303
|
+
var MemoryEdit = z3.object({ text: MemoryText }).strict();
|
|
304
|
+
var MemoryBulkDelete = z3.object({ basis: z3.literal("import") }).strict();
|
|
305
|
+
|
|
306
|
+
// ../protocol/src/document.ts
|
|
307
|
+
import { z as z4 } from "zod";
|
|
308
|
+
var MAX_DOCUMENT_BYTES = 25 * 1024 * 1024;
|
|
309
|
+
var DocumentView = z4.object({
|
|
310
|
+
id: z4.string(),
|
|
311
|
+
sessionId: z4.string(),
|
|
312
|
+
messageId: z4.string().nullable(),
|
|
313
|
+
filename: z4.string(),
|
|
314
|
+
kind: z4.enum(["pdf", "pptx"]),
|
|
315
|
+
byteSize: z4.number().int(),
|
|
316
|
+
pageCount: z4.number().int(),
|
|
317
|
+
pagesWithText: z4.number().int(),
|
|
318
|
+
status: z4.literal("ready"),
|
|
319
|
+
createdAt: z4.string().datetime()
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ../protocol/src/knowledge.ts
|
|
323
|
+
import { z as z5 } from "zod";
|
|
324
|
+
var NoteRef = z5.string().regex(/^n\d{1,3}$/);
|
|
325
|
+
var ConceptName2 = z5.string().trim().min(1).max(80);
|
|
326
|
+
var MAX_PROPOSED_CONCEPTS = 30;
|
|
327
|
+
var MAX_PROPOSED_EDGES = 40;
|
|
328
|
+
var MAX_PROPOSED_MEMORIES = 30;
|
|
329
|
+
var ConceptEdgeKind = z5.enum(["prerequisite", "related"]);
|
|
330
|
+
var RecordFromNotesInput = z5.object({
|
|
331
|
+
concepts: z5.array(
|
|
332
|
+
z5.object({
|
|
333
|
+
name: ConceptName2.describe("A name from <existing_concepts> or <vault_tags> when one fits. Otherwise a new name, written as it appears in the notes."),
|
|
334
|
+
notes: z5.array(NoteRef).min(1).max(20).describe("The refs of the notes that cover it.")
|
|
335
|
+
}).strict()
|
|
336
|
+
).max(MAX_PROPOSED_CONCEPTS),
|
|
337
|
+
edges: z5.array(
|
|
338
|
+
z5.object({
|
|
339
|
+
from: ConceptName2,
|
|
340
|
+
to: ConceptName2,
|
|
341
|
+
kind: ConceptEdgeKind.describe("prerequisite = from must be understood before to; related = they're closely linked."),
|
|
342
|
+
note: NoteRef.describe("The ref of the note that shows this link.")
|
|
343
|
+
}).strict()
|
|
344
|
+
).max(MAX_PROPOSED_EDGES).describe("Edges between concepts named in this call or in <existing_concepts>."),
|
|
345
|
+
memories: z5.array(
|
|
346
|
+
z5.object({
|
|
347
|
+
kind: z5.enum(["known", "goal", "misconception"]).describe("known = the notes cover this concept; goal = a goal the notes state; misconception = a wrong belief the notes state."),
|
|
348
|
+
text: MemoryText.describe("One short sentence about the learner."),
|
|
349
|
+
concept: ConceptName2.optional().describe("Required for known and misconception: a concept named in this call or in <existing_concepts>."),
|
|
350
|
+
note: NoteRef.describe("The ref of the note it comes from.")
|
|
351
|
+
}).strict()
|
|
352
|
+
).max(MAX_PROPOSED_MEMORIES)
|
|
353
|
+
}).strict();
|
|
354
|
+
var DistillationStatus = z5.enum(["idle", "queued", "running", "cancelled", "failed"]);
|
|
355
|
+
var DistillationView = z5.object({
|
|
356
|
+
status: DistillationStatus,
|
|
357
|
+
pendingNotes: z5.number().int(),
|
|
358
|
+
groups: z5.number().int(),
|
|
359
|
+
groupsDone: z5.number().int(),
|
|
360
|
+
error: z5.string().nullable(),
|
|
361
|
+
/** Concepts and memories drawn from this import's notes so far. */
|
|
362
|
+
concepts: z5.number().int(),
|
|
363
|
+
memories: z5.number().int()
|
|
364
|
+
}).strict();
|
|
365
|
+
var ConceptGraph = z5.object({
|
|
366
|
+
concepts: z5.array(z5.object({ id: z5.string(), name: z5.string(), notes: z5.array(z5.string()) }).strict()),
|
|
367
|
+
edges: z5.array(z5.object({ from: z5.string(), to: z5.string(), kind: ConceptEdgeKind, notes: z5.array(z5.string()) }).strict())
|
|
368
|
+
}).strict();
|
|
369
|
+
|
|
370
|
+
// ../protocol/src/vault.ts
|
|
371
|
+
import { z as z6 } from "zod";
|
|
372
|
+
var MAX_VAULT_FILES = 1e4;
|
|
373
|
+
var MAX_NOTE_CHARS = 1e6;
|
|
374
|
+
var MAX_VAULT_BYTES = 64 * 1024 * 1024;
|
|
375
|
+
var MAX_PATH_CHARS = 512;
|
|
376
|
+
var VaultFile = z6.object({
|
|
377
|
+
/** The file's path inside the vault, with `/` between folders, e.g. `Maths/Recursion.md`. */
|
|
378
|
+
path: z6.string().min(1).max(MAX_PATH_CHARS),
|
|
379
|
+
text: z6.string().max(MAX_NOTE_CHARS)
|
|
380
|
+
}).strict();
|
|
381
|
+
var VaultFiles = z6.array(VaultFile).max(MAX_VAULT_FILES);
|
|
382
|
+
var VaultName = z6.string().trim().min(1).max(120);
|
|
383
|
+
var VaultImportInput = z6.object({ name: VaultName, files: VaultFiles }).strict();
|
|
384
|
+
var VaultSnapshotInput = z6.object({ files: VaultFiles }).strict();
|
|
385
|
+
var VaultImportView = z6.object({
|
|
386
|
+
id: z6.string(),
|
|
387
|
+
name: z6.string(),
|
|
388
|
+
source: z6.literal("obsidian"),
|
|
389
|
+
noteCount: z6.number().int(),
|
|
390
|
+
createdAt: z6.string().datetime(),
|
|
391
|
+
updatedAt: z6.string().datetime(),
|
|
392
|
+
/** Distilling its notes into concepts and memories, which starts after every import (ADR-014). */
|
|
393
|
+
distillation: DistillationView
|
|
394
|
+
}).strict();
|
|
395
|
+
var SkipReason = z6.enum(["not_markdown", "hidden", "bad_path", "duplicate", "too_long", "symlink", "generated"]);
|
|
396
|
+
var VaultImportResult = z6.object({
|
|
397
|
+
import: VaultImportView,
|
|
398
|
+
added: z6.number().int(),
|
|
399
|
+
updated: z6.number().int(),
|
|
400
|
+
removed: z6.number().int(),
|
|
401
|
+
unchanged: z6.number().int(),
|
|
402
|
+
skippedCount: z6.number().int(),
|
|
403
|
+
skipped: z6.array(z6.object({ path: z6.string(), reason: SkipReason }).strict()),
|
|
404
|
+
/** Links or tags left out because a note or the vault had more than the limit. */
|
|
405
|
+
truncated: z6.boolean()
|
|
406
|
+
}).strict();
|
|
407
|
+
var NoteView = z6.object({
|
|
408
|
+
id: z6.string(),
|
|
409
|
+
importId: z6.string(),
|
|
410
|
+
path: z6.string(),
|
|
411
|
+
title: z6.string(),
|
|
412
|
+
aliases: z6.array(z6.string()),
|
|
413
|
+
tags: z6.array(z6.string()),
|
|
414
|
+
body: z6.string(),
|
|
415
|
+
updatedAt: z6.string().datetime()
|
|
416
|
+
}).strict();
|
|
417
|
+
var NoteGraph = z6.object({
|
|
418
|
+
notes: z6.array(z6.object({ id: z6.string(), path: z6.string(), title: z6.string(), tags: z6.array(z6.string()) }).strict()),
|
|
419
|
+
links: z6.array(z6.object({ from: z6.string(), to: z6.string().nullable(), target: z6.string(), kind: z6.enum(["link", "embed"]) }).strict())
|
|
420
|
+
}).strict();
|
|
421
|
+
var WHOLE_GRAPH_NOTES = 500;
|
|
422
|
+
var MAX_GRAPH_VIEW_NOTES = 500;
|
|
423
|
+
var MAX_GRAPH_VIEW_NODES = 1e3;
|
|
424
|
+
var MAX_GRAPH_VIEW_EDGES = 5e3;
|
|
425
|
+
var MAX_GRAPH_FACETS = 200;
|
|
426
|
+
var NoteGraphViewQuery = z6.object({
|
|
427
|
+
/** `auto` draws the whole graph when at most WHOLE_GRAPH_NOTES notes match, and the local graph otherwise. */
|
|
428
|
+
mode: z6.enum(["auto", "local"]).default("auto"),
|
|
429
|
+
/** The note the local graph is drawn around. Defaults to the matching note with the most connections. */
|
|
430
|
+
focus: z6.string().max(64).optional(),
|
|
431
|
+
/** How many hops from the focus the local graph reaches. Sharing a tag or concept is one hop, as a link is. */
|
|
432
|
+
depth: z6.coerce.number().int().min(1).max(3).default(2),
|
|
433
|
+
/** Only notes carrying this tag, or one nested under it (`maths` matches `maths/algebra`). */
|
|
434
|
+
tag: z6.string().max(200).optional(),
|
|
435
|
+
/** Only notes in this folder or below it, without a trailing `/`. */
|
|
436
|
+
folder: z6.string().max(512).optional()
|
|
437
|
+
}).strict();
|
|
438
|
+
var NoteGraphNodeKind = z6.enum(["note", "ghost", "tag", "concept"]);
|
|
439
|
+
var NoteGraphEdgeKind = z6.enum(["link", "tag", "concept", "prerequisite", "related"]);
|
|
440
|
+
var NoteGraphView = z6.object({
|
|
441
|
+
mode: z6.enum(["whole", "local"]),
|
|
442
|
+
focus: z6.string().nullable(),
|
|
443
|
+
depth: z6.number().int(),
|
|
444
|
+
totalNotes: z6.number().int(),
|
|
445
|
+
/** Notes matching the filters, drawn or not. */
|
|
446
|
+
matchingNotes: z6.number().int(),
|
|
447
|
+
/** Whether the limits left matching nodes or edges out of the drawing. */
|
|
448
|
+
truncated: z6.boolean(),
|
|
449
|
+
nodes: z6.array(
|
|
450
|
+
z6.object({
|
|
451
|
+
id: z6.string(),
|
|
452
|
+
kind: NoteGraphNodeKind,
|
|
453
|
+
label: z6.string(),
|
|
454
|
+
path: z6.string().optional(),
|
|
455
|
+
notes: z6.number().int().optional(),
|
|
456
|
+
hops: z6.number().int().optional()
|
|
457
|
+
}).strict()
|
|
458
|
+
),
|
|
459
|
+
edges: z6.array(z6.object({ from: z6.string(), to: z6.string(), kind: NoteGraphEdgeKind }).strict()),
|
|
460
|
+
tags: z6.array(z6.object({ name: z6.string(), notes: z6.number().int() }).strict()),
|
|
461
|
+
folders: z6.array(z6.object({ path: z6.string(), notes: z6.number().int() }).strict())
|
|
462
|
+
}).strict();
|
|
463
|
+
var NoteSummary = z6.object({ id: z6.string(), title: z6.string(), path: z6.string() }).strict();
|
|
464
|
+
|
|
465
|
+
// ../protocol/src/index.ts
|
|
466
|
+
import { z as z15 } from "zod";
|
|
467
|
+
|
|
468
|
+
// ../protocol/src/artifact-math-input.ts
|
|
469
|
+
import "zod";
|
|
470
|
+
|
|
471
|
+
// ../protocol/src/math-text.ts
|
|
472
|
+
var isSpace = (char) => char !== void 0 && /\s/.test(char);
|
|
473
|
+
var isDigit = (char) => char !== void 0 && char >= "0" && char <= "9";
|
|
474
|
+
function splitMath(source) {
|
|
475
|
+
const pieces = [];
|
|
476
|
+
let literal = "";
|
|
477
|
+
let i = 0;
|
|
478
|
+
while (i < source.length) {
|
|
479
|
+
const char = source[i];
|
|
480
|
+
if (char === "\\" && source[i + 1] === "$") {
|
|
481
|
+
literal += "$";
|
|
482
|
+
i += 2;
|
|
483
|
+
} else if (char !== "$") {
|
|
484
|
+
literal += char;
|
|
485
|
+
i += 1;
|
|
486
|
+
} else if (source[i + 1] === "$") {
|
|
487
|
+
while (source[i] === "$") {
|
|
488
|
+
literal += "$";
|
|
489
|
+
i += 1;
|
|
490
|
+
}
|
|
491
|
+
} else {
|
|
492
|
+
const close = closingDollar(source, i);
|
|
493
|
+
if (close === void 0) {
|
|
494
|
+
literal += "$";
|
|
495
|
+
i += 1;
|
|
496
|
+
} else {
|
|
497
|
+
if (literal) pieces.push({ text: literal });
|
|
498
|
+
literal = "";
|
|
499
|
+
pieces.push({ formula: source.slice(i + 1, close) });
|
|
500
|
+
i = close + 1;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (literal) pieces.push({ text: literal });
|
|
505
|
+
return pieces;
|
|
506
|
+
}
|
|
507
|
+
function closingDollar(source, open) {
|
|
508
|
+
let close = open + 1;
|
|
509
|
+
while (close < source.length && source[close] !== "$") {
|
|
510
|
+
close += source[close] === "\\" && (source[close + 1] === "$" || source[close + 1] === "\\") ? 2 : 1;
|
|
511
|
+
}
|
|
512
|
+
if (close >= source.length || close === open + 1 || source[close + 1] === "$") return void 0;
|
|
513
|
+
if (isSpace(source[open + 1]) || isSpace(source[close - 1]) || isDigit(source[close + 1])) return void 0;
|
|
514
|
+
return /`|\n\s*\n/.test(source.slice(open, close)) ? void 0 : close;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ../protocol/src/artifact-math-input.ts
|
|
518
|
+
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.`;
|
|
519
|
+
function checkMathText(value, path, ctx) {
|
|
520
|
+
if (typeof value === "string" && splitMath(value).some((piece) => "text" in piece && /\\[a-zA-Z]{2,}/.test(piece.text))) {
|
|
521
|
+
ctx.addIssue({ code: "custom", path, message: REPAIR });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function artifactMathInput(schema, fields, extra) {
|
|
525
|
+
return schema.superRefine((spec, ctx) => {
|
|
526
|
+
const visit = (value, parts, path) => {
|
|
527
|
+
if (parts.length === 0) return checkMathText(value, path, ctx);
|
|
528
|
+
const [key, ...rest] = parts;
|
|
529
|
+
if (key === "*" && Array.isArray(value)) value.forEach((item, i) => visit(item, rest, [...path, i]));
|
|
530
|
+
else if (value && typeof value === "object" && key !== void 0) visit(value[key], rest, [...path, key]);
|
|
531
|
+
};
|
|
532
|
+
for (const field of fields) visit(spec, field.split("."), []);
|
|
533
|
+
extra?.(spec, ctx);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// ../protocol/src/algorithm-trace.ts
|
|
538
|
+
import { z as z8 } from "zod";
|
|
539
|
+
var MAX_VALUES = 64;
|
|
540
|
+
var MAX_STEPS = 200;
|
|
541
|
+
var MAX_CODE_LINES = 40;
|
|
542
|
+
var MAX_CODE_LINE_LENGTH = 120;
|
|
543
|
+
var MAX_CODE_CHARS = 4e3;
|
|
544
|
+
function codeLines(source) {
|
|
545
|
+
return source.replace(/\r\n?/g, "\n").replace(/\n$/, "").split("\n");
|
|
546
|
+
}
|
|
547
|
+
var Label = z8.string().trim().min(1).max(40);
|
|
548
|
+
var Cell = z8.union([z8.number(), z8.string().max(24)]);
|
|
549
|
+
var Index = z8.number().int().nonnegative();
|
|
550
|
+
var TracePointer = z8.object({
|
|
551
|
+
name: Label.describe('Pointer label shown under the cell, e.g. "left", "right", "mid", "i".'),
|
|
552
|
+
index: Index.describe("0-based index into the sequence as it is at this step.")
|
|
553
|
+
}).strict();
|
|
554
|
+
var TraceRange = z8.object({
|
|
555
|
+
start: Index.describe("0-based start index, inclusive, within the sequence as it is at this step."),
|
|
556
|
+
end: Index.describe("0-based end index, inclusive. Must be >= start and within the sequence."),
|
|
557
|
+
label: Label.optional().describe('Optional label, e.g. "window".'),
|
|
558
|
+
tone: z8.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished/sorted, muted = ruled out. Defaults to active.")
|
|
559
|
+
}).strict();
|
|
560
|
+
var TraceVariable = z8.object({
|
|
561
|
+
name: Label,
|
|
562
|
+
value: z8.union([z8.number(), z8.string().max(80), z8.boolean()])
|
|
563
|
+
}).strict();
|
|
564
|
+
var TraceCode = z8.object({
|
|
565
|
+
language: z8.string().trim().min(1).max(30).describe('The language the code is written in, e.g. "Python", "TypeScript", "Java" or "pseudocode". Shown as a label.'),
|
|
566
|
+
source: z8.string().min(1).max(MAX_CODE_CHARS).describe(
|
|
567
|
+
`The code, as plain text with newlines and its real indentation: at most ${MAX_CODE_LINES} lines of at most ${MAX_CODE_LINE_LENGTH} characters. Line 1 is the first line. No Markdown fences.`
|
|
568
|
+
)
|
|
569
|
+
}).strict().superRefine((code, ctx) => {
|
|
570
|
+
const lines = codeLines(code.source);
|
|
571
|
+
if (lines.every((line) => line.trim() === "")) {
|
|
572
|
+
ctx.addIssue({ code: "custom", path: ["source"], message: "source has no code" });
|
|
573
|
+
}
|
|
574
|
+
if (lines.length > MAX_CODE_LINES) {
|
|
575
|
+
ctx.addIssue({ code: "custom", path: ["source"], message: `source has ${lines.length} lines; at most ${MAX_CODE_LINES} are allowed` });
|
|
576
|
+
}
|
|
577
|
+
const long = lines.findIndex((line) => line.length > MAX_CODE_LINE_LENGTH);
|
|
578
|
+
if (long >= 0) {
|
|
579
|
+
ctx.addIssue({ code: "custom", path: ["source"], message: `line ${long + 1} is longer than ${MAX_CODE_LINE_LENGTH} characters` });
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
var TraceStep = z8.object({
|
|
583
|
+
explanation: z8.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
|
|
584
|
+
values: z8.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."),
|
|
585
|
+
pointers: z8.array(TracePointer).max(8).optional().describe("All pointers to show at this step. Not carried over from earlier steps: repeat any that still apply."),
|
|
586
|
+
ranges: z8.array(TraceRange).max(8).optional().describe("All highlighted ranges at this step. Not carried over from earlier steps."),
|
|
587
|
+
variables: z8.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."),
|
|
588
|
+
lines: z8.array(z8.number().int().positive()).max(MAX_CODE_LINES).optional().describe(
|
|
589
|
+
"Only with code: the 1-based line numbers in code.source this step is running, highlighted beside the values. Not carried over from earlier steps; omit or leave empty to highlight none."
|
|
590
|
+
)
|
|
591
|
+
}).strict();
|
|
592
|
+
var AlgorithmTraceSpec = z8.object({
|
|
593
|
+
title: z8.string().trim().min(1).max(120),
|
|
594
|
+
values: z8.array(Cell).min(1).max(MAX_VALUES).describe("The input sequence before the first step."),
|
|
595
|
+
code: TraceCode.optional().describe(
|
|
596
|
+
"Optional source code shown beside the values, with each step's `lines` highlighted. Include it only when the code itself is the point."
|
|
597
|
+
),
|
|
598
|
+
steps: z8.array(TraceStep).min(1).max(MAX_STEPS)
|
|
599
|
+
}).strict().superRefine((spec, ctx) => {
|
|
600
|
+
let length = spec.values.length;
|
|
601
|
+
const codeLength = spec.code ? codeLines(spec.code.source).length : 0;
|
|
602
|
+
spec.steps.forEach((step, i) => {
|
|
603
|
+
if (step.lines && !spec.code) {
|
|
604
|
+
ctx.addIssue({ code: "custom", path: ["steps", i, "lines"], message: "lines need code: add code, or remove lines" });
|
|
605
|
+
} else {
|
|
606
|
+
step.lines?.forEach((line, j) => {
|
|
607
|
+
if (line > codeLength) {
|
|
608
|
+
ctx.addIssue({
|
|
609
|
+
code: "custom",
|
|
610
|
+
path: ["steps", i, "lines", j],
|
|
611
|
+
message: `line ${line} is outside the code (${codeLength} lines)`
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
if (step.values) length = step.values.length;
|
|
617
|
+
step.pointers?.forEach((p, j) => {
|
|
618
|
+
if (p.index >= length) {
|
|
619
|
+
ctx.addIssue({
|
|
620
|
+
code: "custom",
|
|
621
|
+
path: ["steps", i, "pointers", j, "index"],
|
|
622
|
+
message: `index ${p.index} is outside the sequence (length ${length})`
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
step.ranges?.forEach((r, j) => {
|
|
627
|
+
if (r.end >= length || r.start > r.end) {
|
|
628
|
+
ctx.addIssue({
|
|
629
|
+
code: "custom",
|
|
630
|
+
path: ["steps", i, "ranges", j],
|
|
631
|
+
message: `range ${r.start}..${r.end} is invalid for a sequence of length ${length}`
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// ../protocol/src/code-walkthrough.ts
|
|
639
|
+
import { z as z9 } from "zod";
|
|
640
|
+
var MAX_WALKTHROUGH_STEPS = 200;
|
|
641
|
+
var MAX_WALKTHROUGH_VARIABLES = 12;
|
|
642
|
+
var MAX_WALKTHROUGH_OUTPUT = 4e3;
|
|
643
|
+
var CodeWalkthroughStep = z9.object({
|
|
644
|
+
explanation: z9.string().trim().min(1).max(500).describe("What happens at this step and why, in one or two sentences."),
|
|
645
|
+
label: z9.string().trim().min(1).max(80).optional().describe('Optional short name for the step, e.g. "Initial render", "Click handler", "Render 2".'),
|
|
646
|
+
lines: z9.array(z9.number().int().positive()).max(MAX_CODE_LINES).optional().describe("The 1-based line numbers in code.source this step is at. Not carried over: omit or leave empty to highlight none."),
|
|
647
|
+
variables: z9.array(TraceVariable).max(MAX_WALKTHROUGH_VARIABLES).describe(
|
|
648
|
+
'All the state visible at this step, each name once, e.g. "n", "render.count", "handler.count", "queued update". Not carried over: list everything that still applies, or [] for none. Values are plain text, numbers or booleans; write undefined, null or a short object as a string.'
|
|
649
|
+
),
|
|
650
|
+
output: z9.string().max(MAX_WALKTHROUGH_OUTPUT).describe(
|
|
651
|
+
'Everything visible as output at this step, as plain text, e.g. printed lines or what the page shows ("Count: 0"). Not carried over: repeat earlier output that is still visible, or "" for none.'
|
|
652
|
+
)
|
|
653
|
+
}).strict();
|
|
654
|
+
var CodeWalkthroughSpec = z9.object({
|
|
655
|
+
title: z9.string().trim().min(1).max(120),
|
|
656
|
+
code: TraceCode.describe("The source shown on every step. It stays the same across steps."),
|
|
657
|
+
steps: z9.array(CodeWalkthroughStep).min(1).max(MAX_WALKTHROUGH_STEPS)
|
|
658
|
+
}).strict().superRefine((spec, ctx) => {
|
|
659
|
+
const codeLength = codeLines(spec.code.source).length;
|
|
660
|
+
spec.steps.forEach((step, i) => {
|
|
661
|
+
step.lines?.forEach((line, j) => {
|
|
662
|
+
if (line > codeLength) {
|
|
663
|
+
ctx.addIssue({ code: "custom", path: ["steps", i, "lines", j], message: `line ${line} is outside the code (${codeLength} lines)` });
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
const seen = /* @__PURE__ */ new Set();
|
|
667
|
+
step.variables.forEach((variable, j) => {
|
|
668
|
+
if (seen.has(variable.name)) {
|
|
669
|
+
ctx.addIssue({ code: "custom", path: ["steps", i, "variables", j, "name"], message: `variable "${variable.name}" appears twice in this step` });
|
|
670
|
+
}
|
|
671
|
+
seen.add(variable.name);
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
// ../protocol/src/graph.ts
|
|
677
|
+
import { z as z10 } from "zod";
|
|
678
|
+
var MAX_NODES = 60;
|
|
679
|
+
var MAX_EDGES = 200;
|
|
680
|
+
var MAX_STEPS2 = 200;
|
|
681
|
+
var Id = z10.string().trim().min(1).max(24);
|
|
682
|
+
var Text = z10.string().trim().min(1).max(24);
|
|
683
|
+
var GraphTone = z10.enum(["active", "done", "muted"]);
|
|
684
|
+
var ToneField = GraphTone.optional().describe(
|
|
685
|
+
"active = current focus, done = finished/visited, muted = ruled out. Defaults to active."
|
|
686
|
+
);
|
|
687
|
+
var GraphNode = z10.object({
|
|
688
|
+
id: Id.describe("Unique id, used by edges and steps. Shown on the node if it has no label."),
|
|
689
|
+
label: Text.optional().describe("Short text on the node. Only $...$ is a formula, e.g. $v_1$.")
|
|
690
|
+
}).strict();
|
|
691
|
+
var GraphEdge = z10.object({
|
|
692
|
+
from: Id.describe("Id of a node. In a tree, the parent."),
|
|
693
|
+
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`."),
|
|
694
|
+
side: z10.enum(["left", "right"]).optional().describe(
|
|
695
|
+
"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."
|
|
696
|
+
),
|
|
697
|
+
weight: z10.number().optional().describe("Numeric weight shown on the edge. Give a weight or a label, not both."),
|
|
698
|
+
label: Text.optional().describe("Text shown on the edge. Only $...$ is a formula.")
|
|
699
|
+
}).strict();
|
|
700
|
+
var GraphNodeState = z10.object({ id: Id.describe("Id of a node."), tone: ToneField }).strict();
|
|
701
|
+
var GraphEdgeState = z10.object({
|
|
702
|
+
from: Id,
|
|
703
|
+
to: Id,
|
|
704
|
+
nth: z10.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`."),
|
|
705
|
+
tone: ToneField
|
|
706
|
+
}).strict().describe("An edge of the graph. In an undirected graph, from and to may be in either order.");
|
|
707
|
+
var GraphStep = z10.object({
|
|
708
|
+
explanation: z10.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
|
|
709
|
+
nodeStates: z10.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."),
|
|
710
|
+
edgeStates: z10.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."),
|
|
711
|
+
variables: z10.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.")
|
|
712
|
+
}).strict();
|
|
713
|
+
var pairKey = (from, to, directed) => JSON.stringify(directed || from <= to ? [from, to] : [to, from]);
|
|
714
|
+
function graphEdgeLookup(spec) {
|
|
715
|
+
const byPair = /* @__PURE__ */ new Map();
|
|
716
|
+
spec.edges.forEach((edge, i) => {
|
|
717
|
+
const key = pairKey(edge.from, edge.to, spec.directed);
|
|
718
|
+
const indices = byPair.get(key);
|
|
719
|
+
if (indices) indices.push(i);
|
|
720
|
+
else byPair.set(key, [i]);
|
|
721
|
+
});
|
|
722
|
+
return (ref) => {
|
|
723
|
+
const name = `${ref.from} ${spec.directed ? "->" : "--"} ${ref.to}`;
|
|
724
|
+
const indices = byPair.get(pairKey(ref.from, ref.to, spec.directed));
|
|
725
|
+
if (!indices) return { error: `there is no edge ${name}` };
|
|
726
|
+
if (ref.nth === void 0 && indices.length > 1) return { error: `${indices.length} edges match ${name}: set nth to pick one` };
|
|
727
|
+
const index = indices[ref.nth ?? 0];
|
|
728
|
+
return index === void 0 ? { error: `nth ${ref.nth} is out of range: ${indices.length} edges match ${name}` } : { index };
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function graphTreeShape(spec) {
|
|
732
|
+
if (spec.edges.length !== spec.nodes.length - 1) return void 0;
|
|
733
|
+
const ids = spec.nodes.map((node) => node.id);
|
|
734
|
+
const adjacent = new Map(ids.map((id) => [id, []]));
|
|
735
|
+
for (const { from, to } of spec.edges) {
|
|
736
|
+
adjacent.get(from).push(to);
|
|
737
|
+
if (!spec.directed && from !== to) adjacent.get(to).push(from);
|
|
738
|
+
}
|
|
739
|
+
const roots = spec.directed ? ids.filter((id) => !spec.edges.some((edge) => edge.to === id)) : ids.slice(0, 1);
|
|
740
|
+
const root = roots[0];
|
|
741
|
+
if (roots.length !== 1 || root === void 0) return void 0;
|
|
742
|
+
const children = /* @__PURE__ */ new Map();
|
|
743
|
+
const pending = [root];
|
|
744
|
+
while (pending.length) {
|
|
745
|
+
const id = pending.pop();
|
|
746
|
+
const next = adjacent.get(id).filter((other) => !children.has(other));
|
|
747
|
+
children.set(id, next);
|
|
748
|
+
pending.push(...next);
|
|
749
|
+
}
|
|
750
|
+
return children.size === ids.length ? { root, children } : void 0;
|
|
751
|
+
}
|
|
752
|
+
function checkSides(spec, ctx) {
|
|
753
|
+
const sided = spec.edges.flatMap((edge, i) => edge.side ? [{ edge, side: edge.side, path: ["edges", i, "side"] }] : []);
|
|
754
|
+
const first = sided[0];
|
|
755
|
+
if (!first) return;
|
|
756
|
+
if (spec.kind !== "tree") {
|
|
757
|
+
for (const { path } of sided) ctx.addIssue({ code: "custom", path, message: 'side only applies when kind is "tree": remove it, or set kind' });
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const shape = graphTreeShape(spec);
|
|
761
|
+
if (!shape) {
|
|
762
|
+
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" });
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const sideOf = /* @__PURE__ */ new Map();
|
|
766
|
+
for (const { edge, side, path } of sided) {
|
|
767
|
+
if (shape.children.get(edge.from).includes(edge.to)) sideOf.set(edge.to, side);
|
|
768
|
+
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` });
|
|
769
|
+
}
|
|
770
|
+
for (const [parent, children] of shape.children) {
|
|
771
|
+
const sides = children.flatMap((child) => sideOf.get(child) ?? []);
|
|
772
|
+
if (sides.length > 0 && sides.length < children.length) {
|
|
773
|
+
ctx.addIssue({ code: "custom", path: ["edges"], message: `node ${parent} mixes children with and without a side: give all of them one, or none` });
|
|
774
|
+
}
|
|
775
|
+
for (const side of ["left", "right"]) {
|
|
776
|
+
if (sides.filter((s) => s === side).length > 1) ctx.addIssue({ code: "custom", path: ["edges"], message: `node ${parent} has two ${side} children` });
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
var GraphSpec = z10.object({
|
|
781
|
+
title: z10.string().trim().min(1).max(120),
|
|
782
|
+
directed: z10.boolean().describe("True draws arrowheads from `from` to `to`."),
|
|
783
|
+
kind: z10.enum(["tree", "graph"]).optional().describe(
|
|
784
|
+
"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."
|
|
785
|
+
),
|
|
786
|
+
nodes: z10.array(GraphNode).min(1).max(MAX_NODES),
|
|
787
|
+
edges: z10.array(GraphEdge).max(MAX_EDGES).describe("Self-loops and parallel edges are allowed."),
|
|
788
|
+
steps: z10.array(GraphStep).min(1).max(MAX_STEPS2).optional().describe("Omit to show the graph without stepping through it.")
|
|
789
|
+
}).strict().superRefine((spec, ctx) => {
|
|
790
|
+
const ids = /* @__PURE__ */ new Set();
|
|
791
|
+
spec.nodes.forEach((node, i) => {
|
|
792
|
+
if (ids.has(node.id)) ctx.addIssue({ code: "custom", path: ["nodes", i, "id"], message: `duplicate node id ${node.id}` });
|
|
793
|
+
ids.add(node.id);
|
|
794
|
+
});
|
|
795
|
+
spec.edges.forEach((edge, i) => {
|
|
796
|
+
for (const end of ["from", "to"]) {
|
|
797
|
+
if (!ids.has(edge[end])) ctx.addIssue({ code: "custom", path: ["edges", i, end], message: `no node has id ${edge[end]}` });
|
|
798
|
+
}
|
|
799
|
+
if (edge.weight !== void 0 && edge.label !== void 0) {
|
|
800
|
+
ctx.addIssue({ code: "custom", path: ["edges", i], message: "give a weight or a label, not both" });
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
if (spec.edges.every((edge) => ids.has(edge.from) && ids.has(edge.to))) checkSides(spec, ctx);
|
|
804
|
+
const lookup = graphEdgeLookup(spec);
|
|
805
|
+
spec.steps?.forEach((step, i) => {
|
|
806
|
+
const seenNodes = /* @__PURE__ */ new Set();
|
|
807
|
+
step.nodeStates?.forEach((state, j) => {
|
|
808
|
+
const path = ["steps", i, "nodeStates", j];
|
|
809
|
+
if (!ids.has(state.id)) ctx.addIssue({ code: "custom", path, message: `no node has id ${state.id}` });
|
|
810
|
+
if (seenNodes.has(state.id)) ctx.addIssue({ code: "custom", path, message: `node ${state.id} has two states in one step` });
|
|
811
|
+
seenNodes.add(state.id);
|
|
812
|
+
});
|
|
813
|
+
const seenEdges = /* @__PURE__ */ new Set();
|
|
814
|
+
step.edgeStates?.forEach((state, j) => {
|
|
815
|
+
const path = ["steps", i, "edgeStates", j];
|
|
816
|
+
const found = lookup(state);
|
|
817
|
+
if ("error" in found) return ctx.addIssue({ code: "custom", path, message: found.error });
|
|
818
|
+
if (seenEdges.has(found.index)) ctx.addIssue({ code: "custom", path, message: `edge ${found.index} has two states in one step` });
|
|
819
|
+
seenEdges.add(found.index);
|
|
820
|
+
});
|
|
821
|
+
});
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// ../protocol/src/multiple-choice.ts
|
|
825
|
+
import { z as z11 } from "zod";
|
|
826
|
+
var MultipleChoiceOption = z11.object({
|
|
827
|
+
text: z11.string().trim().min(1).max(300),
|
|
828
|
+
feedback: z11.string().trim().min(1).max(500).optional().describe("Shown if the learner picks this option: why it is right or what misconception it reflects.")
|
|
829
|
+
}).strict();
|
|
830
|
+
var MultipleChoiceSpec = z11.object({
|
|
831
|
+
concept: z11.string().trim().min(1).max(80).describe('Short label for the concept being checked, e.g. "sliding window invariant". Used to track progress.'),
|
|
832
|
+
question: z11.string().trim().min(1).max(1e3),
|
|
833
|
+
options: z11.array(MultipleChoiceOption).min(2).max(6).describe("2-6 options with distinct text."),
|
|
834
|
+
correctOptionIndex: z11.number().int().nonnegative().describe("0-based index of the single correct option; must be less than the number of options."),
|
|
835
|
+
explanation: z11.string().trim().min(1).max(1e3).describe("Shown after answering: why the correct option is correct.")
|
|
836
|
+
}).strict().superRefine((spec, ctx) => {
|
|
837
|
+
if (spec.correctOptionIndex >= spec.options.length) {
|
|
838
|
+
ctx.addIssue({
|
|
839
|
+
code: "custom",
|
|
840
|
+
path: ["correctOptionIndex"],
|
|
841
|
+
message: "correctOptionIndex must point at one of the options"
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
const seen = /* @__PURE__ */ new Map();
|
|
845
|
+
spec.options.forEach((option, i) => {
|
|
846
|
+
const key = option.text.normalize("NFC");
|
|
847
|
+
const first = seen.get(key);
|
|
848
|
+
if (first !== void 0) {
|
|
849
|
+
ctx.addIssue({ code: "custom", path: ["options", i, "text"], message: `duplicates option ${first}` });
|
|
850
|
+
} else {
|
|
851
|
+
seen.set(key, i);
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
var MultipleChoicePublic = z11.object({
|
|
856
|
+
concept: z11.string(),
|
|
857
|
+
question: z11.string(),
|
|
858
|
+
options: z11.array(z11.object({ text: z11.string() }).strict())
|
|
859
|
+
}).strict();
|
|
860
|
+
function toMultipleChoicePublic(spec) {
|
|
861
|
+
return {
|
|
862
|
+
concept: spec.concept,
|
|
863
|
+
question: spec.question,
|
|
864
|
+
options: spec.options.map((o) => ({ text: o.text }))
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
var MultipleChoiceAnswer = z11.object({ optionIndex: z11.number().int().nonnegative() }).strict();
|
|
868
|
+
var MultipleChoiceGrade = z11.object({
|
|
869
|
+
correct: z11.boolean(),
|
|
870
|
+
correctOptionIndex: z11.number().int().nonnegative(),
|
|
871
|
+
explanation: z11.string(),
|
|
872
|
+
feedback: z11.string().optional()
|
|
873
|
+
}).strict();
|
|
874
|
+
function gradeMultipleChoice(spec, answer) {
|
|
875
|
+
const chosen = spec.options[answer.optionIndex];
|
|
876
|
+
if (!chosen) throw new RangeError(`optionIndex ${answer.optionIndex} is not one of the ${spec.options.length} options`);
|
|
877
|
+
return {
|
|
878
|
+
correct: answer.optionIndex === spec.correctOptionIndex,
|
|
879
|
+
correctOptionIndex: spec.correctOptionIndex,
|
|
880
|
+
explanation: spec.explanation,
|
|
881
|
+
...chosen.feedback ? { feedback: chosen.feedback } : {}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// ../protocol/src/set-diagram.ts
|
|
886
|
+
import { z as z12 } from "zod";
|
|
887
|
+
var MAX_SETS = 3;
|
|
888
|
+
var MAX_REGIONS = 8;
|
|
889
|
+
var MAX_ELEMENTS = 30;
|
|
890
|
+
var MAX_STEPS3 = 40;
|
|
891
|
+
var SetId = z12.string().trim().min(1).max(24);
|
|
892
|
+
var ONE_LINE = /^[^\n\r\v\f\u0085\u2028\u2029]*$/;
|
|
893
|
+
var oneLine = (max) => z12.string().trim().min(1).max(max).regex(ONE_LINE, "must not contain line breaks");
|
|
894
|
+
var Element = z12.union([z12.number(), oneLine(24)]);
|
|
895
|
+
function setRegionKey(ids) {
|
|
896
|
+
return JSON.stringify([...ids].sort());
|
|
897
|
+
}
|
|
898
|
+
var RegionIn = z12.array(SetId).max(MAX_SETS);
|
|
899
|
+
var SetDiagramSet = z12.object({
|
|
900
|
+
id: SetId.describe('Short id used to refer to this set, e.g. "a". Unique within the diagram.'),
|
|
901
|
+
label: oneLine(32).describe('Shown next to the circle, e.g. "$A$" or "Multiples of 3", on one line. Only $...$ is a formula.')
|
|
902
|
+
}).strict();
|
|
903
|
+
var SetDiagramRegion = z12.object({
|
|
904
|
+
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.'),
|
|
905
|
+
elements: z12.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.'),
|
|
906
|
+
count: z12.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.")
|
|
907
|
+
}).strict();
|
|
908
|
+
var SetDiagramHighlight = z12.object({
|
|
909
|
+
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."),
|
|
910
|
+
tone: z12.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished, muted = ruled out. Defaults to active.")
|
|
911
|
+
}).strict();
|
|
912
|
+
var SetDiagramStep = z12.object({
|
|
913
|
+
explanation: z12.string().trim().min(1).max(500).describe("What this step shows, in one or two sentences."),
|
|
914
|
+
highlights: z12.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."),
|
|
915
|
+
variables: z12.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.")
|
|
916
|
+
}).strict();
|
|
917
|
+
var SetDiagramSpec = z12.object({
|
|
918
|
+
title: z12.string().trim().min(1).max(120),
|
|
919
|
+
sets: z12.array(SetDiagramSet).min(1).max(MAX_SETS).describe("The circles, 1 to 3."),
|
|
920
|
+
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.'),
|
|
921
|
+
regions: z12.array(SetDiagramRegion).max(MAX_REGIONS).describe("What each region contains, each region at most once."),
|
|
922
|
+
steps: z12.array(SetDiagramStep).min(1).max(MAX_STEPS3).optional().describe("Optional walk through the diagram. Omit for a static diagram.")
|
|
923
|
+
}).strict().superRefine((spec, ctx) => {
|
|
924
|
+
const ids = spec.sets.map((s) => s.id);
|
|
925
|
+
spec.sets.forEach((set, i) => {
|
|
926
|
+
if (ids.indexOf(set.id) !== i) ctx.addIssue({ code: "custom", path: ["sets", i, "id"], message: `duplicate set id "${set.id}"` });
|
|
927
|
+
});
|
|
928
|
+
const checkRegions = (entries, path) => {
|
|
929
|
+
const seen = /* @__PURE__ */ new Set();
|
|
930
|
+
entries.forEach((entry, i) => {
|
|
931
|
+
const at = [...path, i, "in"];
|
|
932
|
+
entry.in.forEach((id, j) => {
|
|
933
|
+
if (!ids.includes(id)) ctx.addIssue({ code: "custom", path: [...at, j], message: `unknown set "${id}"` });
|
|
934
|
+
if (entry.in.indexOf(id) !== j) ctx.addIssue({ code: "custom", path: [...at, j], message: `set "${id}" is named twice` });
|
|
935
|
+
});
|
|
936
|
+
if (entry.in.length === 0 && spec.universe === void 0) {
|
|
937
|
+
ctx.addIssue({ code: "custom", path: at, message: "the region outside every set needs `universe`" });
|
|
938
|
+
}
|
|
939
|
+
const key = setRegionKey(entry.in);
|
|
940
|
+
if (seen.has(key)) ctx.addIssue({ code: "custom", path: at, message: `region ${key} appears more than once` });
|
|
941
|
+
seen.add(key);
|
|
942
|
+
});
|
|
943
|
+
};
|
|
944
|
+
checkRegions(spec.regions, ["regions"]);
|
|
945
|
+
spec.steps?.forEach((step, i) => checkRegions(step.highlights ?? [], ["steps", i, "highlights"]));
|
|
946
|
+
const placed = /* @__PURE__ */ new Set();
|
|
947
|
+
spec.regions.forEach((region, i) => {
|
|
948
|
+
region.elements.forEach((element, j) => {
|
|
949
|
+
if (placed.has(String(element))) {
|
|
950
|
+
ctx.addIssue({ code: "custom", path: ["regions", i, "elements", j], message: `element "${element}" appears more than once; regions don't overlap` });
|
|
951
|
+
}
|
|
952
|
+
placed.add(String(element));
|
|
953
|
+
});
|
|
954
|
+
if (region.count !== void 0 && region.count < region.elements.length) {
|
|
955
|
+
ctx.addIssue({ code: "custom", path: ["regions", i, "count"], message: `count ${region.count} is less than the ${region.elements.length} elements listed` });
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
// ../protocol/src/table.ts
|
|
961
|
+
import { z as z13 } from "zod";
|
|
962
|
+
var MAX_COLUMNS = 16;
|
|
963
|
+
var MAX_ROWS = 64;
|
|
964
|
+
var MAX_STEPS4 = 100;
|
|
965
|
+
var Header = z13.string().trim().min(1).max(80);
|
|
966
|
+
var CellValue = z13.union([z13.number(), z13.boolean(), z13.string().max(120)]);
|
|
967
|
+
var Index2 = z13.number().int().nonnegative();
|
|
968
|
+
var TableHighlight = z13.object({
|
|
969
|
+
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."),
|
|
970
|
+
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."),
|
|
971
|
+
tone: z13.enum(["active", "done", "muted"]).optional().describe("active = current focus, done = finished, muted = ruled out. Defaults to active. Where highlights overlap, the later one wins.")
|
|
972
|
+
}).strict();
|
|
973
|
+
var TableCellChange = z13.object({
|
|
974
|
+
row: Index2.describe("0-based data row, below the number of rows."),
|
|
975
|
+
column: Index2.describe("0-based data column, below the number of columns."),
|
|
976
|
+
value: CellValue.describe("The cell's value from this step on.")
|
|
977
|
+
}).strict();
|
|
978
|
+
var TableStep = z13.object({
|
|
979
|
+
explanation: z13.string().trim().min(1).max(500).describe("What happens in this step, in one or two sentences."),
|
|
980
|
+
highlight: z13.array(TableHighlight).max(32).optional().describe("All cells, rows and columns to highlight at this step. Not carried over from earlier steps."),
|
|
981
|
+
cells: z13.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.')
|
|
982
|
+
}).strict();
|
|
983
|
+
var TableSpec = z13.object({
|
|
984
|
+
title: z13.string().trim().min(1).max(120),
|
|
985
|
+
columns: z13.array(Header).min(1).max(MAX_COLUMNS).describe("Column headers, one per data column. Don't include a header for rowHeaders."),
|
|
986
|
+
rows: z13.array(z13.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.'),
|
|
987
|
+
rowHeaders: z13.array(Header).max(MAX_ROWS).optional().describe("Optional label for each row, e.g. a relation matrix's elements. Exactly one per row."),
|
|
988
|
+
steps: z13.array(TableStep).min(1).max(MAX_STEPS4).optional().describe("Omit for a static table. With steps, the learner steps through them.")
|
|
989
|
+
}).strict().superRefine((spec, ctx) => {
|
|
990
|
+
const rowCount = spec.rows.length;
|
|
991
|
+
const columnCount = spec.columns.length;
|
|
992
|
+
spec.rows.forEach((row, i) => {
|
|
993
|
+
if (row.length !== columnCount) {
|
|
994
|
+
ctx.addIssue({ code: "custom", path: ["rows", i], message: `row has ${row.length} cells but there are ${columnCount} columns` });
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
if (spec.rowHeaders && spec.rowHeaders.length !== rowCount) {
|
|
998
|
+
ctx.addIssue({ code: "custom", path: ["rowHeaders"], message: `${spec.rowHeaders.length} row headers for ${rowCount} rows` });
|
|
999
|
+
}
|
|
1000
|
+
const checkRow = (row, path) => {
|
|
1001
|
+
if (row >= rowCount) ctx.addIssue({ code: "custom", path, message: `row ${row} is outside the table (${rowCount} rows)` });
|
|
1002
|
+
};
|
|
1003
|
+
const checkColumn = (column, path) => {
|
|
1004
|
+
if (column >= columnCount) ctx.addIssue({ code: "custom", path, message: `column ${column} is outside the table (${columnCount} columns)` });
|
|
1005
|
+
};
|
|
1006
|
+
spec.steps?.forEach((step, i) => {
|
|
1007
|
+
step.highlight?.forEach((h, j) => {
|
|
1008
|
+
const path = ["steps", i, "highlight", j];
|
|
1009
|
+
if (h.row === void 0 && h.column === void 0) ctx.addIssue({ code: "custom", path, message: "a highlight needs a row, a column or both" });
|
|
1010
|
+
if (h.row !== void 0) checkRow(h.row, [...path, "row"]);
|
|
1011
|
+
if (h.column !== void 0) checkColumn(h.column, [...path, "column"]);
|
|
1012
|
+
});
|
|
1013
|
+
step.cells?.forEach((c, j) => {
|
|
1014
|
+
checkRow(c.row, ["steps", i, "cells", j, "row"]);
|
|
1015
|
+
checkColumn(c.column, ["steps", i, "cells", j, "column"]);
|
|
1016
|
+
});
|
|
1017
|
+
});
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
// ../protocol/src/worked-steps.ts
|
|
1021
|
+
import { z as z14 } from "zod";
|
|
1022
|
+
var MAX_STEPS5 = 50;
|
|
1023
|
+
var WorkedStep = z14.object({
|
|
1024
|
+
label: z14.string().trim().min(1).max(40).optional().describe('Optional heading for this part of the working, e.g. "Base case", "Inductive step".'),
|
|
1025
|
+
statement: z14.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."),
|
|
1026
|
+
justification: z14.string().trim().min(1).max(500).describe('Why it follows, e.g. "by the inductive hypothesis".')
|
|
1027
|
+
}).strict();
|
|
1028
|
+
var WorkedStepsSpec = z14.object({
|
|
1029
|
+
title: z14.string().trim().min(1).max(120),
|
|
1030
|
+
goal: z14.string().trim().min(1).max(500).optional().describe("Optional statement of what is being shown, e.g. the claim to prove."),
|
|
1031
|
+
steps: z14.array(WorkedStep).min(1).max(MAX_STEPS5)
|
|
1032
|
+
}).strict();
|
|
1033
|
+
|
|
1034
|
+
// ../protocol/src/index.ts
|
|
1035
|
+
var artifactKinds = {
|
|
1036
|
+
algorithm_trace: {
|
|
1037
|
+
version: 1,
|
|
1038
|
+
toolName: "show_algorithm_trace",
|
|
1039
|
+
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. A code pane is optional: add `code` and each step's `lines` only when the code itself is the point, such as how an implementation's lines move the state, and leave it out when the idea matters more than any code. Write that code in the programming language the learner has shown proficiency in according to <learner_memories>; if they show none, use Python or pseudocode. Keep the code short, and highlight the lines each step is running. For code that doesn't move over a sequence, such as a plain function or a React render, use show_code_walkthrough instead of inventing an array.",
|
|
1040
|
+
spec: AlgorithmTraceSpec,
|
|
1041
|
+
input: artifactMathInput(AlgorithmTraceSpec, ["title", "steps.*.explanation"])
|
|
1042
|
+
},
|
|
1043
|
+
code_walkthrough: {
|
|
1044
|
+
version: 1,
|
|
1045
|
+
toolName: "show_code_walkthrough",
|
|
1046
|
+
description: 'Show the learner a step-by-step walkthrough of a short piece of code that isn\'t about a sequence: a plain function\'s parameters, locals and return value, or a React component\'s renders, handlers and state updates. Each step highlights the source lines it is at and gives a complete snapshot of the visible state (`variables`) and the visible output (`output`, plain text such as printed lines or what the page shows, e.g. "Count: 0"); nothing carries over between steps, so repeat whatever still applies and use [] or "" for none. The source stays the same on every step. Use show_algorithm_trace instead for an algorithm moving over an array or other sequence, and show_graph for a component hierarchy. Keep the code short (a few to about 20 lines) and the walkthrough short (roughly 3-12 steps). Write the code in the language the concept belongs to (JSX for React); for a language-neutral idea, use the language the learner knows from <learner_memories>, else Python or pseudocode. The snapshots are your illustration, not a real run, so get them right. For React, keep the state a render or handler sees apart from updates it queues: inside a handler, state still has the value from the render it belongs to (name it, e.g. "handler.count" = 0, with "queued update" = "count + 1"), and the new value and its output appear only at the next render\'s step.',
|
|
1047
|
+
spec: CodeWalkthroughSpec,
|
|
1048
|
+
input: artifactMathInput(CodeWalkthroughSpec, ["title", "steps.*.explanation"])
|
|
1049
|
+
},
|
|
1050
|
+
graph: {
|
|
1051
|
+
version: 1,
|
|
1052
|
+
toolName: "show_graph",
|
|
1053
|
+
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. For a component hierarchy (such as React components), set kind to tree and directed to true, with one node per component instance (distinct ids for two instances of the same component, labelled with the short component name) and one edge from each parent to each child it renders, labelled with the props it passes (e.g. "count" or "onClick"). Use steps to highlight where state is owned and the nodes and edges its value flows through, with variables for simple state such as count = 1. The nodes and edges stay the same on every step: don't add callback edges back up the tree, and don't suggest that a component's output changes just because it re-renders.`,
|
|
1054
|
+
spec: GraphSpec,
|
|
1055
|
+
input: artifactMathInput(GraphSpec, ["title", "nodes.*.label", "edges.*.label", "steps.*.explanation"], (spec, ctx) => {
|
|
1056
|
+
spec.nodes.forEach((node, i) => {
|
|
1057
|
+
if (node.label === void 0) checkMathText(node.id, ["nodes", i, "id"], ctx);
|
|
1058
|
+
});
|
|
1059
|
+
})
|
|
1060
|
+
},
|
|
1061
|
+
interview_context: {
|
|
1062
|
+
version: 1,
|
|
1063
|
+
toolName: "ask_interview_context",
|
|
1064
|
+
description: "Course placement interview only: ask the learner once, as the last question of the interview and in the same reply as the placement questions, whether there is anything else they want you to know about what they already understand or want to explore. They answer in their own words in the UI, or leave it blank; the answer is reported back to you with the placement results. Not graded.",
|
|
1065
|
+
spec: InterviewContextSpec,
|
|
1066
|
+
input: artifactMathInput(InterviewContextSpec, ["question"])
|
|
1067
|
+
},
|
|
1068
|
+
multiple_choice: {
|
|
1069
|
+
version: 1,
|
|
1070
|
+
toolName: "ask_multiple_choice",
|
|
1071
|
+
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. For a code prediction, put the short snippet in a fenced code block in your reply text before this call and ask what it returns, prints or displays; the question and options render maths and plain text only, so never put code fences in them.",
|
|
1072
|
+
spec: MultipleChoiceSpec,
|
|
1073
|
+
input: artifactMathInput(MultipleChoiceSpec, ["question", "options.*.text", "options.*.feedback", "explanation"])
|
|
1074
|
+
},
|
|
1075
|
+
placement_question: {
|
|
1076
|
+
version: 1,
|
|
1077
|
+
toolName: "ask_placement_question",
|
|
1078
|
+
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.`,
|
|
1079
|
+
spec: PlacementQuestionSpec,
|
|
1080
|
+
input: artifactMathInput(PlacementQuestionSpec, ["question", "options.*.text", "explanation"])
|
|
1081
|
+
},
|
|
1082
|
+
set_diagram: {
|
|
1083
|
+
version: 1,
|
|
1084
|
+
toolName: "show_set_diagram",
|
|
1085
|
+
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.",
|
|
1086
|
+
spec: SetDiagramSpec,
|
|
1087
|
+
input: artifactMathInput(SetDiagramSpec, ["title", "universe", "sets.*.label", "regions.*.elements.*", "steps.*.explanation", "steps.*.variables.*.name", "steps.*.variables.*.value"])
|
|
1088
|
+
},
|
|
1089
|
+
table: {
|
|
1090
|
+
version: 1,
|
|
1091
|
+
toolName: "show_table",
|
|
1092
|
+
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.",
|
|
1093
|
+
spec: TableSpec,
|
|
1094
|
+
input: artifactMathInput(TableSpec, ["title", "columns.*", "rowHeaders.*", "rows.*.*", "steps.*.explanation", "steps.*.cells.*.value"])
|
|
1095
|
+
},
|
|
1096
|
+
worked_steps: {
|
|
1097
|
+
version: 1,
|
|
1098
|
+
toolName: "show_worked_steps",
|
|
1099
|
+
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.",
|
|
1100
|
+
spec: WorkedStepsSpec,
|
|
1101
|
+
input: artifactMathInput(WorkedStepsSpec, ["title", "goal", "steps.*.label", "steps.*.statement", "steps.*.justification"])
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
var ArtifactKind = z15.enum(Object.keys(artifactKinds));
|
|
1105
|
+
var ArtifactBase = { id: z15.string(), createdAt: z15.string().datetime() };
|
|
1106
|
+
var MultipleChoiceAttempt = z15.object({ answer: MultipleChoiceAnswer, grade: MultipleChoiceGrade, createdAt: z15.string().datetime() }).strict();
|
|
1107
|
+
var InterviewContextAttempt = z15.object({ answer: InterviewContextAnswer, grade: InterviewContextGrade, createdAt: z15.string().datetime() }).strict();
|
|
1108
|
+
var PlacementAttempt = z15.object({ answer: PlacementAnswer, grade: PlacementGrade, createdAt: z15.string().datetime() }).strict();
|
|
1109
|
+
var ArtifactView = z15.discriminatedUnion("kind", [
|
|
1110
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("algorithm_trace"), version: z15.literal(1), spec: AlgorithmTraceSpec }).strict(),
|
|
1111
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("code_walkthrough"), version: z15.literal(1), spec: CodeWalkthroughSpec }).strict(),
|
|
1112
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("graph"), version: z15.literal(1), spec: GraphSpec }).strict(),
|
|
1113
|
+
z15.object({
|
|
1114
|
+
...ArtifactBase,
|
|
1115
|
+
kind: z15.literal("interview_context"),
|
|
1116
|
+
version: z15.literal(1),
|
|
1117
|
+
spec: InterviewContextSpec,
|
|
1118
|
+
latestAttempt: InterviewContextAttempt.optional()
|
|
1119
|
+
}).strict(),
|
|
1120
|
+
z15.object({
|
|
1121
|
+
...ArtifactBase,
|
|
1122
|
+
kind: z15.literal("multiple_choice"),
|
|
1123
|
+
version: z15.literal(1),
|
|
1124
|
+
spec: MultipleChoicePublic,
|
|
1125
|
+
latestAttempt: MultipleChoiceAttempt.optional()
|
|
1126
|
+
}).strict(),
|
|
1127
|
+
z15.object({
|
|
1128
|
+
...ArtifactBase,
|
|
1129
|
+
kind: z15.literal("placement_question"),
|
|
1130
|
+
version: z15.literal(1),
|
|
1131
|
+
spec: PlacementQuestionPublic,
|
|
1132
|
+
latestAttempt: PlacementAttempt.optional()
|
|
1133
|
+
}).strict(),
|
|
1134
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("set_diagram"), version: z15.literal(1), spec: SetDiagramSpec }).strict(),
|
|
1135
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("table"), version: z15.literal(1), spec: TableSpec }).strict(),
|
|
1136
|
+
z15.object({ ...ArtifactBase, kind: z15.literal("worked_steps"), version: z15.literal(1), spec: WorkedStepsSpec }).strict()
|
|
1137
|
+
]);
|
|
1138
|
+
var CHATGPT_USAGE_LIMIT_ERROR = "ChatGPT usage limit reached. Review your plan or this app's limit in ChatGPT settings.";
|
|
1139
|
+
|
|
1140
|
+
export {
|
|
1141
|
+
AlgorithmTraceSpec,
|
|
1142
|
+
CodeWalkthroughSpec,
|
|
1143
|
+
StartCourse,
|
|
1144
|
+
PlacementQuestionSpec,
|
|
1145
|
+
toPlacementQuestionPublic,
|
|
1146
|
+
PlacementAnswer,
|
|
1147
|
+
gradePlacementQuestion,
|
|
1148
|
+
InterviewContextSpec,
|
|
1149
|
+
InterviewContextAnswer,
|
|
1150
|
+
gradeInterviewContext,
|
|
1151
|
+
CourseIcon,
|
|
1152
|
+
SyllabusInput,
|
|
1153
|
+
CourseView,
|
|
1154
|
+
GraphSpec,
|
|
1155
|
+
MultipleChoiceSpec,
|
|
1156
|
+
toMultipleChoicePublic,
|
|
1157
|
+
MultipleChoiceAnswer,
|
|
1158
|
+
gradeMultipleChoice,
|
|
1159
|
+
SetDiagramSpec,
|
|
1160
|
+
TableSpec,
|
|
1161
|
+
WorkedStepsSpec,
|
|
1162
|
+
LessonSectionKind,
|
|
1163
|
+
MAX_LESSON_SECTIONS,
|
|
1164
|
+
LessonOutlineInput,
|
|
1165
|
+
LessonTextInput,
|
|
1166
|
+
LessonView,
|
|
1167
|
+
CourseLessonsView,
|
|
1168
|
+
ChangeLessonInput,
|
|
1169
|
+
ChangeSyllabusInput,
|
|
1170
|
+
AddToLesson,
|
|
1171
|
+
AdaptSyllabusInput,
|
|
1172
|
+
RememberInput,
|
|
1173
|
+
MemoryView,
|
|
1174
|
+
MemoryEdit,
|
|
1175
|
+
MemoryBulkDelete,
|
|
1176
|
+
MAX_DOCUMENT_BYTES,
|
|
1177
|
+
DocumentView,
|
|
1178
|
+
RecordFromNotesInput,
|
|
1179
|
+
DistillationView,
|
|
1180
|
+
ConceptGraph,
|
|
1181
|
+
MAX_VAULT_FILES,
|
|
1182
|
+
MAX_NOTE_CHARS,
|
|
1183
|
+
MAX_VAULT_BYTES,
|
|
1184
|
+
VaultImportInput,
|
|
1185
|
+
VaultSnapshotInput,
|
|
1186
|
+
VaultImportView,
|
|
1187
|
+
SkipReason,
|
|
1188
|
+
VaultImportResult,
|
|
1189
|
+
NoteView,
|
|
1190
|
+
NoteGraph,
|
|
1191
|
+
WHOLE_GRAPH_NOTES,
|
|
1192
|
+
MAX_GRAPH_VIEW_NOTES,
|
|
1193
|
+
MAX_GRAPH_VIEW_NODES,
|
|
1194
|
+
MAX_GRAPH_VIEW_EDGES,
|
|
1195
|
+
MAX_GRAPH_FACETS,
|
|
1196
|
+
NoteGraphViewQuery,
|
|
1197
|
+
NoteGraphView,
|
|
1198
|
+
NoteSummary,
|
|
1199
|
+
artifactKinds,
|
|
1200
|
+
ArtifactView,
|
|
1201
|
+
CHATGPT_USAGE_LIMIT_ERROR
|
|
1202
|
+
};
|
|
1203
|
+
//# sourceMappingURL=chunk-YACRW47X.js.map
|