comfyui-mcp
Version:
Local-first, agent-native control plane for ComfyUI — MCP server + autonomous sidebar agent that drives your live graph in natural language on ANY LLM: Claude/ChatGPT/Gemini on your subscription (no API key), free local models via Ollama (fully offline),
62 lines • 2.25 kB
JavaScript
import { createWorkflow } from "./workflow-composer.js";
import { DefaultsManager } from "./defaults-manager.js";
import { ValidationError } from "../utils/errors.js";
// Keys the DefaultsManager may supply for image generation.
const DEFAULTABLE_KEYS = [
"negative_prompt",
"width",
"height",
"steps",
"cfg",
"sampler",
"scheduler",
"seed",
"checkpoint",
"batch_size",
];
/**
* Construct a txt2img workflow from `args` backfilled by DefaultsManager,
* auto-resolving a checkpoint if needed, then enqueue it. Reuses the existing
* workflow-composer txt2img template rather than building the node graph here.
*/
export async function generateImage(args, deps) {
// Backfill only the defaultable knobs; prompt is always caller-supplied.
const seed = {};
for (const key of DEFAULTABLE_KEYS) {
const v = args[key];
if (v !== undefined)
seed[key] = v;
}
const resolved = DefaultsManager.apply(seed);
let checkpoint = resolved.checkpoint;
if (!checkpoint) {
checkpoint = await deps.resolveCheckpoint();
}
if (!checkpoint) {
throw new ValidationError("No checkpoint specified, defaulted, or found locally. " +
"Pass `checkpoint`, set a default via get_defaults (action:\"set\"), or download one with download_model.");
}
const workflow = createWorkflow("txt2img", {
checkpoint,
positive_prompt: args.prompt,
negative_prompt: resolved.negative_prompt,
width: resolved.width,
height: resolved.height,
steps: resolved.steps,
cfg: resolved.cfg,
seed: resolved.seed,
sampler_name: resolved.sampler,
scheduler: resolved.scheduler,
});
const batchSize = resolved.batch_size;
if (batchSize !== undefined && batchSize !== 1) {
for (const node of Object.values(workflow)) {
if (node.class_type === "EmptyLatentImage") {
node.inputs.batch_size = batchSize;
}
}
}
const { prompt_id, queue_remaining, rejectedOutputs } = await deps.enqueue(workflow);
return { prompt_id, queue_remaining, rejectedOutputs, checkpoint };
}
//# sourceMappingURL=generate-image.js.map