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),
95 lines • 3.9 kB
JavaScript
// Persisted panel settings for the orchestrator's background agent. Survives
// soft reloads and full restarts (it's a small JSON file on disk), so a setting
// like the adult-content consent gate stays put and is queryable across the
// session — the agent reads it before deciding whether to surface NSFW work.
//
// The NSFW gate is a SAFETY control: it defaults OFF (keep everything SFW), and
// only flips ON after an explicit, verified-adult opt-in (18+ and adult content
// legal in the user's region). It governs what the system SURFACES and records
// the user's consent. It never overrides hard limits (no minors, no real-person
// sexual deepfakes, no depictions of actual non-consensual acts).
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { logger } from "../utils/logger.js";
/** Settings file path. Overridable for tests. */
export function panelSettingsPath() {
return (process.env.COMFYUI_MCP_PANEL_SETTINGS ||
join(homedir(), ".comfyui-mcp", "panel-settings.json"));
}
function read() {
const p = panelSettingsPath();
if (!existsSync(p))
return {};
try {
const parsed = JSON.parse(readFileSync(p, "utf-8"));
return parsed && typeof parsed === "object" ? parsed : {};
}
catch (err) {
logger.warn(`[panel-settings] could not parse ${p}: ${err instanceof Error ? err.message : String(err)}`);
return {};
}
}
function write(settings) {
const p = panelSettingsPath();
mkdirSync(dirname(p), { recursive: true });
writeFileSync(p, JSON.stringify(settings, null, 2));
}
/** Current NSFW consent state. Defaults to OFF when never set. */
export function getNsfwConsent() {
return read().nsfwConsent ?? { allowed: false };
}
/**
* Persist an NSFW consent decision. `allowed` true ONLY after a verified-adult
* opt-in; false revokes. Stamps the decision time.
*/
export function setNsfwConsent(allowed) {
const decidedAt = new Date().toISOString();
const settings = read();
settings.nsfwConsent = { allowed, decidedAt };
write(settings);
return settings.nsfwConsent;
}
/** Persisted agent backend/model preferences ({} when never set). */
export function getAgentSettings() {
return read().agent ?? {};
}
/**
* Merge a partial update into the persisted agent settings. `preferredModels`
* replaces the whole list (the panel sends the full edited list); `ollama`
* fields merge per-key so e.g. a model change doesn't clobber the base URL.
*/
/**
* Canonical form of a preferred-models list: trim, drop blanks, dedup, cap at 50.
* Exported so the set_config handler can compare an INCOMING list against the
* persisted one on the SAME footing — comparing a raw payload against this
* normalized list would report "changed" on every heartbeat and revive the
* config-repush loop (#393 follow-up).
*/
export function normalizePreferredModels(list) {
return [...new Set(list.map((m) => m.trim()).filter(Boolean))].slice(0, 50);
}
export function setAgentSettings(patch) {
const settings = read();
const prev = settings.agent ?? {};
const next = { ...prev };
if (patch.preferredModels !== undefined) {
next.preferredModels = normalizePreferredModels(patch.preferredModels);
}
if (patch.ollama !== undefined) {
next.ollama = { ...prev.ollama, ...patch.ollama };
}
if (patch.lmstudio !== undefined) {
next.lmstudio = { ...prev.lmstudio, ...patch.lmstudio };
}
if (patch.llamacpp !== undefined) {
next.llamacpp = { ...prev.llamacpp, ...patch.llamacpp };
}
if (patch.custom !== undefined) {
next.custom = { ...prev.custom, ...patch.custom };
}
settings.agent = next;
write(settings);
return next;
}
//# sourceMappingURL=panel-settings.js.map