Files
DemonGatanjieu-Anomalous_Mo…/web/modules/node_parameter_sets.js
T
DemonGatanjieuandClaude Opus 5.5 1d02d5b74d Remove the Material Library page; Prompts opens Prompt Studio
The page held four unrelated things, so each now lives where it is used:
the rail's Prompts entry (and the Ctrl+Shift+L shortcut) opens Prompt
Studio beside the canvas, where saved prompts are managed; the browser
comes back when the studio closes. Saved node values stay in Current
node, which can now delete them; moved whole workflows are no longer
offered there twice. Recent results, combos and whole workflows already
have their own homes.

Deleted ui_materials.js, ui_material_cards.js, ui_material_detail.js,
ui_material_application.js (its receipt is ui_apply_receipt.js) and
material_feedback.js, the recipe page's copy-to-library buttons and the
save_parameter_material route, with about 2,000 lines of CSS and 200 locale
keys. Words that said "material library" now say where things go.
Material files are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 22:59:35 +08:00

118 lines
5.7 KiB
JavaScript

/**
* The saved parameters for a node type, as one list: material blocks
* (GET /anomalous/materials/by_node_type) and recipes' parameter sets
* (GET /anomalous/parameters/by_node_type), with the same values saved twice merged into
* one entry that names both sources. For a live node, what an entry would change: every
* differing value, except seeds and how they change after a run, model files (the model
* section changes those) and choices this computer does not have, which stay. No DOM.
*/
import { applyNodeMaterialValues, isModelFilePath, isVolatileWidget } from './node_material_actions.js';
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
async function fetchJson(url, signal) {
const response = await fetch(url, { cache: 'no-store', signal });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
}
/**
* [{ name, role, timestamp, values, sources: [{ kind: 'material' | 'recipe', label }] }],
* newest first.
*/
export async function loadParameterSets(type, { signal } = {}) {
const query = `type=${encodeURIComponent(type)}`;
const [materials, recipes] = await Promise.all([
fetchJson(`/anomalous/materials/by_node_type?${query}`, signal),
fetchJson(`/anomalous/parameters/by_node_type?${query}`, signal),
]);
const entries = new Map();
const add = (values, entry) => {
if (!Array.isArray(values) || !values.length) return;
const key = JSON.stringify(values);
const known = entries.get(key);
if (!known) entries.set(key, { ...entry, values });
else {
known.sources.push(...entry.sources);
known.timestamp = Math.max(known.timestamp, entry.timestamp);
}
};
for (const material of materials.materials || []) {
const blocks = material.blocks || [];
for (const block of blocks) {
add(block.widgets_values, {
name: blocks.length > 1 ? `${material.name} · ${block.title || block.type}` : material.name,
role: block.role || '',
timestamp: material.timestamp || 0,
sources: [{ kind: 'material', label: material.name, filename: material.filename }],
});
}
}
for (const group of recipes.groups || []) {
const recipe = String(group.recipe_name || group.recipe_filename || '');
// Sets not bound to a recipe, or whose recipe is gone (only its file name is left).
if (group.recipe_filename === 'unbound' || recipe.endsWith('.json')) continue;
for (const notebook of group.notebooks || []) {
const nodes = notebook.nodes || [];
for (const node of nodes) {
add(node.widgets_values, {
name: nodes.length > 1 ? `${notebook.name} · ${node.title}` : notebook.name,
role: node.role || '',
timestamp: notebook.timestamp || 0,
sources: [{ kind: 'recipe', label: recipe }],
});
}
}
}
return [...entries.values()].sort((a, b) => b.timestamp - a.timestamp);
}
/**
* What putting `values` into `node` would change: [{ index, label, from, to, keep }], keep
* being '' for a change that is made, or why the value stays: 'seed' | 'model' | 'missing'.
*/
export function parameterChanges(node, values) {
const changes = [];
values.forEach((to, index) => {
const widget = node.widgets?.[index];
if (!widget || to === undefined || to === null || same(widget.value, to)) return;
if (widget.value != null && typeof widget.value !== typeof to) return; // not the same input
const choices = Array.isArray(widget.options?.values) ? widget.options.values : null;
const keep = isVolatileWidget(node, widget, index) || widget.name === 'control_after_generate' ? 'seed'
: isModelFilePath(to) || isModelFilePath(widget.value) ? 'model'
: choices && !choices.includes(to) ? 'missing' : '';
changes.push({ index, label: widget.label || widget.name || `#${index}`, from: widget.value, to, keep });
});
return changes;
}
/** Puts the changes that are made into the node; the undoable result of node_material_actions. */
export function applyParameterChanges(app, node, changes) {
return applyNodeMaterialValues(app, node, changes.filter(change => !change.keep).map(({ index, to }) => ({ index, value: to })));
}
/** Saves the node's current values as a material; { status: 'success' | 'duplicate', name }. */
/** Deletes saved values (a material file, with any other nodes saved with them) to the Recycle Bin. */
export async function deleteSavedValues(filename) {
const response = await fetch('/anomalous/delete_material', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filename }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
}
export async function saveNodeParameters(node, name) {
const values = node.serialize?.().widgets_values || node.widgets_values || (node.widgets || []).map(widget => widget.value);
const response = await fetch('/anomalous/save_node_material', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, node: { type: node.type, title: node.title || node.type, widgets_values: values } }),
});
const payload = await response.json().catch(() => ({}));
if (payload.status === 'success') return { status: 'success', name: payload.material?.name || name };
if (payload.status === 'duplicate') return { status: 'duplicate', name: payload.name };
throw new Error(payload.message || `HTTP ${response.status}`);
}