Files
SatadalAI-SATA_UtilityNode/web/prompt_machine.js
T
2025-08-31 19:31:38 +05:30

30 lines
1.5 KiB
JavaScript

import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "SATA_UtilityNode.PromptMachine",
async nodeCreated(node) {
if (node.comfyClass === "Prompt_Machine") {
// When csv_file changes, refresh names list
const widget = node.widgets.find(w => w.name === "csv_file");
if (widget) {
widget.callback = async (value) => {
try {
const resp = await fetch(`/sata/prompt_machine/names?csv=${encodeURIComponent(value)}`);
const data = await resp.json();
const names = Array.isArray(data.names) && data.names.length > 0 ? data.names : ["None"];
const nameWidget = node.widgets.find(w => w.name === "name");
if (nameWidget) {
if (!nameWidget.options) nameWidget.options = {};
nameWidget.options.values = names;
nameWidget.value = names[0];
if (typeof node.setDirtyCanvas === "function") node.setDirtyCanvas(true);
if (typeof node.onWidgetChanged === "function") node.onWidgetChanged(nameWidget, nameWidget.value, null, 0);
}
} catch (e) {
console.error("[PromptMachine] Failed to fetch names:", e);
}
};
}
}
}
});