From 9ff76dd8ab5cc7e85fdd7c53c84a30bfb833cec7 Mon Sep 17 00:00:00 2001 From: Jason Hoku Date: Thu, 7 May 2026 09:55:49 -0700 Subject: [PATCH] feat: add POST /configbuilder/preview endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both runtime (generate_config) and preview now invoke state_to_configs_json — single source of truth, drift-proof. The Builder UI will fetch this endpoint instead of running a parallel JS transformer (next commit removes that JS code). Co-Authored-By: Claude Opus 4.7 (1M context) --- config_builder_node.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config_builder_node.py b/config_builder_node.py index 483bab5..850e8da 100644 --- a/config_builder_node.py +++ b/config_builder_node.py @@ -1331,5 +1331,27 @@ async def save_lora_triggers_endpoint(request): print(f"[ConfigBuilder] ✏️ Saved {len(triggers)} trigger words for: {normalized}") return web.json_response({"status": "saved", "lora_name": normalized, "triggers": triggers}) + except Exception as e: + return web.json_response({"error": str(e)}, status=500) + + +@server.PromptServer.instance.routes.post("/configbuilder/preview") +async def preview_endpoint(request): + """ + Preview endpoint — runs state_to_configs_json on the POSTed builder UI + state and returns the resulting configs_json string. The Builder UI's + JSON Preview panel calls this. Single source of truth: this endpoint and + generate_config() share state_to_configs_json, so they cannot disagree. + """ + try: + body = await request.json() + state = body.get("state") + if not isinstance(state, dict): + return web.json_response( + {"error": "Missing or invalid 'state' object in request body"}, + status=400, + ) + configs_json = UltimateConfigBuilder.state_to_configs_json(state) + return web.json_response({"configs_json": configs_json}) except Exception as e: return web.json_response({"error": str(e)}, status=500) \ No newline at end of file