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
Scheduled tasks: a file input the skill can do without starts on None or the skill's own file, and runs without it when nothing is uploaded yet
Claude8c8318c6862d
diff --git a/src/components/assist/schedule-skill.tsx b/src/components/assist/schedule-skill.tsxindex 470035da..62735f8a 100644--- a/src/components/assist/schedule-skill.tsx+++ b/src/components/assist/schedule-skill.tsx@@ -10,7 +10,7 @@ import { EngineSwitch } from "@/components/studio/engine-switch";import { MediaSlot, type SlotValue } from "@/components/studio/media-slot";import { radioKeys, radioTab } from "@/components/studio/radio-keys";import type { SkillSummary } from "@/lib/assist";-import { newestWords, type ScheduleSkill } from "@/lib/assist-schedule";+import type { ScheduleSkill } from "@/lib/assist-schedule";import type { Engine } from "@/lib/catalog/types";import { formatCost } from "@/lib/format";import { checkValues, isMediaType, type RecipeEstimate, type RecipeParam, type RecipeView } from "@/lib/recipe";@@ -24,11 +24,14 @@ import { SkillIcon } from "./skill-icon";* for each file input a picked file or the newest upload of that kind, read when the run starts.*/+/** Where a file input comes from: the newest upload when it runs, one picked file, or none (the skill's default, if it has one). */+type Source = "newest" | "file" | "none";+/** What the form holds: values as typed (a picked file's URL too), the file slots, and where each file input comes from. */export interface SkillInputs {values: Record<string, string | number | undefined>;slots: Record<string, SlotValue | null>;- sources: Record<string, "newest" | "file">;+ sources: Record<string, Source>;}/** The form for a saved task's skill, or an empty one. */@@ -40,8 +43,21 @@ export const inputsFrom = (skill?: ScheduleSkill | null): SkillInputs => ({type FileParam = RecipeParam & { type: "image" | "video" | "audio" };-/** A file input with nothing picked takes the newest upload; one that holds a file keeps it. */-const sourceOf = (p: RecipeParam, inputs: SkillInputs) => inputs.sources[p.id] ?? (typeof inputs.values[p.id] === "string" && inputs.values[p.id] ? "file" : "newest");+/** An input the skill can't run without: required, with no default of its own. */+const needed = (p: RecipeParam) => p.required && p.default === undefined;++/**+ * Where a file input comes from. One that holds a file keeps it. Otherwise an input the skill needs takes the newest+ * upload (only the first needed input of each kind, so two don't read the same file), and one it can do without, or+ * that has a default of its own, takes none.+ */+function sourceOf(p: RecipeParam, inputs: SkillInputs, params: RecipeParam[]): Source {+ const set = inputs.sources[p.id];+ if (set) return set;+ if (typeof inputs.values[p.id] === "string" && inputs.values[p.id]) return "file";+ if (!needed(p)) return "none";+ return params.find((q) => q.type === p.type && needed(q))?.id === p.id ? "newest" : "file";+}const slotOf = (p: FileParam, inputs: SkillInputs): SlotValue | null => {if (p.id in inputs.slots) return inputs.slots[p.id];@@ -60,11 +76,13 @@ export function skillTask(view: RecipeView, inputs: SkillInputs): { task: Schedulet uploading = false;for (const p of view.recipe.params) {if (isMediaType(p.type)) {- if (sourceOf(p, inputs) === "newest") {+ const source = sourceOf(p, inputs, view.recipe.params);+ if (source === "newest") {sources[p.id] = "newest";priced[p.id] = NEWEST[p.type];continue;}+ if (source === "none") continue;const slot = slotOf(p as FileParam, inputs);if (slot?.uploading) uploading = true;else if (slot?.ref) values[p.id] = priced[p.id] = slot.ref;@@ -185,7 +203,7 @@ export function SkillTaskFields({<FileInputkey={p.id}p={p as FileParam}- source={sourceOf(p, inputs)}+ source={sourceOf(p, inputs, view.recipe.params)}onSource={(s) => set({ sources: { ...inputs.sources, [p.id]: s } })}slot={slotOf(p as FileParam, inputs)}onSlot={(v) => set({ slots: { ...inputs.slots, [p.id]: v } })}@@ -240,17 +258,20 @@ function FileInput({error,}: {p: FileParam;- source: "newest" | "file";- onSource: (s: "newest" | "file") => void;+ source: Source;+ onSource: (s: Source) => void;slot: SlotValue | null;onSlot: (v: SlotValue | null) => void;error?: string;}) {const labelId = useId();- const options = [+ const options: { id: Source; label: string }[] = [{ id: "newest", label: "Newest upload (when it runs)" },{ id: "file", label: "This file" },- ] as const;+ // An input the skill can do without: leave it out, or use the file the skill comes with.+ ...(needed(p) ? [] : [{ id: "none" as const, label: p.default !== undefined ? "The skill's own" : "None" }]),+ ];+ const kind = p.type === "image" ? "image" : p.type === "video" ? "video" : "audio file";return (<div className="space-y-2"><p id={labelId} className="text-sm font-medium">@@ -273,7 +294,16 @@ function FileInput({))}</div>{source === "newest" ? (- <p className="text-[12px] text-muted-foreground">Each run uses {newestWords(p.type)} at that moment: upload a new one before it runs, and that's the one it takes.</p>+ <p className="text-[12px] text-muted-foreground">+ Each run takes the newest {kind} in{" "}+ <Link href="/library?tab=uploads" className="font-medium text-brand-text underline-offset-2 hover:underline">+ Library → Uploads+ </Link>{" "}+ at that moment, whatever put it there: upload a new one before it runs, and that's the one it takes.+ {needed(p) ? "" : p.default !== undefined ? ` With no ${kind} there yet, it uses the skill's own.` : ` With no ${kind} there yet, the run goes ahead without one.`}+ </p>+ ) : source === "none" ? (+ <p className="text-[12px] text-muted-foreground">{p.default !== undefined ? `Every run uses the skill's own ${kind}.` : "Every run goes without one."}</p>) : (<div className="flex items-center gap-3"><MediaSlot label={p.label} kind={p.type} value={slot} onChange={onSlot} required={p.required} />diff --git a/src/lib/assist-schedule.ts b/src/lib/assist-schedule.tsindex 288748ad..c245fbd8 100644--- a/src/lib/assist-schedule.ts+++ b/src/lib/assist-schedule.ts@@ -288,7 +288,11 @@ export function skillTaskLine(skill: ScheduleSkill, params: { id: string; label:const parts = params.flatMap((p) => {const v = skill.values[p.id];const file = p.type === "image" || p.type === "video" || p.type === "audio" ? p.type : null;- if (skill.sources?.[p.id] === "newest" && file) return [`${p.label}: ${newestWords(file)}${files && v ? ` (${files(v)})` : ""}`];+ if (skill.sources?.[p.id] === "newest" && file) {+ // A run's line says when there was nothing to read, so the input was left out.+ if (files && !v) return [`${p.label}: no ${KIND_WORDS[file]} upload yet, so it's left out`];+ return [`${p.label}: ${newestWords(file)}${files && v ? ` (${files(v)})` : ""}`];+ }if (v === undefined || v === "") return [];if (file && /^(\/api\/files\/|https?:\/\/)/i.test(v)) return [`${p.label}: ${files ? files(v) : "a file you picked"}`];return [`${p.label}: ${v.length > 80 ? `${v.slice(0, 79).trimEnd()}…` : v}`];diff --git a/src/server/assist/schedules.ts b/src/server/assist/schedules.tsindex a68364be..180995ac 100644--- a/src/server/assist/schedules.ts+++ b/src/server/assist/schedules.ts@@ -388,8 +388,10 @@ function prepareSkillRun(task: ScheduleSkill, projectId: string | null): SkillRuif (task.sources?.[p.id] !== "newest" || !isMediaType(p.type)) continue;// The owner's newest upload of that kind, as the Library's Uploads list shows it.const newest = listAssets({ source: "upload", kind: p.type, limit: 1 })[0];- if (!newest) return { stop: "failed", message: `There's no ${newestWords(p.type).replace(/^your newest /, "")} yet for “${p.label}” — upload one, or edit the task to pick a file` };- values[p.id] = newest.url;+ if (newest) values[p.id] = newest.url;+ // An input the skill can do without (or has a file of its own for) is left out until there's an upload.+ else if (!p.required || p.default !== undefined) delete values[p.id];+ else return { stop: "failed", message: `There's no ${newestWords(p.type).replace(/^your newest /, "")} yet for “${p.label}” — upload one, or edit the task to pick a file` };}const files = [...new Set(recipe.params.flatMap((p) => (isMediaType(p.type) && values[p.id]?.startsWith("/api/files/") ? [values[p.id]] : [])))].slice(0, 8);const line = skillTaskLine({ ...task, values }, recipe.params, (url) => (files.includes(url) ? `file ${files.indexOf(url) + 1}` : url));diff --git a/tests/assist-schedules.test.ts b/tests/assist-schedules.test.tsindex 928b5fdb..7d280be0 100644--- a/tests/assist-schedules.test.ts+++ b/tests/assist-schedules.test.ts@@ -410,6 +410,53 @@ describe("a skill on a schedule (Skills W4)", () => {expect(sched.getSchedule(s.id)).toMatchObject({ paused: false, runs: 1, last: { threadId: null, status: "failed", text: "There's no image upload yet for “Product photo” — upload one, or edit the task to pick a file" } });});+ it("an input the skill can do without, set to the newest upload with none yet, is left out and the run goes ahead", async () => {+ const name = "logo-promo";+ (await skills()).createSkill({ name, title: "Logo promo", description: "A promo still, with a logo when there is one.", body: "# Logo promo\n\n1. Stage it." });+ (await recipes()).saveRecipe(name, {+ fuobeRecipe: 1,+ params: [+ { id: "name", label: "Product name", type: "text", required: true, max: 200 },+ { id: "logo", label: "Logo", type: "image" },+ ],+ steps: [{ key: "ad", kind: "generate", request: { feature: "skill", modelId: "nano-banana-pro", prompt: "{{name}} on a sunlit plinth", inputs: { images: ["{{logo}}"] } } }],+ });+ const s = sched.createSchedule({ ...base, prompt: "", title: "", skill: { name, values: { name: "Lumen lamp" }, sources: { logo: "newest" } }, rule: daily }, at);+ const [id] = await sched.sweepSchedules(T("2026-10-27T09:00:00Z"), { model: noModel });+ const t = threadOf(id);+ expect(t.items[1]).toMatchObject({ role: "user", text: "Product name: Lumen lamp · Logo: no image upload yet, so it's left out" });+ expect(t.items.find((i) => i.role === "approval")).toMatchObject({ status: "pending", summary: "Logo promo" });+ const use = stored(id).flatMap((m) => (typeof m.content === "string" ? [] : m.content)).find((b) => b.type === "tool_use");+ expect(use).toMatchObject({ name: "run_skill", input: { name, values: { name: "Lumen lamp" } } });+ expect(sched.getSchedule(s.id)).toMatchObject({ paused: false, last: { threadId: id, status: "waiting" } });+ (await skills()).deleteSkill(name);+ });++ it("the dialog starts a needed file input on the newest upload, and one the skill can do without on none", async () => {+ const { inputsFrom, skillTask } = await import("@/components/assist/schedule-skill");+ const view = {+ name: "two-shots",+ recipe: {+ params: [+ { id: "front", label: "Front", type: "image", required: true },+ { id: "back", label: "Back", type: "image", required: true },+ { id: "logo", label: "Logo", type: "image" },+ { id: "badge", label: "Badge", type: "image", required: true, default: "/api/files/uploads/badge.png" },+ ],+ },+ } as unknown as import("@/lib/recipe").RecipeView;+ // Only the first needed input of a kind reads the newest upload, so two never take the same file; the second asks for one.+ const fresh = skillTask(view, inputsFrom(null));+ expect(fresh.task).toEqual({ name: "two-shots", values: {}, sources: { front: "newest" } });+ expect(fresh.errors).toMatchObject({ back: "Back is needed" });+ expect(Object.keys(fresh.errors)).toEqual(["back"]);+ // Picked by hand: the newest upload for the optional logo, a file for the back.+ const picked = skillTask(view, { ...inputsFrom(null), values: { back: "/api/files/uploads/back.png" }, sources: { logo: "newest" } });+ expect(picked).toMatchObject({ ok: true, task: { values: { back: "/api/files/uploads/back.png" }, sources: { front: "newest", logo: "newest" } } });+ // A saved task reopens as it was saved: what it left out stays out.+ expect(skillTask(view, inputsFrom(picked.task)).task).toEqual(picked.task);+ });+it("is checked when saved: the skill, its inputs and the engine; and needs no prompt or model", async () => {const name = await promoSkill();const save = (skill: import("@/lib/assist-schedule").ScheduleSkill, extra: Partial<import("@/server/assist/schedules").ScheduleInput> = {}) =>