Files
BlackVortexAI-bv_nodepack/js/bv_pipe.js
T
BlackVortexAI 6f6514ed54 Add BV Pipe and Config Node implementation for dynamic pipelines
Features include:
- `bv_pipe_shared.js`: common logic for managing UI state and propagation.
- `bv_pipe.js` and `bv_pipe_config.js`: client-side node handlers for ComfyUI.
- `bv_pipe.py` and `bv_pipe_config.py`: backend node definitions and execution logic.
- Dynamic input/output slots up to 100, with fallback and propagation handling.
- Integration with upstream configurations for seamless pipeline updates.
2025-12-20 12:38:24 +01:00

60 lines
1.9 KiB
JavaScript

// bv_pipe.js
import { app } from "../../scripts/app.js";
import {
defer,
refreshPipeNodeFromUpstream,
resolveCfgByPipeLinksNoCache,
getCfgFromNodeWithFallback,
updatePipeNodeUI,
} from "./bv_pipe_shared.js";
/**
* Returns true if the node has NO connections at all.
* We use this to "collapse" new nodes to only the pipe input/output,
* but do NOT touch nodes loaded from a workflow that already have links.
*/
function isCompletelyUnconnected(node) {
// Any input linked?
const hasInputLinks = (node.inputs || []).some((inp) => inp?.link != null);
// Any output linked?
const hasOutputLinks = (node.outputs || []).some((out) => (out?.links?.length || 0) > 0);
return !hasInputLinks && !hasOutputLinks;
}
app.registerExtension({
name: "bv_nodepack.bv_pipe",
async nodeCreated(node) {
if (node.comfyClass !== "BV Pipe") return;
// 1) Immediately collapse NEW nodes (no connections) to only show pipe in/out
// This runs after the node is created so we can inspect connections safely.
defer(() => {
if (isCompletelyUnconnected(node)) {
// shrink to 0 dynamic slots -> leaves only "pipe" input/output
updatePipeNodeUI(node, { namesRaw: "", names: [], count: 0 });
}
});
// 2) Initial apply on workflow load:
// - If connected, prefer resolving upstream config.
// - If disconnected but cached, use fallback.
defer(async () => {
const cfg = resolveCfgByPipeLinksNoCache(node) || getCfgFromNodeWithFallback(node);
if (cfg) updatePipeNodeUI(node, cfg);
});
// 3) Refresh on pipe connect
const orig = node.onConnectionsChange;
node.onConnectionsChange = function (type, index, connected, link_info) {
orig?.call(this, type, index, connected, link_info);
// pipe input is index 0
if (type === 1 && index === 0 && connected) {
defer(() => refreshPipeNodeFromUpstream(node));
}
};
},
});