The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
N7-6 fixes: /api/turnaround names the film as final; a character's consent is asked and recorded by the server
Claudeb2565dbfe119
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.tsindex 24167b2a..75032dc4 100644--- a/src/lib/catalog/types.ts+++ b/src/lib/catalog/types.ts@@ -931,6 +931,11 @@ export interface GenerationRequest {* it was before the signature routed it (Reuse restores that). See src/lib/catalog/palettes.ts.*/signature?: SignatureRecord;+ /**+ * Server-set: when someone confirmed Soul ID's consent line for the real person this run shows (Turnaround video's+ * steps, src/server/turnaround.ts; a character trained with it carries its training's time). Stripped from API input.+ */+ consentAt?: number;}export interface ChainSlot {diff --git a/src/server/training.ts b/src/server/training.tsindex 1c5be9e1..d7c9e2ca 100644--- a/src/server/training.ts+++ b/src/server/training.ts@@ -174,6 +174,16 @@ const isAudio = (r: string) => /\.(wav|mp3|ogg|flac|m4a|webm)$/i.test(r);/** The photos a training uses: the element's images, up to Soul ID's 80. */const photosOf = (el: StudioElement) => el.references.filter((r) => !isAudio(r)).slice(0, SOUL_ID_PHOTOS.max);+/** When the consent line was confirmed for an element's Soul ID training (its latest that recorded one), if ever. */+export function consentOnFile(elementId: string): number | undefined {+ const rows = db().prepare(`SELECT meta_json FROM trainings WHERE element_id = ? AND meta_json LIKE '%"consentAt"%' ORDER BY created_at DESC`).all(elementId) as Pick<Row, "meta_json">[];+ for (const r of rows) {+ const at = metaOf(r).consentAt;+ if (typeof at === "number") return at;+ }+ return undefined;+}+export function startTraining(elementId: string, targetId: string, opts: { consent?: boolean } = {}): Training {const el = getElement(elementId);const target = getTrainingTarget(targetId);diff --git a/src/server/turnaround.ts b/src/server/turnaround.tsindex c443a7b3..9e158b5f 100644--- a/src/server/turnaround.ts+++ b/src/server/turnaround.ts@@ -5,9 +5,12 @@ import { getModel } from "@/lib/catalog";import { routesFor } from "@/lib/catalog/plan";import { planTurnaround, routeOfModel, type TurnaroundContext, type TurnaroundInput, type TurnaroundPlan, type TurnaroundPreview, type TurnStep } from "@/lib/catalog/turnaround";import type { Generation } from "@/lib/catalog/types";+import { needsConsent } from "@/lib/catalog/training";+import { getElement } from "./elements";import { cancelGeneration, createGenerations, previewChained, previewGeneration } from "./generations";import { isOffered } from "./model-access";import { loadManifest } from "./providers/comfyui";+import { consentOnFile } from "./training";/*** Turnaround video (build plan N7-6): the plan from src/lib/catalog/turnaround.ts, checked step by step on this install@@ -44,10 +47,23 @@ export const TurnaroundBodySchema = TurnaroundSchema.extend({requestId: z.string().max(80).optional(),});-/** A request body as the server runs it: a character's run filed in its feed, a named model's route. */+/**+ * A request body as the server runs it: a character's run filed in its feed, a named model's route. A character is a+ * person whatever the client says (Soul ID's rule, needsConsent): its run needs the consent line, unless the character+ * was trained with it confirmed (the training's consentAt).+ */export function turnaroundRun({ elementId, modelId, ...input }: Omit<z.infer<typeof TurnaroundBodySchema>, "requestId">): TurnaroundRequest {const route = input.route ?? routeOfModel(input.engine, modelId);- return { ...input, ...(route && { route }), ...(elementId && { feature: `element:${elementId}` }) };+ const el = elementId ? getElement(elementId) : null;+ const person = !!el && needsConsent(el.kind);+ const onFile = person ? consentOnFile(el.id) : undefined;+ return {+ ...input,+ ...(route && { route }),+ ...(elementId && { feature: `element:${elementId}` }),+ ...(person && { realPerson: true }),+ ...(onFile !== undefined && { consentOnFile: onFile }),+ };}export class TurnaroundError extends Error {@@ -63,6 +79,8 @@ export interface TurnaroundRequest extends TurnaroundInput {/** The pictures show a real person (not one Fuobe made): Soul ID's consent line must be confirmed. */realPerson?: boolean;consent?: boolean;+ /** Server-set (never from the body): when the character's consent was confirmed for its Soul ID training. */+ consentOnFile?: number;}/** What this install offers (Settings → Models & licences). */@@ -121,7 +139,7 @@ export function previewTurnaround(input: TurnaroundRequest): TurnaroundPreview {blocker = (e as Error).message;}}- if (!blocker && input.realPerson && !input.consent) blocker = NEEDS_CONSENT;+ if (!blocker && input.realPerson && !input.consent && input.consentOnFile === undefined) blocker = NEEDS_CONSENT;return {route: plan.route,routes: plan.routes,@@ -135,6 +153,7 @@ export function previewTurnaround(input: TurnaroundRequest): TurnaroundPreview {steps: plan.steps.length,notes: [...plan.notes, ...check.notes.filter((n) => !plan.notes.includes(n))],...(blocker && { blocker }),+ ...(input.realPerson && { consent: input.consentOnFile !== undefined ? ("on-file" as const) : ("asked" as const) }),costUsd: check.demo ? 0 : check.costUsd,demo: check.demo,...(gpuGb(plan) !== undefined && { gpuGb: gpuGb(plan) }),@@ -164,19 +183,28 @@ export function runTurnaroundSteps(steps: TurnStep[], batchId = nanoid(10)): Gen}export interface TurnaroundResult {+ /** The finished turnaround's generation (the film, or the one clip): what the studio routes' `final` names, so the+ * evaluation harness measures the film, not the last step made. */+ final: Generation;items: Generation[];- /** The finished turnaround's generation (the film, or the one clip). */filmId: string;batchId: string;plan: TurnaroundPreview;}-/** Plan, check every step, then run them; a real person's pictures need the consent line. */+/**+ * Plan, check every step, then run them. A real person's pictures need the consent line: every step's request records+ * when it was confirmed (GenerationRequest.consentAt; the training's time for a character trained with it).+ */export function createTurnaround(input: TurnaroundRequest): TurnaroundResult {const preview = previewTurnaround(input);if (preview.blocker) throw new TurnaroundError(preview.blocker);const plan = planTurnaround(input, turnaroundContext());+ if (input.realPerson) {+ const consentAt = input.consent ? Date.now() : input.consentOnFile;+ for (const s of plan.steps) s.request.consentAt = consentAt;+ }const batchId = nanoid(10);const items = runTurnaroundSteps(plan.steps, batchId);- return { items, filmId: items[0].id, batchId, plan: preview };+ return { final: items[0], items, filmId: items[0].id, batchId, plan: preview };}diff --git a/tests/turnaround-api.test.ts b/tests/turnaround-api.test.tsindex 8eb50d66..54e6c0c7 100644--- a/tests/turnaround-api.test.ts+++ b/tests/turnaround-api.test.ts@@ -20,6 +20,8 @@ const { saveFile } = await import("@/server/storage");const { encodePng } = await import("@/server/png");const { NEEDS_CONSENT } = await import("@/server/turnaround");const { ORBIT_PROMPT } = await import("@/lib/catalog/turnaround");+const { db } = await import("@/server/db");+const { routeResult } = (await import("../scripts/eval/lib/run.mjs")) as { routeResult: (answer: unknown, how?: string) => { id: string; op?: string }[] };beforeAll(() => {setSetting("demoMode", "auto");@@ -58,8 +60,12 @@ describe("/api/turnaround", () => {const back = upload("back2.png");const res = await post({ engine: "open", views: { front, back }, name: "Ada", requestId: "turn-open-1" });expect(res.status).toBe(201);- const { items, filmId, batchId } = await res.json();+ const answer = await res.json();+ const { items, filmId, batchId } = answer;expect(items[0].id).toBe(filmId);+ // The answer names the film as `final`, so the evaluation harness measures it (not the last clip made).+ expect(answer.final.id).toBe(filmId);+ expect(routeResult(answer).map((g: { id: string }) => g.id)).toEqual([filmId]);expect(items[0]).toMatchObject({ modelId: "oss-join-clips", op: "concat", feature: "turnaround", prompt: "Turnaround · Ada" });const steps = items.slice(1);expect(steps.filter((g: { feature: string }) => g.feature === "turnaround-step").map((g: { request: { step: { label: string } } }) => g.request.step.label)).toEqual(["Right side (Angles)", "Left side (Angles)"]);@@ -80,8 +86,10 @@ describe("/api/turnaround", () => {expect(preview.gpuGb).toBeUndefined();const res = await post({ engine: "cloud", views: pics, route: "keyframes" });expect(res.status).toBe(201);- const { filmId, items } = await res.json();+ const answer = await res.json();+ const { filmId, items } = answer;expect(items[0]).toMatchObject({ modelId: "flux-3-max", op: "keyframes", feature: "turnaround" });+ expect(routeResult(answer)[0].id).toBe(filmId);expect((await settle(filmId)).status).toBe("succeeded");}, 60_000);@@ -102,6 +110,52 @@ describe("/api/turnaround", () => {await settle(filmId);}, 60_000);+ it("names the film, not a drawn side, when the cloud's references wait for the Angles app", async () => {+ const res = await post({ engine: "cloud", views: { front: upload("rf.png"), back: upload("rb.png") }, fill: true, requestId: "turn-refs-fill" });+ expect(res.status).toBe(201);+ const answer = await res.json();+ expect(answer.items.map((g: { op: string }) => g.op)).toEqual(["ref2v", "edit", "edit"]);+ expect(routeResult(answer)).toEqual([expect.objectContaining({ id: answer.filmId, op: "ref2v" })]);+ // It ends on the front, as it starts.+ expect(answer.final.request.inputs.endImage).toBe(answer.final.request.inputs.images[0]);+ await settle(answer.filmId);+ }, 60_000);++ it("asks a character's consent on the server whatever the client says, records it, and takes it from its Soul ID training", async () => {+ const { createElement } = await import("@/server/elements");+ const front = upload("char.png");+ const el = createElement({ name: "Bea", kind: "character", references: [front] });+ // Left out, or the switch turned off: still asked.+ for (const body of [{}, { realPerson: false }]) {+ const preview = await (await post({ engine: "cloud", views: { front }, elementId: el.id, ...body }, true)).json();+ expect(preview).toMatchObject({ blocker: NEEDS_CONSENT, consent: "asked" });+ const refused = await post({ engine: "cloud", views: { front }, elementId: el.id, ...body });+ expect(refused.status).toBe(422);+ }+ // Confirmed: every step records when.+ const before = Date.now();+ const ok = await post({ engine: "cloud", views: { front }, elementId: el.id, consent: true });+ expect(ok.status).toBe(201);+ const { items } = await ok.json();+ expect(items.every((g: { request: { consentAt?: number } }) => (g.request.consentAt ?? 0) >= before)).toBe(true);+ // A character trained for Soul ID with the consent line confirmed has it on file.+ const trained = createElement({ name: "Cy", kind: "character", references: [front] });+ const at = 1_790_000_000_000;+ db()+ .prepare(+ "INSERT INTO trainings (id, element_id, target, provider, status, progress, message, external_id, meta_json, trigger_word, error, cost_usd, created_at, updated_at, completed_at) VALUES (?, ?, 'demo', 'demo', 'succeeded', NULL, NULL, 'demo', ?, 'cy', NULL, NULL, ?, ?, ?)",+ )+ .run("tr-cy", trained.id, JSON.stringify({ consentAt: at }), at, at, at);+ const onFile = await (await post({ engine: "cloud", views: { front }, elementId: trained.id }, true)).json();+ expect(onFile.blocker).toBeUndefined();+ expect(onFile.consent).toBe("on-file");+ const run = await (await post({ engine: "cloud", views: { front }, elementId: trained.id })).json();+ expect(run.final.request.consentAt).toBe(at);+ // A Character Sheet with no character: the client's own switch (made-up people need no consent line).+ expect((await (await post({ engine: "cloud", views: { front } }, true)).json()).consent).toBeUndefined();+ await settle(run.filmId);+ }, 60_000);+it("prices a job named by its model at /api/turnaround/estimate, as the evaluation harness does", async () => {const pics = { front: upload("ef.png"), right: upload("er.png"), back: upload("eb.png"), left: upload("el.png") };const ask = async (b: unknown) =>