UNPKG

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),

64 lines • 2.48 kB
// Per-panel-tab workflow target: which open ComfyUI workflow tab the agent // should edit. Without pinning, graph_* commands hit whatever workflow the user // is currently viewing — browsing another tab mid-conversation redirects edits. // // Pinning injects `workflow_path` on workflow-scoped bridge commands so the // panel can operate on a background workflow without switching the user's view. // The comfyui-mcp-panel pack must honor `workflow_path` on graph executors. const DEFAULT_TARGET = { mode: "current" }; /** In-memory per-tab workflow pin. Process-scoped; cleared on orchestrator restart. */ export class WorkflowTargetStore { targets = new Map(); get(tabId) { return this.targets.get(tabId) ?? DEFAULT_TARGET; } set(tabId, target) { const normalized = normalizeTarget(target); if (normalized.mode === "current") { this.targets.delete(tabId); return DEFAULT_TARGET; } this.targets.set(tabId, normalized); return normalized; } clear(tabId) { this.targets.delete(tabId); } } function normalizeTarget(raw) { if (raw.mode !== "pinned") return { mode: "current" }; const path = (raw.path ?? "").trim(); if (!path) return { mode: "current" }; const filename = (raw.filename ?? "").trim() || undefined; return { mode: "pinned", path, filename }; } /** Bridge commands that target a specific workflow canvas (not tab navigation). */ export function shouldInjectWorkflowPath(cmd, args) { if (cmd === "workflow_list" || cmd === "workflow_new" || cmd === "workflow_open") return false; if (cmd.startsWith("graph_")) return true; // workflow_* that default to "active" when path omitted if ((cmd === "workflow_save" || cmd === "workflow_save_as" || cmd === "workflow_rename" || cmd === "workflow_close") && args.path === undefined) { return true; } return false; } /** Attach workflow_path when the tab has a pinned target. */ export function withWorkflowTarget(cmd, target) { if (target.mode !== "pinned" || !target.path) return cmd; const name = typeof cmd.cmd === "string" ? cmd.cmd : ""; if (!name || cmd.workflow_path !== undefined) return cmd; if (!shouldInjectWorkflowPath(name, cmd)) return cmd; return { ...cmd, workflow_path: target.path }; } //# sourceMappingURL=workflow-target-store.js.map