Phase 3: Check my work, follow-ups and turn-into-deck
Check my work (third homework mode) - One model call with its own system prompt marks the student's own attempt: verdict, what's right, each issue with why + fix, and the corrected version that keeps everything the student got right. Unasked-for extras are never errors. The attempt is typed/pasted (photos of handwriting are documented as unsupported) and stored in the record so Redo re-checks the same work. - Server: mode "check" + solution on POST /api/homework (zod, 400 server.needSolution without one) and the same NDJSON stream; new checkHomework() pipeline with repair-once validation. Follow-ups - New POST /api/homework/refine (plain JSON, RATE_LIMIT_REFINE, zod, auth before body): shorter / more detail / explain, plain text back, language preserved. - Shorter + More detail + Original rewrite the finished answer and the corrected version in place (FollowUpBar); every guide step has Explain step N differently; failed calls say so without losing text. Turn into a study deck - Any result hands its content (answer, corrected version or assembled guide) to New deck through a one-shot sessionStorage seed with the options step pre-filled. UI - Phone step 2 gains the third card: tapping it reveals the solution field + submit; desktop has three cards and the solution field shows with the mode. Homework history labels and share/card previews cover the new mode. Verified: new phase-3 suite 20/20 against a stub Ollama (check payload, missing-solution 400, refine validation, phone + desktop check flows, shorter follow-up with restore, guide explain, deck hand-off) plus regression 74/74, mobile 52/52, declutter 116/116, wizard 80/80, animation 8/8, native 35/35, phase1 38/38, phase2 43/43, i18n 25/25. Key parity 734/734. Lint + build clean. SW freezmo-v27.
This commit is contained in:
parent
a8a8bc0477
commit
4513364019
22 changed files with 947 additions and 56 deletions
|
|
@ -154,6 +154,8 @@ export type HomeworkInput = {
|
|||
mode: HomeworkMode;
|
||||
images?: string[];
|
||||
text?: string;
|
||||
/** Mode "check": the student's own attempt at the assignment. */
|
||||
solution?: string;
|
||||
language?: string;
|
||||
};
|
||||
|
||||
|
|
@ -164,7 +166,17 @@ export type HomeworkProgress = {
|
|||
|
||||
export type StreamedHomework =
|
||||
| { mode: "make"; title: string; language?: string; answer: string; sourceText?: string }
|
||||
| { mode: "guide"; title: string; language?: string; steps: HomeworkStep[]; sourceText?: string };
|
||||
| { mode: "guide"; title: string; language?: string; steps: HomeworkStep[]; sourceText?: string }
|
||||
| {
|
||||
mode: "check";
|
||||
title: string;
|
||||
language?: string;
|
||||
verdict: string;
|
||||
correct: string[];
|
||||
wrong: Array<{ issue: string; why: string; fix: string }>;
|
||||
corrected: string;
|
||||
sourceText?: string;
|
||||
};
|
||||
|
||||
type HomeworkStreamEvent =
|
||||
| { type: "stage"; stage: "vision" | "generation" | "done"; message: string }
|
||||
|
|
@ -224,6 +236,10 @@ export async function generateHomework(
|
|||
const result = homework as StreamedHomework;
|
||||
if (result.mode === "make") {
|
||||
if (!result.answer?.trim()) throw new ApiError(t("api.noHomework"), "bad_response");
|
||||
} else if (result.mode === "check") {
|
||||
if (!result.corrected?.trim() || !result.verdict?.trim()) {
|
||||
throw new ApiError(t("api.noHomework"), "bad_response");
|
||||
}
|
||||
} else {
|
||||
const steps = result.steps?.filter((step) => step && typeof step.title === "string");
|
||||
if (!steps || steps.length < 2) throw new ApiError(t("api.noHomework"), "bad_response");
|
||||
|
|
@ -242,6 +258,35 @@ export async function generateHomework(
|
|||
return { homework: result, meta };
|
||||
}
|
||||
|
||||
/** Follow-up on a finished result: shorter, more detail, or explain again. */
|
||||
export async function refineHomework(input: {
|
||||
instruction: "shorter" | "more" | "explain";
|
||||
text: string;
|
||||
context?: string;
|
||||
signal?: AbortSignal;
|
||||
}): Promise<string> {
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch("/api/homework/refine", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", ...authHeaders(), ...localeHeader() },
|
||||
body: JSON.stringify({ instruction: input.instruction, text: input.text, context: input.context }),
|
||||
signal: input.signal,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
throw new ApiError(t("api.cancelled"), "aborted");
|
||||
}
|
||||
throw new ApiError(t("api.unreachable"), "network");
|
||||
}
|
||||
const body = (await response.json().catch(() => null)) as { text?: string; error?: string; kind?: string } | null;
|
||||
if (!response.ok) {
|
||||
throw new ApiError(body?.error ?? t("api.httpError", { status: response.status }), body?.kind);
|
||||
}
|
||||
if (!body?.text?.trim()) throw new ApiError(t("api.noHomework"), "bad_response");
|
||||
return body.text.trim();
|
||||
}
|
||||
|
||||
export async function gradeAnswer(input: {
|
||||
question: string;
|
||||
referenceAnswer: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue