js_internals_prompt - chrisgoringe/Comfy-Custom-Node-How-To GitHub Wiki
The prompt object
The prompt object is the thing that gets sent by the JavaScript to the backend server.
Getting the prompt
The relevant call is the async function
app.graphToPrompt();
So to see what the prompt would be for the current workflow, you can await it:
const p = structuredClone(await app.graphToPrompt());
I'm not sure if the structuredClone
is essential, but doing it ensures that if you do make changes they are only to your copy, not to any underlying objects - and since the underlying code may change in future releases, it's better to be safe.
If you want to change the prompt that gets sent, then hijack this call
async setup() {
/*
The graphToPrompt method is called when the app is going to send a prompt to the server.
We hijack it, call the original, and return a modified copy.
*/
_original_graphToPrompt = app.graphToPrompt;
app.graphToPrompt = async function () {
const p = StructuredClone(await _original_graphToPrompt.apply(app));
// edit p
return p;
}
What's in the prompt?
As always, the best answer is to add a breakpoint in your browser code inspector and take a look!
p
contains two things: p.output
and p.workflow
.
p.output
A list of all nodes indexed by node_id, containing the values of all the inputs to the node. Yes, a list of the inputs is in an object called output
. Go figure.
p.output[node_id].class_type // string of the unique name of the node class (from the python)
p.output.inputs[input_name] // the value of the widget
// OR a list indicating the node this input is connected to [node_id_as_string, output_slot]
// OR undefined for unconnected input
p.workflow
The workflow.
p.workflow.config // not sure - seems to be empty
p.workflow.extra // not sure - seems to be empty
p.workflow.groups // a list of groups
p.workflow.groups[n].bounding // list length 4 for the bounding box - I think its [x,y,w,h] in the current view
.color
.font_size
.title
p.workflow.last_link_id // the highest numbered link in the links list (below)
p.workflow.last_node_id // the highest numbered node in the nodes list (below)
p.workflow.links // a list of links, each of which is a list containing:
// [link_id, source_node_id, source_node_output_slot, destination_node_id, destination_node_input_slot, type]
// type is a string, the rest are integers
p.workflow.nodes // a list of nodes (see below)
p.workflow.version // current value 0.4
node = p.workflow.nodes[n]
node.flags // dunno
node.id // id (as an integer)
node.mode // 0 = ALWAYS, 1 = ON_EVENT, 2 = NEVER, 3 = ON_TRIGGER, 4 = BYPASSED (I've only seen 0 and 4 in Comfy)
node.order // position in execution order (zero index)
node.outputs // the outputs
node.outputs[n].links // array of integers which correspond to the link_id in p.workflow.links
.name
.slot_index
.type
node.pos // position (relative to current view, I think)
node.properties // I've only seen 'Node node for S&R'
node.size // size!
node.type // string of the unique name of the node class (from the python)
node.widgets_values // array of the value of the widgets