Share-link sets save into the class; flashcards up to 75
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 28s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 28s
- Sets visitors generate show in the owner's Drafts while being written, then save into the class (and exam, for an exam link) automatically, as if approved. If the save fails, the draft waits in Drafts for review. - Deleting a share link keeps what was made on it; running jobs finish and save. - Visitor flashcard sets go up to 75 cards (default 30); quizzes stay at 50. - The visitor page links finished sets to the class items; the separate AI-set view is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e945f589ce
commit
76112cb4ae
8 changed files with 146 additions and 103 deletions
|
|
@ -62,7 +62,7 @@ interface DraftRow {
|
|||
saved_kind: string | null;
|
||||
saved_id: string | null;
|
||||
conversation_id: string | null;
|
||||
/** Made by a visitor of this share link (not listed with the owner's drafts). */
|
||||
/** Made by a visitor of this share link (saved to the library automatically when done). */
|
||||
share_id: string | null;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
|
|
@ -154,7 +154,7 @@ export function createDraft(
|
|||
|
||||
export function listDrafts(db: DB) {
|
||||
return db
|
||||
.all<DraftRow>(`SELECT * FROM drafts WHERE status IN ('generating', 'ready', 'failed') AND share_id IS NULL ORDER BY updated_at DESC LIMIT 50`)
|
||||
.all<DraftRow>(`SELECT * FROM drafts WHERE status IN ('generating', 'ready', 'failed') ORDER BY updated_at DESC LIMIT 50`)
|
||||
.map(mapDraft)
|
||||
.map(({ payload: _payload, ...rest }) => rest);
|
||||
}
|
||||
|
|
@ -266,9 +266,7 @@ export function discardDraft(db: DB, id: string): void {
|
|||
export function tidyDrafts(db: DB): void {
|
||||
db.run(`UPDATE drafts SET status = 'failed', error = 'Generation was interrupted by a restart. Start it again.' WHERE status = 'generating'`);
|
||||
db.run(`DELETE FROM drafts WHERE status IN ('saved', 'discarded') AND updated_at < ?`, now() - 14 * 86_400_000);
|
||||
db.run(`DELETE FROM drafts WHERE status IN ('ready', 'failed') AND share_id IS NULL AND updated_at < ?`, now() - 60 * 86_400_000);
|
||||
// Sets made on a share link stay with the link; failed attempts go after a week.
|
||||
db.run(`DELETE FROM drafts WHERE status = 'failed' AND share_id IS NOT NULL AND updated_at < ?`, now() - 7 * 86_400_000);
|
||||
db.run(`DELETE FROM drafts WHERE status IN ('ready', 'failed') AND updated_at < ?`, now() - 60 * 86_400_000);
|
||||
}
|
||||
|
||||
/* ------------------------------ request ------------------------------ */
|
||||
|
|
@ -759,7 +757,14 @@ const NOTE_TITLES: Record<string, string> = { study_guide: 'study guide', summar
|
|||
export function startGeneration(
|
||||
app: AppContext,
|
||||
input: z.input<typeof generateRequestSchema>,
|
||||
opts: { conversationId?: string | null; origin?: DraftMeta['origin']; onProgress?: (label: string) => void; shareId?: string } = {},
|
||||
opts: {
|
||||
conversationId?: string | null;
|
||||
origin?: DraftMeta['origin'];
|
||||
onProgress?: (label: string) => void;
|
||||
shareId?: string;
|
||||
/** Save the finished draft to the library straight away (share-link visitors' sets). */
|
||||
autoSave?: { description: string };
|
||||
} = {},
|
||||
): { draftId: string; done: Promise<DraftDto> } {
|
||||
const req = generateRequestSchema.parse(input);
|
||||
if (req.classId) getClass(app.db, req.classId);
|
||||
|
|
@ -798,11 +803,27 @@ export function startGeneration(
|
|||
.then(() => {
|
||||
running.delete(draftId);
|
||||
progressListeners.delete(draftId);
|
||||
if (opts.autoSave) autoSaveDraft(app, draftId, opts.autoSave.description);
|
||||
return getDraft(app.db, draftId);
|
||||
});
|
||||
return { draftId, done };
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a finished draft into its class (and exam) as if the owner had approved it. When saving
|
||||
* fails, the draft stays in the owner's drafts to review.
|
||||
*/
|
||||
function autoSaveDraft(app: AppContext, draftId: string, description: string): void {
|
||||
try {
|
||||
const draft = getDraft(app.db, draftId);
|
||||
if (draft.status !== 'ready' || (draft.payload.kind !== 'quiz' && draft.payload.kind !== 'deck')) return;
|
||||
if (!draft.payload.description) updateDraftPayload(app.db, draftId, { ...draft.payload, description });
|
||||
saveDraft(app, draftId, {});
|
||||
} catch (err) {
|
||||
app.log('warn', 'A share-link set could not be saved automatically; it is waiting in Drafts', err);
|
||||
}
|
||||
}
|
||||
|
||||
async function runGeneration(app: AppContext, draftId: string, req: GenerateRequest, signal: AbortSignal): Promise<void> {
|
||||
const { db } = app;
|
||||
const resolved = resolveModel(app, 'generate', req.modelId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue