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
Skills W1: the Run form starts what it priced, takes typed decimals, and says when a skill is off
Claude64aa075ffd7c
diff --git a/src/components/assist/hooks.ts b/src/components/assist/hooks.tsindex 1524f153..789ef0c6 100644--- a/src/components/assist/hooks.ts+++ b/src/components/assist/hooks.ts@@ -215,10 +215,17 @@ export function useRecipeActions() {run: (name: string, body: RecipeBody) => recipeCall<{ engine: Engine; runs: RecipeRun[]; demo: boolean }>(`/api/assist/skills/${name}/run`, body),/** Check it (plan + the free dry run by default); the skill's status is refreshed with the result. */verify: async (name: string, body: { level?: "plan" | "demo" | "real"; engine?: Engine; confirm?: boolean } = {}) => {- const r = await recipeCall<VerifyResult>(`/api/assist/skills/${name}/verify`, { level: "demo", ...body });- qc.setQueryData(["assist-recipe", name], r.view);- void qc.invalidateQueries({ queryKey: ["assist-skills"] });- return r;+ try {+ const r = await recipeCall<VerifyResult>(`/api/assist/skills/${name}/verify`, { level: "demo", ...body });+ qc.setQueryData(["assist-recipe", name], r.view);+ return r;+ } catch (e) {+ // Refused (the recipe changed while it was checked, say): show the recipe as it is now.+ void qc.invalidateQueries({ queryKey: ["assist-recipe", name] });+ throw e;+ } finally {+ void qc.invalidateQueries({ queryKey: ["assist-skills"] });+ }},};}diff --git a/src/components/assist/run-skill-dialog.tsx b/src/components/assist/run-skill-dialog.tsxindex 3a087b76..64ea7938 100644--- a/src/components/assist/run-skill-dialog.tsx+++ b/src/components/assist/run-skill-dialog.tsx@@ -1,6 +1,6 @@"use client";-import { keepPreviousData, useQuery } from "@tanstack/react-query";+import { keepPreviousData, useQuery, useQueryClient } from "@tanstack/react-query";import { AlertTriangle, ChevronDown, Cloud, Cpu, FileUp, Info, Loader2, Minus, Play, Plus, ShieldCheck, X } from "lucide-react";import Link from "next/link";import { useRouter } from "next/navigation";@@ -22,7 +22,7 @@ import type { Engine } from "@/lib/catalog/types";import { formatCost } from "@/lib/format";import { checkValues, isMediaType, parseRows, RECIPE_LIMITS, type RecipeEstimate, type RecipeParam, type RecipeView } from "@/lib/recipe";import { cn } from "@/lib/utils";-import { useRecipe, useRecipeActions, type RecipeFailure } from "./hooks";+import { useRecipe, useRecipeActions, useSkillActions, type RecipeFailure } from "./hooks";import { PlanJobs } from "./plan-jobs";import { SkillIcon } from "./skill-icon";@@ -82,6 +82,8 @@ function priceLine(e: RecipeEstimate | undefined, runs: number): string {function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {const { recipe, name } = view;const actions = useRecipeActions();+ const skillActions = useSkillActions();+ const qc = useQueryClient();const router = useRouter();const [tab, setTab] = useState<"one" | "many">("one");const [values, setValues] = useState<Record<string, string | number | undefined>>(() => Object.fromEntries(recipe.params.map((p) => [p.id, p.default])));@@ -89,7 +91,7 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {const [csv, setCsv] = useState("");const [engine, setEngine] = useState<Engine>(view.ready[0] ?? view.engines[0] ?? "cloud");const [tried, setTried] = useState(false);- const [busy, setBusy] = useState<"run" | "check" | null>(null);+ const [busy, setBusy] = useState<"run" | "check" | "on" | null>(null);const [problems, setProblems] = useState<string[]>([]);const [open, setOpen] = useState(false);@@ -101,8 +103,11 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {const rowsOk = !!rows && !rows.errors.length && rows.rows.length > 0 && rows.rows.every((r) => !r.errors.length);const runs = tab === "many" ? (rows?.rows.length ?? 0) : 1;const body = tab === "one" ? { values: checked.values ?? form, engine } : { csv, engine };- const key = useDebounced(JSON.stringify(body), 400);- const canPrice = ready && !uploading && (tab === "one" ? !!checked.values : rowsOk);+ const sent = JSON.stringify(body);+ const key = useDebounced(sent, 400);+ // The price on screen is for `key`: Run starts exactly that, and only once it is what the form says now.+ const fresh = key === sent;+ const canPrice = view.enabled && ready && !uploading && (tab === "one" ? !!checked.values : rowsOk);const estimate = useQuery({queryKey: ["assist-recipe-estimate", name, key],enabled: canPrice,@@ -112,7 +117,7 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {});const est = canPrice ? estimate.data : undefined;const estError = canPrice && estimate.error ? (estimate.error as Error).message : (est?.errors[0] ?? est?.runs.flatMap((r) => r.errors)[0]);- const runnable = canPrice && !!est?.runnable && !estimate.isFetching;+ const runnable = canPrice && fresh && !!est?.runnable && !estimate.isFetching;const recheck = view.recheck[engine];const check = async () => {@@ -138,12 +143,25 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {}};+ const switchOn = async () => {+ setBusy("on");+ try {+ await skillActions.toggle(name, true);+ await qc.invalidateQueries({ queryKey: ["assist-recipe", name] });+ } catch (e) {+ toast.error((e as Error).message);+ } finally {+ setBusy(null);+ }+ };+const run = async () => {setTried(true);if (!runnable) return;setBusy("run");try {- const r = await actions.run(name, body);+ // What was priced (the debounced key), which `fresh` says is what the form holds.+ const r = await actions.run(name, JSON.parse(key) as typeof body);const started = r.runs.filter((x) => !x.error);const failed = r.runs.filter((x) => x.error);const href = started[0]?.href ?? "/library";@@ -163,7 +181,7 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {}};- const price = !ready ? "" : estError ? "" : estimate.isFetching && !est ? "Pricing…" : priceLine(est, runs);+ const price = !ready ? "" : estError ? "" : !fresh || estimate.isFetching ? "Pricing…" : priceLine(est, runs);return (<><DialogHeader className="flex-row items-start gap-3 border-b px-5 pt-5 pb-4 text-left">@@ -174,7 +192,18 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {</div></DialogHeader><div className="min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4">- {view.why ? (+ {!view.enabled ? (+ <Notice+ tone="warn"+ action={+ <Button size="sm" variant="outline" onClick={() => void switchOn()} disabled={busy !== null}>+ {busy === "on" ? <Loader2 className="animate-spin" /> : null} Switch it on+ </Button>+ }+ >+ This skill is switched off: switch it on to run it.+ </Notice>+ ) : view.why ? (<Notice tone="warn">{view.why}</Notice>) : !view.ready.length ? (<div className="flex flex-col gap-3 rounded-xl bg-muted/60 px-4 py-3 sm:flex-row sm:items-center">@@ -278,13 +307,13 @@ function Loaded({ view, onClose }: { view: RecipeView; onClose: () => void }) {</div><DialogFooter className="mx-0 mb-0 flex-col gap-2 border-t px-5 py-3 sm:flex-row sm:items-center sm:justify-between"><p className={cn("min-w-0 text-[13px] break-words", estError ? "text-destructive" : "text-muted-foreground")} aria-live="polite">- {!ready ? "Check it first to see the price" : estError ?? (canPrice ? price : tab === "one" ? (tried ? Object.values(checked.errors)[0] : "Fill in the inputs to see the price") : rows ? (rows.errors[0] ?? "Fix the rows marked below") : "Paste rows to see the total")}+ {!view.enabled ? "Switched off" : !ready ? "Check it first to see the price" : estError ?? (canPrice ? price : tab === "one" ? (tried ? Object.values(checked.errors)[0] : "Fill in the inputs to see the price") : rows ? (rows.errors[0] ?? "Fix the rows marked below") : "Paste rows to see the total")}</p><div className="flex shrink-0 gap-1.5 max-sm:w-full"><Button variant="ghost" size="sm" onClick={onClose} className="max-sm:flex-1">Cancel</Button>- <Button size="sm" onClick={() => void run()} disabled={busy !== null || !ready || (tried && !runnable)} className="max-sm:flex-[2]">+ <Button size="sm" onClick={() => void run()} disabled={busy !== null || !view.enabled || !ready || (canPrice && (!fresh || estimate.isFetching)) || (tried && !runnable)} className="max-sm:flex-[2]">{busy === "run" ? <Loader2 className="animate-spin" /> : <Play />}{runs > 1 ? `Run ${runs}` : "Run"}{runnable && est && !est.demo && est.total ? ` · ${formatCost(est.total)}` : ""}@@ -371,9 +400,12 @@ function Field({);}if (p.type === "number") {- const n = typeof value === "number" ? value : Number(value ?? p.min ?? 0);+ // What was typed stays as typed ("0." on the way to "0.5"); checkValues reads it as a number.+ const typed = typeof value === "number" ? value : Number(value ?? NaN);+ const n = Number.isFinite(typed) ? typed : (p.min ?? 0);const step = p.step ?? 1;- const clamp = (x: number) => Math.min(p.max ?? Infinity, Math.max(p.min ?? -Infinity, x));+ const places = (String(step).split(".")[1] ?? "").length;+ const clamp = (x: number) => Number(Math.min(p.max ?? Infinity, Math.max(p.min ?? -Infinity, x)).toFixed(places));return (<div className="space-y-1.5">{label}@@ -386,7 +418,7 @@ function Field({inputMode="decimal"value={value === undefined ? "" : String(value)}placeholder={example}- onChange={(e) => onChange(e.target.value === "" ? undefined : Number.isNaN(Number(e.target.value)) ? e.target.value : Number(e.target.value))}+ onChange={(e) => onChange(e.target.value === "" ? undefined : e.target.value)}className="h-8 w-16 border-0 bg-transparent text-center tabular-nums shadow-none"aria-invalid={!!error}/>diff --git a/tests/e2e/skills-run.mjs b/tests/e2e/skills-run.mjsindex 8b6e52a4..a629ab27 100644--- a/tests/e2e/skills-run.mjs+++ b/tests/e2e/skills-run.mjs@@ -1,9 +1,9 @@// Skills W1 in a real browser (demo mode: no keys, ComfyUI unreachable). A skill with a recipe is seeded over the API;// its card says "Runs by itself"; /assist/skills?run=<name> opens the Run form, which asks for a free check first,// then runs it once from the form (a photo, a name, a shape) and three times from pasted CSV rows, each priced first-// ("Demo" here); the skill's dialog says where it was checked, and in amber that it needs a re-check after its route-// changed, and Re-check clears it. ⌘K lists "Run <skill>…". At 1440 and 390 px, light and dark: nothing scrolls-// sideways, and on a phone the form fills the screen.+// ("Demo" here); a switched-off skill's form says so and switches it back on; the skill's dialog says where it was+// checked, and in amber that it needs a re-check after its route changed, and Re-check clears it. ⌘K lists+// "Run <skill>…". At 1440 and 390 px, light and dark: nothing scrolls sideways, and on a phone the form fills the screen.// Usage: node tests/e2e/skills-run.mjs [appUrl] [--shots <dir>] (app running in demo mode). Exits 1 on a failed check.import fs from "node:fs";import path from "node:path";@@ -155,6 +155,13 @@ try {await dialog.getByLabel("Rows to run").fill(`product,name\n${photo},Desk lamp\nnot-a-link,Floor lamp\n`);check(`${tag}: a bad row is marked inline`, await seen(dialog.getByText(/Product photo: a file from Fuobe/)));check(`${tag}: …and the footer says to fix it, with no price`, await seen(dialog.getByText("Fix the rows marked below")));+ // A switched-off skill's form says so (its Run is off), and switches it back on.+ await send("PATCH", `/api/assist/skills/${NAME}`, { enabled: false });+ await openRoute(page, `${app}/assist/skills?run=${NAME}`);+ check(`${tag}: a switched-off skill's form says so`, await seen(dialog.getByText("This skill is switched off")));+ check(`${tag}: …and its Run button is off`, await dialog.getByRole("button", { name: /^Run/ }).isDisabled());+ await dialog.getByRole("button", { name: "Switch it on" }).click();+ check(`${tag}: Switch it on brings the form back`, await seen(dialog.getByText("Runs in the cloud")));// 4. Re-check: a different route than the one checked (Replicate preferred) needs a re-check, and Re-check clears it.await send("PUT", "/api/settings", { cloudProvider: "replicate" });await openRoute(page, `${app}/assist/skills?skill=${NAME}`);