* feat(nodes): per-node Save to library switch (#90) Every PromptManager node (Classic, Text, Focused, Split, Pair) gets an optional save_to_library BOOLEAN, default on and declared last. Off, the node still returns its normal outputs but PromptManager ignores the run: - the node saves, counts, tracks and records nothing; - the queue hook reads the switch from the queued graph (literal, or a linked PrimitiveBoolean), so a cached node is not counted either; a switch wired from an unreadable node is left to the node itself; - an opted-out node is no run prompt, so no tracker entry, run key, embedded-metadata match or history attribution links its images, and a run with any opted-out positive node links none of its files; - the scan reports such files as not_saved (never stored or queued for Needs review), and a file whose only opted-out node is its negative is stored positive-only, without the pair; - execution history records no prompt text for an opted-out role. PromptSearchList only reads the library and gets no switch. The switch takes the widget index older workflows used for the editor's own DOM slot (''), so a configure step turns any non-boolean value on: workflows saved before the switch load with it on and no earlier widget value moves. The Focused, Split and Pair editors draw it as a "Save to library" checkbox in their toolbar; Classic and Text show the native toggle. * fix(nodes): Save to library review fixes (#90) - A switch wired from a node the graph cannot read and off at run time marks the node's run key, so an earlier run's tracker entry never links this run's images. - The scan reports such files as not_saved_wired ("only the run itself can link it") instead of not_saved. - Workflow-only metadata ignores muted and bypassed PromptManager nodes and reads nodes inside subgraph definitions. - The Focused, Split and Pair footer says when the switch comes from a link. * fix(usage): count cached re-runs of runtime-linked prompt text (#347) A PromptManager-family node whose text comes from a runtime link (PreviewAny, an LLM, a list node) counted only the job that executed it; later jobs served from ComfyUI's output cache counted nothing. Each execution now records a receipt (digests of its STRING outputs and hashes of the text it stores) per run key and queue item. On execution_cached the receipt whose digests equal the cache entry's text is replayed once for the job, with the node's role and what the queue hook already saw recomputed from the job's own graph. The executing node and the replay count through one shared own_counts. Unmatched cache entries count nothing, as before; a node that executes after its replay in the same job skips its own count. No schema change, no backfill. * fix(usage): never replay a node twice in one job; dedupe receipts once complete (#347) A repeated execution_cached id or message for the same job now counts the node once. Receipts replace equal older ones only when their job finishes (or the next job starts), so a list still recording [A] of [A, B] no longer drops an older [A] receipt. Node-level tests check the receipt each execution records. * test(coverage): baseline for the Save to library module (#90) * test(usage): disabled node then cached jobs counts 0 (#90, #347) A PromptManager node with Save to library off records no cached-run receipt and is no run prompt in the replayed job's graph, so ComfyUI serving it from its cache on later jobs counts nothing. The prompt is saved first by an enabled run, so a replayed count would show. Covers PromptManager, Focused, Split, Text and the Pair. * fix(nodes): hide the editor's native widgets through one helper (#90) The Save to library switch copied the text fallbacks' zero-height computeSize arrow, and neither copy was ever called, so focused-node.js function coverage fell to 87.5 (floor 90). One hideNativeWidget helper now hides both, and the spec checks that the hidden switch and a text fallback take no node height.
48 lines
2.0 KiB
JavaScript
48 lines
2.0 KiB
JavaScript
// #90: a PromptManager node's `save_to_library` switch. Off: PromptManager ignores the node's runs (nothing saved,
|
|
// counted or linked); the node's output is unchanged.
|
|
//
|
|
// The input is declared last, so it takes the widget index an older workflow used for the editor's own
|
|
// (non-serialized) DOM widget, where it stored `''` or nothing. ComfyUI coerces a BOOLEAN with `bool(value)`, so that
|
|
// `''` would turn saving off: after a workflow loads, anything that is not a boolean is the default, on.
|
|
|
|
export const SAVE_WIDGET = 'save_to_library';
|
|
|
|
export function saveWidget(node) {
|
|
return node?.widgets?.find(widget => widget?.name === SAVE_WIDGET);
|
|
}
|
|
|
|
/** Whether the node saves its runs (a missing widget, as on an older backend, is on). */
|
|
export function savesToLibrary(node) {
|
|
return saveWidget(node)?.value !== false;
|
|
}
|
|
|
|
/** Set a non-boolean switch value (from an older workflow) to on. Returns whether it changed. */
|
|
export function normalizeSaveWidget(node) {
|
|
const widget = saveWidget(node);
|
|
if (!widget || typeof widget.value === 'boolean') return false;
|
|
widget.value = true;
|
|
const index = node.widgets.indexOf(widget);
|
|
if (Array.isArray(node.widgets_values) && index >= 0) node.widgets_values[index] = true;
|
|
return true;
|
|
}
|
|
|
|
/** Move the switch after every other widget the node has now, so its index is the same on every frontend. */
|
|
export function placeSaveWidgetLast(node) {
|
|
const widget = saveWidget(node);
|
|
const widgets = node?.widgets;
|
|
if (!widget || widgets.at(-1) === widget) return false;
|
|
widgets.splice(widgets.indexOf(widget), 1);
|
|
widgets.push(widget);
|
|
return true;
|
|
}
|
|
|
|
/** Turn the switch on or off the way a native widget edit does. */
|
|
export function setSaveToLibrary(node, value) {
|
|
const widget = saveWidget(node);
|
|
if (!widget) return;
|
|
widget.value = Boolean(value);
|
|
const index = node.widgets.indexOf(widget);
|
|
if (Array.isArray(node.widgets_values) && index >= 0) node.widgets_values[index] = widget.value;
|
|
widget.callback?.(widget.value, undefined, node);
|
|
}
|