Add “Make my homework”, and finish the mobile polish pass
Homework (/homework — entry points in the drawer and on the create screen) - Assignment intake reuses the study pipeline: pasted text, photos (camera/picker, compressed in the browser) and documents (PDF/DOCX/PPTX/ ODT/text) through lib/image + lib/documents, the same vision step and the same language guard. Raw files never leave the device — only text and JPEG data URLs reach the server. - Two large choice cards: “Just make it” returns the finished homework (answer only, plain text, copy + make it again); “Explain how to make this homework” builds an interactive guide. - The guide is one step per screen in the study-feed snap layout: explanation, three progressive hints (nudge -> hint -> the answer) and an optional checkpoint rendered by the existing activity components (graded through /api/grade). The last screen assembles the solution from the step answers, with a copy button. Checkpoints carry xp 0 so the guide stays free of XP/streak chrome. - Results live in freezmo.homework.v1 with a small history (open/delete); “Make it again” re-runs from the stored assignment text (the vision transcription when photos were used) — no original files are stored. - The answer and the guide are written in the assignment's language, never translated into the UI language. Server - POST /api/homework: NDJSON stage events like /api/generate, the same http-guard, auth checked before parsing, and its own RATE_LIMIT_HOMEWORK (documented in .env.example + the README table). - New prompts in lib/prompts.ts and zod schemas in lib/schemas.ts with the same single repair retry; TEXT_MODEL for content, VISION_MODEL only for photos. New shared client pieces: useNotesIntake, lib/homework store, lib/clipboard, and a shared NDJSON reader in lib/client-api. Also finishing the mobile polish pass from the previous request - Phone ice scene: the top-left orb moved behind the glass header (it sat behind the page heading/subtitle). The settings sheet's scroll cue is now a bare chevron inside a content fade (mask) instead of a chip over the status banner, and the API key card's note/disclosure/actions are tightened. - theme-color now follows the in-app theme (SSR metas still fall back to the OS preference); apple-mobile-web-app-status-bar-style stays “default” because iOS fixes the status-bar text colour at launch. Verified: 78/78 homework checks (text/photo/PDF, both modes, EN+CS, dark+light, 360/390px, copy, history persistence, storage privacy, API language, axe), plus the existing suites re-run (mobile 47/47, pixel contrast 0 below AA, i18n 27/27, desktop regression 72/72). Lint + build clean; service worker freezmo-v6.
This commit is contained in:
parent
9fb728d735
commit
ef2a6a3589
35 changed files with 2334 additions and 100 deletions
|
|
@ -135,6 +135,95 @@ export const gradeResultSchema = z.object({
|
|||
missing: z.array(z.string().max(200)).max(6).default([]),
|
||||
});export type GradeResult = z.infer<typeof gradeResultSchema>;
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Make my homework */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
export const homeworkModeSchema = z.enum(["make", "guide"]);
|
||||
export type HomeworkMode = z.infer<typeof homeworkModeSchema>;
|
||||
|
||||
/** Mode 1 — the finished homework, nothing else. */
|
||||
export const homeworkMakeSchema = z.object({
|
||||
title: z.string().min(1).max(200),
|
||||
/** English name of the language the assignment was written in. */
|
||||
language: z.string().max(60).optional(),
|
||||
answer: z.string().min(1).max(20_000),
|
||||
});
|
||||
export type HomeworkMake = z.infer<typeof homeworkMakeSchema>;
|
||||
|
||||
/**
|
||||
* One step of the interactive guide, as the model returns it. `checkpoint` is
|
||||
* a normal study activity (validated by the same schema as the feed) that the
|
||||
* student answers to check the step landed.
|
||||
*/
|
||||
export const homeworkStepSchema = z.object({
|
||||
title: z.string().min(1).max(200),
|
||||
explanation: z.string().min(1).max(1500),
|
||||
/** Progressive help: nudge -> real hint -> the full answer for this step. */
|
||||
hints: z.array(z.string().min(1).max(1500)).min(1).max(4),
|
||||
/** The full answer for this step; the guide assembles the solution from these. */
|
||||
answer: z.string().min(1).max(5000),
|
||||
checkpoint: generatedActivitySchema.optional(),
|
||||
});
|
||||
|
||||
export const homeworkGuideSchema = z.object({
|
||||
title: z.string().min(1).max(200),
|
||||
language: z.string().max(60).optional(),
|
||||
steps: z.array(homeworkStepSchema).min(2).max(10),
|
||||
});
|
||||
export type HomeworkGuide = z.infer<typeof homeworkGuideSchema>;
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Client-side homework types (checkpoints carry id/xp, plus storage) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
export const homeworkCheckpointSchema = generatedActivitySchema.and(
|
||||
z.object({ id: z.string(), xp: z.number() }),
|
||||
);
|
||||
export type HomeworkCheckpoint = z.infer<typeof homeworkCheckpointSchema>;
|
||||
|
||||
export type HomeworkStep = {
|
||||
title: string;
|
||||
explanation: string;
|
||||
hints: string[];
|
||||
answer: string;
|
||||
checkpoint?: HomeworkCheckpoint;
|
||||
};
|
||||
|
||||
export const homeworkStepStoredSchema: z.ZodType<HomeworkStep> = z.object({
|
||||
title: z.string().min(1).max(200),
|
||||
explanation: z.string().min(1).max(1500),
|
||||
hints: z.array(z.string().min(1).max(1500)).min(1).max(4),
|
||||
answer: z.string().min(1).max(5000),
|
||||
checkpoint: homeworkCheckpointSchema.optional(),
|
||||
});
|
||||
|
||||
const homeworkBaseFields = {
|
||||
id: z.string().min(1).max(80),
|
||||
title: z.string().min(1).max(200),
|
||||
language: z.string().max(60).optional(),
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
/** The assignment text (photos/documents were reduced to text client-side). */
|
||||
sourceText: z.string().max(40_000),
|
||||
};
|
||||
|
||||
export const homeworkRecordSchema = z.discriminatedUnion("mode", [
|
||||
z.object({
|
||||
...homeworkBaseFields,
|
||||
mode: z.literal("make"),
|
||||
answer: z.string().min(1).max(20_000),
|
||||
}),
|
||||
z.object({
|
||||
...homeworkBaseFields,
|
||||
mode: z.literal("guide"),
|
||||
steps: z.array(homeworkStepStoredSchema).min(2).max(10),
|
||||
}),
|
||||
]);
|
||||
export type HomeworkRecord = z.infer<typeof homeworkRecordSchema>;
|
||||
export type HomeworkMakeRecord = Extract<HomeworkRecord, { mode: "make" }>;
|
||||
export type HomeworkGuideRecord = Extract<HomeworkRecord, { mode: "guide" }>;
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Client-side deck types (activity + id/xp, plus storage metadata) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue