5860b232d4
Publish to Comfy registry / Publish Custom Node to registry (push) Has been cancelled
getmappings keys packs by dir name/registry id far more often than by repo URL, so the url-only join found just 7 of 73 disabled packs (71 nodes). Resolve each getmappings key against every identifier a pack exposes (dir, id, cnr_id, aux_id, files) like classifyUnresolved does — now 69 packs / 2301 nodes. Bump to 1.4.1.
1269 lines
57 KiB
JavaScript
1269 lines
57 KiB
JavaScript
import { app } from "../../scripts/app.js";
|
|
|
|
// Bar chart with nodes icon
|
|
const STATS_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<rect x="3" y="12" width="4" height="9" rx="1"/>
|
|
<rect x="10" y="7" width="4" height="14" rx="1"/>
|
|
<rect x="17" y="3" width="4" height="18" rx="1"/>
|
|
<circle cx="5" cy="8" r="2" fill="currentColor" stroke="none"/>
|
|
<circle cx="12" cy="3.5" r="2" fill="currentColor" stroke="none"/>
|
|
<line x1="7" y1="8" x2="10" y2="4.5"/>
|
|
</svg>`;
|
|
|
|
// Single source of truth for per-status presentation: badge label, accent
|
|
// color, row background + hover, and summary-card colors. Used by the nodes
|
|
// tab, models tab, and summary bars so they all stay in sync.
|
|
const STATUS_META = {
|
|
safe_to_remove: { label: "safe to remove", color: "#e44", bg: "#2a1515", hover: "#3a2020", summaryBg: "#3a1a1a", summaryText: "#c99" },
|
|
consider_removing: { label: "consider removing", color: "#e90", bg: "#2a2215", hover: "#3a2e20", summaryBg: "#2a2215", summaryText: "#ca8" },
|
|
unused_new: { label: "unused <1mo", color: "#68f", bg: "#1a1a25", hover: "#252530", summaryBg: "#1a1a2a", summaryText: "#99b" },
|
|
used: { label: "used", color: "#4a4", bg: "#151a15", hover: "#202a20", summaryBg: "#1a2a1a", summaryText: "#9c9" },
|
|
uninstalled: { label: "uninstalled", color: "#555", bg: "#1a1a1a", hover: "#252525", summaryBg: "#1a1a1a", summaryText: "#888" },
|
|
};
|
|
|
|
// Tiers that may offer a "Disable" action (when ComfyUI Manager is available).
|
|
const DISABLEABLE_TIERS = new Set(["safe_to_remove", "consider_removing"]);
|
|
|
|
app.registerExtension({
|
|
name: "comfyui.nodes_stats",
|
|
|
|
async setup() {
|
|
const btn = document.createElement("button");
|
|
btn.innerHTML = STATS_ICON;
|
|
btn.title = "Node Stats";
|
|
btn.className = "comfyui-button comfyui-menu-mobile-collapse";
|
|
btn.onclick = () => showStatsDialog();
|
|
btn.style.cssText =
|
|
"display:flex;align-items:center;justify-content:center;padding:6px;cursor:pointer;";
|
|
|
|
if (app.menu?.settingsGroup?.element) {
|
|
app.menu.settingsGroup.element.before(btn);
|
|
} else {
|
|
const menu = document.querySelector(".comfy-menu");
|
|
if (menu) {
|
|
menu.append(btn);
|
|
}
|
|
}
|
|
|
|
const searchBtn = document.createElement("button");
|
|
searchBtn.textContent = "⌕";
|
|
searchBtn.title = "Search disabled-pack nodes (Ctrl/Cmd+Shift+D)";
|
|
searchBtn.className = "comfyui-button comfyui-menu-mobile-collapse";
|
|
searchBtn.style.cssText = "display:flex;align-items:center;justify-content:center;padding:6px;cursor:pointer;font-size:16px;";
|
|
searchBtn.onclick = () => openMirrorSearch();
|
|
if (app.menu?.settingsGroup?.element) app.menu.settingsGroup.element.before(searchBtn);
|
|
else document.querySelector(".comfy-menu")?.append(searchBtn);
|
|
|
|
// Detect missing/disabled nodes whenever a workflow is loaded.
|
|
const origLoad = app.loadGraphData?.bind(app);
|
|
if (origLoad) {
|
|
app.loadGraphData = function (...args) {
|
|
const r = origLoad(...args);
|
|
setTimeout(() => onWorkflowLoaded(), 0); // after graph settles
|
|
return r;
|
|
};
|
|
}
|
|
|
|
// Once the app has settled, auto-disable trial packages that went unused for
|
|
// their full budget of distinct boot-days. Inert when ComfyUI Manager is absent.
|
|
setTimeout(() => { processExpiredTrials().catch(() => {}); }, 3000);
|
|
|
|
window.addEventListener("keydown", (e) => {
|
|
if (!(e.shiftKey && (e.ctrlKey || e.metaKey) && (e.key === "D" || e.key === "d"))) return;
|
|
const t = e.target;
|
|
if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
|
|
e.preventDefault();
|
|
openMirrorSearch();
|
|
});
|
|
},
|
|
});
|
|
|
|
// Return the set of node types present in the current graph that LiteGraph
|
|
// doesn't have registered — i.e. nodes from missing or disabled packages.
|
|
function unresolvedNodeTypes() {
|
|
const types = new Set();
|
|
const nodes = app.graph?._nodes || [];
|
|
for (const n of nodes) {
|
|
const t = n.type;
|
|
if (t && !LiteGraph.registered_node_types[t]) types.add(t);
|
|
}
|
|
return [...types];
|
|
}
|
|
|
|
// Latest workflow scan, shared so showStatsDialog can render the Workflow tab.
|
|
let _lastWorkflowScan = { disabled: [], missing: [] };
|
|
|
|
async function onWorkflowLoaded() {
|
|
const types = unresolvedNodeTypes();
|
|
_lastWorkflowScan = await classifyUnresolved(types);
|
|
if (_lastWorkflowScan.disabled.length || _lastWorkflowScan.missing.length) {
|
|
showStatsDialog("workflow"); // auto-open on the Workflow tab
|
|
}
|
|
}
|
|
|
|
async function showStatsDialog(initialTab = "nodes") {
|
|
let data, modelData, managerInfo, trials = [];
|
|
try {
|
|
const [pkgResp, modelResp, mgr, trialsResp] = await Promise.all([
|
|
fetch("/nodes-stats/packages"),
|
|
fetch("/nodes-stats/models"),
|
|
fetchManagerInfo(),
|
|
fetch("/nodes-stats/trials").catch(() => null),
|
|
]);
|
|
if (!pkgResp.ok) { alert("Failed to load node stats: HTTP " + pkgResp.status); return; }
|
|
if (!modelResp.ok) { alert("Failed to load model stats: HTTP " + modelResp.status); return; }
|
|
data = await pkgResp.json();
|
|
modelData = await modelResp.json();
|
|
managerInfo = mgr;
|
|
if (trialsResp && trialsResp.ok) { try { trials = await trialsResp.json(); } catch { trials = []; } }
|
|
if (!Array.isArray(data) || !Array.isArray(modelData)) {
|
|
alert("Failed to load stats: unexpected response format");
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
alert("Failed to load stats: " + e.message);
|
|
return;
|
|
}
|
|
|
|
const custom = data.filter((p) => p.package !== "__builtin__");
|
|
|
|
// Remove existing dialog if any
|
|
const existing = document.getElementById("nodes-stats-dialog");
|
|
if (existing) existing.remove();
|
|
|
|
const overlay = document.createElement("div");
|
|
overlay.id = "nodes-stats-dialog";
|
|
overlay.style.cssText =
|
|
"position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);z-index:10000;display:flex;align-items:center;justify-content:center;";
|
|
overlay.addEventListener("click", (e) => {
|
|
if (e.target === overlay) overlay.remove();
|
|
});
|
|
|
|
const dialog = document.createElement("div");
|
|
dialog.style.cssText =
|
|
"background:#1e1e1e;color:#ddd;border-radius:8px;padding:24px;max-width:800px;width:90%;max-height:85vh;overflow-y:auto;font-family:monospace;font-size:13px;";
|
|
|
|
let html = dialogStyle();
|
|
|
|
html += `<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;">
|
|
<h2 style="margin:0;color:#fff;font-size:18px;">Usage Stats</h2>
|
|
<button id="nodes-stats-close" style="background:none;border:none;color:#888;font-size:20px;cursor:pointer;">×</button>
|
|
</div>`;
|
|
|
|
// Tab switcher — wired via addEventListener after insertion, no onclick globals
|
|
html += `
|
|
<div id="ns-tabs" style="display:flex;gap:0;margin-bottom:20px;border-bottom:1px solid #333;">
|
|
<button id="ns-tab-nodes"
|
|
style="background:none;border:none;border-bottom:2px solid #4a4;color:#4a4;padding:8px 18px;cursor:pointer;font-family:monospace;font-size:13px;font-weight:bold;">
|
|
Nodes
|
|
</button>
|
|
<button id="ns-tab-models"
|
|
style="background:none;border:none;border-bottom:2px solid transparent;color:#888;padding:8px 18px;cursor:pointer;font-family:monospace;font-size:13px;">
|
|
Models
|
|
</button>
|
|
<button id="ns-tab-workflow"
|
|
style="background:none;border:none;border-bottom:2px solid transparent;color:#888;padding:8px 18px;cursor:pointer;font-family:monospace;font-size:13px;">
|
|
Workflow
|
|
</button>
|
|
</div>`;
|
|
|
|
// Nodes tab content
|
|
html += `<div id="ns-content-nodes">`;
|
|
html += buildNodesTabContent(custom, managerInfo);
|
|
html += `</div>`;
|
|
|
|
// Models tab content
|
|
html += `<div id="ns-content-models" style="display:none;">`;
|
|
html += buildModelsTabContent(modelData);
|
|
html += `</div>`;
|
|
|
|
// Workflow tab content (missing / disabled nodes in the loaded workflow)
|
|
html += `<div id="ns-content-workflow" style="display:none;">`;
|
|
html += buildWorkflowTabContent(_lastWorkflowScan, trials);
|
|
html += `</div>`;
|
|
|
|
dialog.innerHTML = html;
|
|
overlay.appendChild(dialog);
|
|
document.body.appendChild(overlay);
|
|
|
|
// Tab switch — local function, no window pollution
|
|
const TABS = ["nodes", "models", "workflow"];
|
|
function switchTab(tab) {
|
|
for (const t of TABS) {
|
|
dialog.querySelector(`#ns-content-${t}`).style.display = t === tab ? "" : "none";
|
|
const b = dialog.querySelector(`#ns-tab-${t}`);
|
|
b.style.borderBottomColor = t === tab ? "#4a4" : "transparent";
|
|
b.style.color = t === tab ? "#4a4" : "#888";
|
|
b.style.fontWeight = t === tab ? "bold" : "normal";
|
|
}
|
|
}
|
|
for (const t of TABS) {
|
|
dialog.querySelector(`#ns-tab-${t}`).addEventListener("click", () => switchTab(t));
|
|
}
|
|
|
|
dialog.querySelector("#nodes-stats-close").addEventListener("click", () => overlay.remove());
|
|
|
|
// Toggle expandable rows
|
|
dialog.querySelectorAll(".pkg-row").forEach((row) => {
|
|
row.addEventListener("click", () => {
|
|
const detail = row.nextElementSibling;
|
|
if (detail && detail.classList.contains("pkg-detail")) {
|
|
detail.style.display =
|
|
detail.style.display === "none" ? "table-row" : "none";
|
|
const arrow = row.querySelector(".arrow");
|
|
if (arrow)
|
|
arrow.textContent = detail.style.display === "none" ? "▶" : "▼";
|
|
}
|
|
});
|
|
});
|
|
|
|
wireDisableButtons(dialog, managerInfo);
|
|
wireWorkflowButtons(dialog);
|
|
|
|
switchTab(TABS.includes(initialTab) ? initialTab : "nodes");
|
|
|
|
// Easter egg: click "used" badge 5 times to show podium
|
|
let eggClicks = 0;
|
|
let eggTimer = null;
|
|
const usedBadge = dialog.querySelector("#nodes-stats-used-badge");
|
|
if (usedBadge) {
|
|
usedBadge.addEventListener("click", () => {
|
|
eggClicks++;
|
|
clearTimeout(eggTimer);
|
|
eggTimer = setTimeout(() => (eggClicks = 0), 1500);
|
|
if (eggClicks >= 5) {
|
|
eggClicks = 0;
|
|
const allNodes = custom
|
|
.flatMap((p) => p.nodes.map((n) => ({ ...n, pkg: p.package })))
|
|
.sort((a, b) => b.count - a.count);
|
|
showPodium(allNodes.slice(0, 3), overlay);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Scoped CSS for the dialog: row backgrounds + hover (replaces inline
|
|
// onmouseover/onmouseout) and the action buttons. Generated from STATUS_META.
|
|
function dialogStyle() {
|
|
let rows = "";
|
|
for (const [status, m] of Object.entries(STATUS_META)) {
|
|
rows += `#nodes-stats-dialog .ns-row-${status}{background:${m.bg};}`;
|
|
rows += `#nodes-stats-dialog .ns-row-${status}:hover{background:${m.hover};}`;
|
|
}
|
|
return `<style>
|
|
#nodes-stats-dialog .ns-disabled-row{opacity:0.45;}
|
|
#nodes-stats-dialog .ns-btn{font-family:monospace;font-size:11px;border:1px solid #555;background:#262626;color:#ddd;border-radius:4px;padding:3px 10px;cursor:pointer;white-space:nowrap;}
|
|
#nodes-stats-dialog .ns-btn:hover:not(:disabled){background:#3a2020;border-color:#e44;color:#fff;}
|
|
#nodes-stats-dialog .ns-btn:disabled{opacity:0.5;cursor:default;}
|
|
#nodes-stats-dialog .ns-disable-all-btn{border-color:#a33;color:#e88;}
|
|
${rows}
|
|
</style>`;
|
|
}
|
|
|
|
// Summary cards row. items: [{count, status, label, id?}]
|
|
function summaryBar(items) {
|
|
let html = `<div style="display:flex;gap:10px;margin-bottom:20px;flex-wrap:wrap;">`;
|
|
for (const it of items) {
|
|
const m = STATUS_META[it.status];
|
|
const idAttr = it.id ? ` id="${it.id}"` : "";
|
|
const cursor = it.id ? "cursor:default;user-select:none;" : "";
|
|
html += `<div${idAttr} style="background:${m.summaryBg};padding:8px 14px;border-radius:4px;border-left:3px solid ${m.color};${cursor}">
|
|
<span style="font-size:20px;font-weight:bold;color:${m.color};">${it.count}</span>
|
|
<span style="color:${m.summaryText};margin-left:6px;">${it.label}</span>
|
|
</div>`;
|
|
}
|
|
html += `</div>`;
|
|
return html;
|
|
}
|
|
|
|
function buildNodesTabContent(custom, managerInfo) {
|
|
const byStatus = (s) => custom.filter((p) => p.status === s);
|
|
const safeToRemove = byStatus("safe_to_remove");
|
|
const considerRemoving = byStatus("consider_removing");
|
|
const unusedNew = byStatus("unused_new");
|
|
const used = byStatus("used");
|
|
const uninstalled = byStatus("uninstalled");
|
|
|
|
let html = summaryBar([
|
|
{ count: safeToRemove.length, status: "safe_to_remove", label: "safe to remove" },
|
|
{ count: considerRemoving.length, status: "consider_removing", label: "consider removing" },
|
|
{ count: unusedNew.length, status: "unused_new", label: "unused <1 month" },
|
|
{ count: used.length, status: "used", label: "used", id: "nodes-stats-used-badge" },
|
|
]);
|
|
|
|
html += renderSection("Safe to Remove", "Unused for 2+ months", "safe_to_remove", safeToRemove, managerInfo);
|
|
html += renderSection("Consider Removing", "Unused for 1-2 months", "consider_removing", considerRemoving, managerInfo);
|
|
html += renderSection("Recently Unused", "Unused for less than 1 month", "unused_new", unusedNew, managerInfo);
|
|
html += renderSection("Used", "", "used", used, managerInfo);
|
|
html += renderSection("Uninstalled", "Previously tracked, no longer installed", "uninstalled", uninstalled, managerInfo);
|
|
|
|
return html;
|
|
}
|
|
|
|
function renderSection(title, subtitle, status, packages, managerInfo) {
|
|
if (packages.length === 0) return "";
|
|
|
|
const color = STATUS_META[status].color;
|
|
const withActions = !!managerInfo && DISABLEABLE_TIERS.has(status);
|
|
const eligible = withActions
|
|
? packages.filter((p) => isDisableEligible(p, managerInfo)).map((p) => p.package)
|
|
: [];
|
|
|
|
let action = "";
|
|
if (eligible.length > 0) {
|
|
action = `<button class="ns-btn ns-disable-all-btn" data-pkgs="${escapeAttr(JSON.stringify(eligible))}">Disable all (${eligible.length})</button>`;
|
|
}
|
|
|
|
let html = `<div style="display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin:16px 0 8px;">
|
|
<h3 style="color:${color};margin:0;font-size:14px;">${escapeHtml(title)}`;
|
|
if (subtitle) html += ` <span style="color:#666;font-size:12px;font-weight:normal;">— ${escapeHtml(subtitle)}</span>`;
|
|
html += `</h3>${action}</div>`;
|
|
|
|
html += buildTable(packages, status, withActions, managerInfo);
|
|
return html;
|
|
}
|
|
|
|
// A package can be disabled only if ComfyUI Manager knows it (by directory
|
|
// name) and it is currently active (any state other than already-disabled).
|
|
function isDisableEligible(pkg, managerInfo) {
|
|
if (!managerInfo || !pkg.installed) return false;
|
|
const info = managerInfo[pkg.package];
|
|
return !!(info && info.state && info.state !== "disabled");
|
|
}
|
|
|
|
function buildModelsTabContent(modelData) {
|
|
const allModels = modelData.flatMap((g) => g.models);
|
|
const count = (s) => allModels.filter((m) => m.status === s).length;
|
|
|
|
let html = summaryBar([
|
|
{ count: count("safe_to_remove"), status: "safe_to_remove", label: "safe to remove" },
|
|
{ count: count("consider_removing"), status: "consider_removing", label: "consider removing" },
|
|
{ count: count("unused_new"), status: "unused_new", label: "unused <1 month" },
|
|
{ count: count("used"), status: "used", label: "used" },
|
|
]);
|
|
|
|
if (allModels.length === 0) {
|
|
html += `<p style="color:#666;">No models tracked yet. Run a workflow to start.</p>`;
|
|
return html;
|
|
}
|
|
|
|
for (const group of modelData) {
|
|
if (group.models.length === 0) continue;
|
|
const title = group.model_type.charAt(0).toUpperCase() + group.model_type.slice(1).replace(/_/g, " ");
|
|
html += sectionHeader(title, `${group.models.length} model${group.models.length !== 1 ? "s" : ""}`, "#4a4");
|
|
html += buildModelTable(group.models);
|
|
}
|
|
|
|
return html;
|
|
}
|
|
|
|
function buildModelTable(models) {
|
|
let html = `<table style="width:100%;border-collapse:collapse;margin-bottom:12px;">
|
|
<thead><tr style="color:#888;text-align:left;border-bottom:1px solid #333;">
|
|
<th style="padding:6px 8px;">Model</th>
|
|
<th style="padding:6px 8px;text-align:right;">Executions</th>
|
|
<th style="padding:6px 8px;">Last Used</th>
|
|
<th style="padding:6px 8px;">Status</th>
|
|
</tr></thead><tbody>`;
|
|
|
|
for (const m of models) {
|
|
const meta = STATUS_META[m.status] || STATUS_META.used;
|
|
const lastSeen = m.last_seen ? new Date(m.last_seen).toLocaleDateString() : "—";
|
|
|
|
html += `<tr class="ns-row-${m.status}" style="border-bottom:1px solid #222;">
|
|
<td style="padding:6px 8px;color:#fff;">${escapeHtml(m.model_name)}</td>
|
|
<td style="padding:6px 8px;text-align:right;">${m.count}</td>
|
|
<td style="padding:6px 8px;color:#888;">${lastSeen}</td>
|
|
<td style="padding:6px 8px;"><span style="color:${meta.color};font-size:11px;">${meta.label}</span></td>
|
|
</tr>`;
|
|
}
|
|
|
|
html += `</tbody></table>`;
|
|
return html;
|
|
}
|
|
|
|
// Render the Workflow tab from a classification result. `disabled` entries get
|
|
// re-enable actions (temporary trial or permanent); `missing` entries get an
|
|
// Install button that defers to ComfyUI Manager.
|
|
function buildWorkflowTabContent({ disabled, missing }, trials) {
|
|
const trialByPkg = Object.fromEntries((trials || []).map((t) => [t.package, t]));
|
|
let html = "";
|
|
if (!disabled.length && !missing.length) {
|
|
return `<p style="color:#666;">No missing or disabled nodes in the current workflow.</p>`;
|
|
}
|
|
if (disabled.length) {
|
|
html += sectionHeader("Disabled", "Installed but disabled — re-enable to use", "#e90");
|
|
html += `<table style="width:100%;border-collapse:collapse;margin-bottom:12px;"><tbody>`;
|
|
for (const d of disabled) {
|
|
const t = trialByPkg[d.pkg];
|
|
const note = t ? `<span style="color:#6a6;font-size:11px;">on trial · ${t.days_remaining}d left</span>` : "";
|
|
html += `<tr class="ns-row-consider_removing" style="border-bottom:1px solid #222;">
|
|
<td style="padding:6px 8px;color:#fff;">${escapeHtml(d.type)}</td>
|
|
<td style="padding:6px 8px;color:#888;">${escapeHtml(d.pkg)} ${note}</td>
|
|
<td style="padding:6px 8px;text-align:right;white-space:nowrap;">
|
|
<button class="ns-btn ns-enable-temp-btn" data-pkg="${escapeAttr(d.pkg)}">Enable 7d</button>
|
|
<button class="ns-btn ns-enable-perm-btn" data-pkg="${escapeAttr(d.pkg)}" style="margin-left:6px;">Enable</button>
|
|
</td></tr>`;
|
|
}
|
|
html += `</tbody></table>`;
|
|
}
|
|
if (missing.length) {
|
|
html += sectionHeader("Missing", "Not installed — install via ComfyUI Manager", "#e44");
|
|
html += `<table style="width:100%;border-collapse:collapse;margin-bottom:12px;"><tbody>`;
|
|
for (const m of missing) {
|
|
html += `<tr class="ns-row-safe_to_remove" style="border-bottom:1px solid #222;">
|
|
<td style="padding:6px 8px;color:#fff;">${escapeHtml(m.type)}</td>
|
|
<td style="padding:6px 8px;color:#888;">${m.pkg ? escapeHtml(m.pkg) : "unknown"}</td>
|
|
<td style="padding:6px 8px;text-align:right;">
|
|
${m.pkg ? `<button class="ns-btn ns-install-btn" data-pkg="${escapeAttr(m.pkg)}">Install</button>` : "—"}
|
|
</td></tr>`;
|
|
}
|
|
html += `</tbody></table>`;
|
|
}
|
|
return html;
|
|
}
|
|
|
|
function sectionHeader(title, subtitle, color) {
|
|
let html = `<h3 style="color:${color};margin:16px 0 8px;font-size:14px;">${escapeHtml(title)}`;
|
|
if (subtitle) html += ` <span style="color:#666;font-size:12px;font-weight:normal;">— ${escapeHtml(subtitle)}</span>`;
|
|
html += `</h3>`;
|
|
return html;
|
|
}
|
|
|
|
function buildTable(packages, status, withActions, managerInfo) {
|
|
const colspan = withActions ? 7 : 6;
|
|
|
|
let html = `<table style="width:100%;border-collapse:collapse;margin-bottom:12px;">
|
|
<thead><tr style="color:#888;text-align:left;border-bottom:1px solid #333;">
|
|
<th style="padding:6px 8px;"></th>
|
|
<th style="padding:6px 8px;">Package</th>
|
|
<th style="padding:6px 8px;text-align:right;">Nodes</th>
|
|
<th style="padding:6px 8px;text-align:right;">Used</th>
|
|
<th style="padding:6px 8px;text-align:right;">Executions</th>
|
|
<th style="padding:6px 8px;">Last Used</th>`;
|
|
if (withActions) html += `<th style="padding:6px 8px;"></th>`;
|
|
html += `</tr></thead><tbody>`;
|
|
|
|
for (const pkg of packages) {
|
|
const hasNodes = pkg.nodes && pkg.nodes.length > 0;
|
|
const lastSeen = pkg.last_seen ? new Date(pkg.last_seen).toLocaleDateString() : "—";
|
|
|
|
html += `<tr class="pkg-row ns-row-${status}" style="cursor:${hasNodes ? "pointer" : "default"};border-bottom:1px solid #222;">
|
|
<td style="padding:6px 8px;width:20px;"><span class="arrow" style="color:#666;">${hasNodes ? "▶" : " "}</span></td>
|
|
<td style="padding:6px 8px;color:#fff;">${escapeHtml(pkg.package)}</td>
|
|
<td style="padding:6px 8px;text-align:right;">${pkg.total_nodes}</td>
|
|
<td style="padding:6px 8px;text-align:right;">${pkg.used_nodes}/${pkg.total_nodes}</td>
|
|
<td style="padding:6px 8px;text-align:right;">${pkg.total_executions}</td>
|
|
<td style="padding:6px 8px;color:#888;">${lastSeen}</td>`;
|
|
|
|
if (withActions) {
|
|
const eligible = isDisableEligible(pkg, managerInfo);
|
|
const cell = eligible
|
|
? `<button class="ns-btn ns-disable-btn" data-pkg="${escapeAttr(pkg.package)}">Disable</button>`
|
|
: `<span style="color:#555;">—</span>`;
|
|
html += `<td class="ns-action-cell" data-pkg="${escapeAttr(pkg.package)}" style="padding:6px 8px;text-align:right;">${cell}</td>`;
|
|
}
|
|
html += `</tr>`;
|
|
|
|
if (hasNodes) {
|
|
html += `<tr class="pkg-detail" style="display:none;"><td colspan="${colspan}" style="padding:0 0 0 32px;">
|
|
<table style="width:100%;border-collapse:collapse;">`;
|
|
for (const node of pkg.nodes) {
|
|
const nLastSeen = node.last_seen ? new Date(node.last_seen).toLocaleDateString() : "—";
|
|
html += `<tr style="border-bottom:1px solid #1a1a1a;color:#aaa;">
|
|
<td style="padding:3px 8px;">${escapeHtml(node.class_type)}</td>
|
|
<td style="padding:3px 8px;text-align:right;">${node.count}</td>
|
|
<td style="padding:3px 8px;color:#666;">${nLastSeen}</td>
|
|
</tr>`;
|
|
}
|
|
html += `</table></td></tr>`;
|
|
}
|
|
}
|
|
|
|
html += `</tbody></table>`;
|
|
return html;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ComfyUI Manager integration: disable unused node packages
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Map of installed packages from ComfyUI Manager, keyed by directory name:
|
|
// { <dir name>: { id, version, files, state }, ... }
|
|
// We read the unified list (/customnode/getlist) rather than /customnode/installed
|
|
// because only the unified list reports the install *state version* the disable
|
|
// endpoint needs: "nightly" for git installs, the semver for registry installs,
|
|
// or "unknown". (/customnode/installed returns a raw git commit hash instead,
|
|
// which the disable endpoint rejects.) This mirrors what Manager's own UI sends.
|
|
// Returns null when the Manager is not installed/reachable, so the disable UI is
|
|
// omitted entirely.
|
|
async function fetchManagerInfo() {
|
|
try {
|
|
const resp = await fetch("/customnode/getlist?mode=local&skip_update=true");
|
|
if (!resp.ok) return null;
|
|
const data = await resp.json();
|
|
const packs = data && data.node_packs;
|
|
if (!packs || typeof packs !== "object") return null;
|
|
const info = {};
|
|
for (const [key, v] of Object.entries(packs)) {
|
|
if (!v || v.state === "not-installed") continue;
|
|
// For installed packs the key is the directory name — matches our package names.
|
|
// cnr_id/aux_id are kept so getmappings keys (which may be a registry id or
|
|
// repo URL rather than the dir name) can be reconciled in classifyUnresolved.
|
|
info[key] = {
|
|
id: v.id || key, version: v.version, files: v.files, state: v.state,
|
|
cnr_id: v.cnr_id, aux_id: v.aux_id,
|
|
};
|
|
}
|
|
return info;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Normalize an identifier (repo URL, dir name, or registry id) for joining
|
|
// getmappings keys to getlist packs. Same ordering as classifyUnresolved's norm.
|
|
function normalizeRepoUrl(url) {
|
|
return String(url || "").trim().replace(/\/+$/, "").replace(/\.git$/i, "").toLowerCase();
|
|
}
|
|
|
|
// Join Manager's node->pack mappings with the disabled packs from getlist.
|
|
// mappings: { <packKey>: [ [class_type,...], {title_aux} ] } (from getmappings)
|
|
// managerInfo: { <dir>: {id,version,files,state,cnr_id,aux_id} } (from fetchManagerInfo)
|
|
// getmappings keys come in several forms (dir name, registry id, repo/gist URL),
|
|
// and Manager keys the node map by dir/id far more often than by URL — so we
|
|
// resolve each key against EVERY identifier a pack exposes, exactly as
|
|
// classifyUnresolved does. Matching repo URLs alone misses the vast majority of
|
|
// packs. Returns [{ class_type, pack, title, info }] for disabled packs only.
|
|
function buildDisabledCatalog(mappings, managerInfo) {
|
|
const byAnyKey = {};
|
|
for (const [dir, info] of Object.entries(managerInfo || {})) {
|
|
if (!info) continue;
|
|
const rec = { dir, info };
|
|
byAnyKey[normalizeRepoUrl(dir)] = rec;
|
|
for (const k of [info.id, info.cnr_id, info.aux_id]) if (k) byAnyKey[normalizeRepoUrl(k)] = rec;
|
|
for (const f of (info.files || [])) if (f) byAnyKey[normalizeRepoUrl(f)] = rec;
|
|
}
|
|
const catalog = [];
|
|
const seen = new Set();
|
|
for (const [packKey, entry] of Object.entries(mappings || {})) {
|
|
const rec = byAnyKey[normalizeRepoUrl(packKey)];
|
|
if (!rec || rec.info.state !== "disabled") continue;
|
|
const list = entry && entry[0];
|
|
if (!Array.isArray(list)) continue;
|
|
const title = rec.info.title || rec.dir;
|
|
for (const ct of list) {
|
|
const dedup = rec.dir + " |