Update js/sequence_prompt_builder.js
This commit is contained in:
@@ -3,7 +3,7 @@ import { api } from "../../scripts/api.js";
|
||||
|
||||
const CLASS = "DumasH3SequencePromptBuilder";
|
||||
// Check the browser console for this line to confirm the patched file loaded.
|
||||
console.info("[DUMAS H3] Prompt Builder v5 (upstream + executed tensor previews) loaded");
|
||||
console.info("[DUMAS H3] Prompt Builder v6 (Get/Set reference thumbnails) loaded");
|
||||
const MAX_CLIPS = 16;
|
||||
const FIXED_TEXT_WIDGETS = [
|
||||
["shared_directive", 84],
|
||||
@@ -227,14 +227,88 @@ function textareaCaretRect(textarea, position) {
|
||||
}
|
||||
|
||||
|
||||
// LiteGraph uses graph._links (Map or plain object) in current ComfyUI;
|
||||
// older builds and test harnesses may expose graph.links instead.
|
||||
function graphLink(graph, linkId) {
|
||||
if (!graph || linkId == null) return null;
|
||||
try {
|
||||
const fromGetter = graph.getLink?.(linkId);
|
||||
if (fromGetter) return fromGetter;
|
||||
} catch (_) { /* compatibility with older LiteGraph */ }
|
||||
for (const links of [graph._links, graph.links]) {
|
||||
const found = links?.get?.(linkId) ?? links?.[linkId];
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function linkedNode(node, inputName) {
|
||||
const input = node.inputs?.find((item) => item.name === inputName);
|
||||
if (input?.link == null) return null;
|
||||
const graph = node.graph || app.graph;
|
||||
const link = graph?.links?.get?.(input.link) ?? graph?.links?.[input.link];
|
||||
const link = graphLink(graph, input.link);
|
||||
return link?.origin_id == null ? null : graph?.getNodeById?.(link.origin_id);
|
||||
}
|
||||
|
||||
// KJNodes GetNode/SetNode are *virtual* relays. A Get has an output wire
|
||||
// but no matching input wire. Its Constant widget is paired to the same
|
||||
// named SetNode's Constant, which DOES have an input wire. The methods
|
||||
// below also support the KJNodes 2026 cross-subgraph naming scopes.
|
||||
function virtualGetterSources(getter, trace) {
|
||||
const type = String(getter?.type || getter?.comfyClass || "");
|
||||
if (!/^(?:GetNode|GetNode\|.*|Get\b.*)$/i.test(type)) return [];
|
||||
const name = String(getter.widgets?.find(w => w.name === "Constant" || w.name === "name")?.value
|
||||
?? getter.widgets?.[0]?.value ?? "").trim();
|
||||
if (!name) {
|
||||
trace.push({id:getter.id, type: "Get (no variable selected)"});
|
||||
return [];
|
||||
}
|
||||
const graph = getter.graph || app.graph;
|
||||
let setter = null;
|
||||
try { setter = getter.findSetter?.(graph) || getter.currentSetter || null; } catch (_) { /* fallback below */ }
|
||||
// KJNodes' findSetter already handles parent graphs. Fall back to a
|
||||
// local/parent name lookup when other packs implement the same convention.
|
||||
if (!setter) {
|
||||
const inspected = new Set();
|
||||
const graphs = [graph];
|
||||
const root = graph?.rootGraph || app.graph?.rootGraph || app.graph;
|
||||
if (root && root !== graph) graphs.push(root);
|
||||
let g = graph;
|
||||
while (g?.parentGraph && !inspected.has(g)) {
|
||||
inspected.add(g);
|
||||
g = g.parentGraph;
|
||||
graphs.push(g);
|
||||
}
|
||||
for (const candidateGraph of graphs) {
|
||||
setter = candidateGraph?._nodes?.find(n =>
|
||||
/^(?:SetNode|SetNode\|.*|Set\b.*)$/i.test(String(n.type || n.comfyClass || "")) &&
|
||||
String(n.widgets?.find(w => w.name === "Constant" || w.name === "name")?.value
|
||||
?? n.widgets?.[0]?.value ?? "").trim() === name
|
||||
);
|
||||
if (setter) break;
|
||||
}
|
||||
}
|
||||
if (!setter) {
|
||||
trace.push({id:getter.id, type:`Get \"${name}\" (Set not found)`});
|
||||
return [];
|
||||
}
|
||||
trace.push({id:setter.id, type:`Set \"${name}\"`});
|
||||
const inputs = (setter.inputs || []).filter(input => input?.link != null);
|
||||
const preferred = inputs.filter(input => /IMAGE|\*/i.test(String(input.type || "")));
|
||||
const followed = preferred.length ? preferred : inputs;
|
||||
const upstream = followed.map(input => linkedNode(setter, input.name)).filter(Boolean);
|
||||
// KJNodes GetNode exposes the already-resolved upstream link; use it
|
||||
// when a custom Set node does not expose a conventional input socket.
|
||||
if (!upstream.length) {
|
||||
try {
|
||||
const link = getter.getInputLink?.(0);
|
||||
const resolved = link?.origin_id == null ? null :
|
||||
(graph?.getNodeById?.(link.origin_id) || setter.graph?.getNodeById?.(link.origin_id));
|
||||
if (resolved) upstream.push(resolved);
|
||||
} catch (_) { /* no virtual link on this implementation */ }
|
||||
}
|
||||
return upstream;
|
||||
}
|
||||
function widgetValue(node, name) {
|
||||
return get(node, name)?.value;
|
||||
}
|
||||
@@ -324,9 +398,8 @@ function imagePreviewCandidates(source) {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
// Resolve both (a) previews returned by THIS builder after execution (exact
|
||||
// tensor from the socket), and (b) upstream previews before execution. Unlike
|
||||
// v4, the upstream search continues through resize/crop/switch/relay nodes.
|
||||
// Resolve executed tensor previews and live upstream image loader previews.
|
||||
// v6 handles virtual GetNode -> SetNode links and LiteGraph _links.
|
||||
function connectedReferenceImageCandidates(node, slot, trace = []) {
|
||||
const candidates = [];
|
||||
const add = (url) => {
|
||||
@@ -341,25 +414,33 @@ function connectedReferenceImageCandidates(node, slot, trace = []) {
|
||||
const visited = new Set();
|
||||
const first = linkedNode(node, `reference_image_${slot}`);
|
||||
const queue = first ? [{source:first, depth:0}] : [];
|
||||
while (queue.length && visited.size < 64) {
|
||||
while (queue.length && visited.size < 96) {
|
||||
const {source, depth} = queue.shift();
|
||||
const identity = source?.id ?? source;
|
||||
if (!source || visited.has(identity)) continue;
|
||||
visited.add(identity);
|
||||
// Node objects are unique even when nested graphs reuse numeric IDs.
|
||||
if (!source || visited.has(source)) continue;
|
||||
visited.add(source);
|
||||
const className = String(source.comfyClass || source.type || "Unknown");
|
||||
trace.push({id:source.id, type:className});
|
||||
for (const url of imagePreviewCandidates(source)) add(url);
|
||||
if (depth >= 16) continue;
|
||||
// Follow IMAGE sockets, so a connected resize node can fall through to
|
||||
// a file-backed LoadImage. Reroute/ANY sockets also participate.
|
||||
if (depth >= 20) continue;
|
||||
|
||||
// GetNode has no wire leading into it. Follow its matching SetNode
|
||||
// (including KJNodes parent-subgraph scoping) then the Set input.
|
||||
const virtualSources = virtualGetterSources(source, trace);
|
||||
if (virtualSources.length) {
|
||||
for (const upstream of virtualSources) queue.push({source:upstream, depth:depth+1});
|
||||
continue;
|
||||
}
|
||||
if (/^GetNode$/i.test(className)) continue; // avoid an unrelated preview
|
||||
|
||||
const inputs = (source.inputs || []).filter(input => input?.link != null);
|
||||
const imageInputs = inputs.filter(input =>
|
||||
/image|any|\*/i.test(String(input.type || "")) ||
|
||||
/image|pixels|input|source/i.test(String(input.name || "")) ||
|
||||
/reroute|switch|pipe|relay/i.test(className)
|
||||
/reroute|switch|pipe|relay|setnode/i.test(className)
|
||||
);
|
||||
const connectedInputs = imageInputs.length ? imageInputs :
|
||||
(/image|crop|resize|scale|switch|reroute|pipe/i.test(className) ? inputs : []);
|
||||
(/image|crop|resize|scale|switch|reroute|pipe|setnode/i.test(className) ? inputs : []);
|
||||
for (const input of connectedInputs) {
|
||||
const upstream = linkedNode(source, input.name);
|
||||
if (upstream) queue.push({source:upstream, depth:depth+1});
|
||||
@@ -367,7 +448,6 @@ function connectedReferenceImageCandidates(node, slot, trace = []) {
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
function refModDescriptorsForNode(node, inputName) {
|
||||
const result = [];
|
||||
const add = (name, copies = 1) => {
|
||||
|
||||
Reference in New Issue
Block a user