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:
2026-02-23 16:11:30 +01:00
parent dfab5e12ab
commit f5e242950d
2 changed files with 22 additions and 6 deletions

View File

@@ -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 });
}
}