const fs = require("fs"); const flowPath = "docker/demo-flow.json"; const flow = JSON.parse(fs.readFileSync(flowPath, "utf8")); let newFlow = flow.filter(n => n.id !== "demo_dbg_reactor_inspect"); const reactor = newFlow.find(n => n.id === "demo_reactor"); reactor.wires[0] = reactor.wires[0].filter(id => id !== "demo_dbg_reactor_inspect"); reactor.kla = 70; newFlow.push({ id: "demo_dbg_reactor_inspect", type: "function", z: "demo_tab_treatment", name: "Reactor State Inspector", func: 'if (msg.topic !== "GridProfile") return null;\nconst p = msg.payload;\nif (!p || !p.grid) return null;\nconst now = Date.now();\nif (global.get("lastInspect") && now - global.get("lastInspect") < 5000) return null;\nglobal.set("lastInspect", now);\nconst profile = p.grid.map((row, i) => "cell" + i + "(" + (i*p.d_x).toFixed(0) + "m): NH4=" + row[3].toFixed(2) + " DO=" + row[0].toFixed(2));\nnode.warn("GRID: " + profile.join(" | "));\nreturn null;', outputs: 1, x: 840, y: 320, wires: [[]] }); reactor.wires[0].push("demo_dbg_reactor_inspect"); fs.writeFileSync(flowPath, JSON.stringify(newFlow, null, 2) + "\n"); console.log("kla:", reactor.kla, "X_A_init:", reactor.X_A_init);