Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

1.2 KB
Raw Blame
import { badBody, DraftSource, recipeFailure } from "@/server/recipe-routes";
import { draftFromCanvas, draftFromGenerations, draftFromThread } from "@/server/recipe-builder";

/**
 * A skill drafted from results in the Library (W2), from an Assist chat (W3) or from a canvas (W5): the steps behind them
 * rebuilt from their requests, every input Fixed, with the inputs that could vary and proposed checks; `refusals` say
 * which picks (or which of the chat's steps, or the canvas's nodes) couldn't be used and why. A canvas's Table rows come
 * as `rows`, for the Run form's Many tab.
 */
export async function POST(request: Request) {
  const parsed = DraftSource.safeParse(await request.json().catch(() => ({})));
  if (!parsed.success) return badBody(parsed.error.issues);
  try {
    if ("thread" in parsed.data) {
      const { draft, refusals } = draftFromThread(parsed.data.thread);
      return Response.json({ draft, refusals });
    }
    if ("canvas" in parsed.data) return Response.json(draftFromCanvas(parsed.data.canvas, parsed.data.page));
    return Response.json(draftFromGenerations(parsed.data.generations));
  } catch (e) {
    return recipeFailure(e);
  }
}