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),
46 lines • 1.87 kB
JavaScript
import { enqueuePrompt as clientEnqueuePrompt, getSystemStats as clientGetSystemStats, } from "../comfyui/client.js";
import { logger } from "../utils/logger.js";
import { JobWatcher } from "./job-watcher.js";
/**
* Randomize seed and noise_seed fields in a workflow.
* Replicates the behavior that the SDK's `enqueue()` does internally,
* since `_enqueue_prompt()` is the raw HTTP POST without seed randomization.
*/
function randomizeSeeds(workflow) {
const copy = JSON.parse(JSON.stringify(workflow));
for (const node of Object.values(copy)) {
if (node.inputs) {
for (const key of ["seed", "noise_seed"]) {
if (key in node.inputs &&
typeof node.inputs[key] === "number") {
node.inputs[key] = Math.floor(Math.random() * 2 ** 32);
}
}
}
}
return copy;
}
/**
* Fire-and-forget workflow enqueue. Returns prompt_id immediately
* without waiting for execution to complete.
*/
export async function enqueueWorkflow(workflowJson, options) {
const workflow = options?.disable_random_seed
? workflowJson
: randomizeSeeds(workflowJson);
logger.info("Enqueueing workflow (fire-and-forget)");
const result = await clientEnqueuePrompt(workflow, options?.extra_data);
logger.info("Workflow enqueued", {
prompt_id: result.prompt_id,
queue_remaining: result.queue_remaining,
});
// Start background watcher for completion detection. Capture the workflow
// that was actually sent (post-seed-randomization) so the AssetRegistry can
// store an exact reproducible snapshot for `regenerate`.
JobWatcher.watch(result.prompt_id, workflow);
return result;
}
export async function getSystemInfo() {
return clientGetSystemStats();
}
//# sourceMappingURL=workflow-executor.js.map