Auto-detect output types (INT, FLOAT, STRING) on dynamic node refresh
API route now returns types alongside keys. JS sets output slot type accordingly, giving correct colored dots and type-safe connections. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -76,8 +76,20 @@ if PromptServer is not None:
|
||||
seq = 1
|
||||
data = read_json_data(json_path)
|
||||
target = get_batch_item(data, seq)
|
||||
keys = list(target.keys()) if isinstance(target, dict) else []
|
||||
return web.json_response({"keys": keys})
|
||||
keys = []
|
||||
types = []
|
||||
if isinstance(target, dict):
|
||||
for k, v in target.items():
|
||||
keys.append(k)
|
||||
if isinstance(v, bool):
|
||||
types.append("STRING")
|
||||
elif isinstance(v, int):
|
||||
types.append("INT")
|
||||
elif isinstance(v, float):
|
||||
types.append("FLOAT")
|
||||
else:
|
||||
types.append("STRING")
|
||||
return web.json_response({"keys": keys, "types": types})
|
||||
|
||||
|
||||
# ==========================================
|
||||
|
||||
@@ -40,7 +40,7 @@ app.registerExtension({
|
||||
const resp = await api.fetchApi(
|
||||
`/json_manager/get_keys?path=${encodeURIComponent(pathWidget.value)}&sequence_number=${seqWidget?.value || 1}`
|
||||
);
|
||||
const { keys } = await resp.json();
|
||||
const { keys, types } = await resp.json();
|
||||
|
||||
// Update output_keys widget for Python to read at execution time
|
||||
const okWidget = this.widgets?.find(w => w.name === "output_keys");
|
||||
@@ -54,14 +54,18 @@ app.registerExtension({
|
||||
|
||||
// Build new outputs, reusing existing slots to preserve links
|
||||
const newOutputs = [];
|
||||
for (const key of keys) {
|
||||
for (let k = 0; k < keys.length; k++) {
|
||||
const key = keys[k];
|
||||
const type = types[k] || "*";
|
||||
if (key in oldSlots) {
|
||||
// Reuse existing slot object (keeps links intact)
|
||||
newOutputs.push(this.outputs[oldSlots[key]]);
|
||||
const slot = this.outputs[oldSlots[key]];
|
||||
slot.type = type;
|
||||
newOutputs.push(slot);
|
||||
delete oldSlots[key];
|
||||
} else {
|
||||
// New key — create a fresh slot
|
||||
newOutputs.push({ name: key, type: "*", links: null });
|
||||
newOutputs.push({ name: key, type: type, links: null });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user