import json _DEFAULT_BEAT = "Describe this beat." _DEFAULT_STATE = {"beats": [{"text": _DEFAULT_BEAT}]} def _clone_default_state(): return {"beats": [{"text": _DEFAULT_BEAT}]} def _parse_beat_prompt_state(value): if isinstance(value, dict): raw = value else: text = str(value or "").strip() if not text: return _clone_default_state() try: raw = json.loads(text) except Exception: return _clone_default_state() beats = [] for item in list(raw.get("beats") or []): if isinstance(item, dict): text = str(item.get("text") or "") else: text = str(item or "") beats.append({"text": text}) if not beats: return _clone_default_state() return {"beats": beats} def _assemble_beat_prompt(state): parsed = _parse_beat_prompt_state(state) chunks = [] for beat in parsed["beats"]: text = str(beat.get("text") or "").strip() if text: chunks.append(text) return "\n\n".join(chunks) class DumasH3BeatPromptNode: DESCRIPTION = ( "Build a MiniMax H3 prompt from one textbox per beat, with a front-end beat " "editor that can append directive examples such as wardrobe, seconds, exit, and music." ) RETURN_TYPES = ("STRING",) RETURN_NAMES = ("prompt",) FUNCTION = "build_prompt" CATEGORY = "Dumas/MiniMax" @classmethod def INPUT_TYPES(cls): return { "required": {}, "hidden": { "H3BeatPromptState": ("STRING", {"default": json.dumps(_DEFAULT_STATE)}), }, } def build_prompt(self, H3BeatPromptState=""): return (_assemble_beat_prompt(H3BeatPromptState),) NODE_CLASS_MAPPINGS = { "DumasH3BeatPrompt": DumasH3BeatPromptNode, } NODE_DISPLAY_NAME_MAPPINGS = { "DumasH3BeatPrompt": "Dumas H3 Beat Prompt", } __all__ = [ "DumasH3BeatPromptNode", "NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "_assemble_beat_prompt", "_parse_beat_prompt_state", ]