HEL-892: pin AudioCrop and GuHai split reference contracts

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
leefer
2026-10-30 03:44:25 +08:00
co-authored by multica-agent
parent b30ea8917d
commit 9fb77d5360
23 changed files with 5143 additions and 25 deletions
@@ -18,6 +18,10 @@ REEL_PROFILE = "comfy-frontend-1.37.11-layerstyle-mixed-core-0.4.0-reference"
MEDIA_PROFILES = (MP3_PROFILE, REEL_PROFILE)
SEPARATION_PROFILE = "comfy-frontend-1.37.11-audio-separation-1.4.0-core-mixed-reference"
CROP_PROFILE = "comfy-frontend-1.37.11-audio-crop-1.4.0-core-0.3.68-reference"
SPLIT_PROFILE = "comfy-frontend-1.37.11-guhai-885cac3d-core-0.21.1-reference"
CROP_SPLIT_PROFILES = (CROP_PROFILE, SPLIT_PROFILE)
ASR_PROFILE = "comfy-frontend-1.37.11-asr-b037d7be-reference"
PROFILE = "comfy-frontend-1.37.11-core-reference"
AUX_PROFILE = "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference"
@@ -88,7 +92,7 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
"output": outputs,
}
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE):
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
return media_definitions(profile)
if profile == ASR_PROFILE:
definitions = reference_definitions(PREVIEW_PROFILE)
@@ -162,7 +166,7 @@ def reference_definitions(profile: str = PROFILE) -> dict[str, Any]:
def serialize_reference_widgets(node: dict[str, Any], profile: str = PROFILE) -> dict[str, Any]:
"""Apply only the pinned identity serializers; reject any extra/missing value."""
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE):
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
return serialize_media_node(node, profile)
if profile == ASR_PROFILE:
if any(k in node for k in ("widgets", "widgets_values_named", "serializeValue")):
@@ -1039,6 +1043,16 @@ _MEDIA_LAYOUTS = {
"LoadAudio": (("audio", str),),
"SaveAudioMP3": (("filename_prefix", str), ("quality", str)),
"PreviewAudio": (),
"AudioCrop": (("start_time", str), ("end_time", str)),
"GuHaiAutoImageSplit": (
("保存目录", str),
("水平张数", int),
("垂直张数", int),
("移除画布边缘", bool),
("移除描边", int),
("文件名前缀", str),
("保存格式", str),
),
"AudioSeparation": (
("chunk_fade_shape", str),
("chunk_length", float),
@@ -1073,6 +1087,32 @@ def media_definitions(profile):
"output": outputs,
}
if profile == SPLIT_PROFILE:
definitions = reference_definitions(PROFILE)
return {
"LoadImage": definitions["LoadImage"],
"PreviewImage": definitions["PreviewImage"],
"GuHaiAutoImageSplit": spec(
{
"图像": "IMAGE",
"保存目录": "STRING",
"水平张数": "INT",
"垂直张数": "INT",
"移除画布边缘": "BOOLEAN",
"移除描边": "INT",
"文件名前缀": "STRING",
"保存格式": "COMBO",
},
["IMAGE"],
),
}
if profile == CROP_PROFILE:
definitions = media_definitions(SEPARATION_PROFILE)
del definitions["SaveAudioMP3"]
definitions["AudioCrop"] = spec(
{"audio": "AUDIO", "start_time": "STRING", "end_time": "STRING"}, ["AUDIO"]
)
return definitions
if profile == SEPARATION_PROFILE:
definitions = media_definitions(MP3_PROFILE)
definitions["PreviewAudio"] = spec({"audio": "AUDIO"}, [], {"audioUI": "AUDIO_UI"})
@@ -1132,7 +1172,7 @@ def serialize_media_node(node, profile):
raise ValueError("节点类型/模式不在媒体固定参考契约内")
if any(k in node for k in ("widgets", "widgets_values_named", "serializeValue")):
raise ValueError("媒体参考不支持自定义控件/serializer覆盖")
if profile == SEPARATION_PROFILE:
if profile in (SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
if type(node.get("mode", 0)) is not int:
raise ValueError("音频分离参考模式必须为整数0")
ue = props.get("ue_properties") or {}
@@ -1145,9 +1185,21 @@ def serialize_media_node(node, profile):
type(output["slot_index"]) is not int or output["slot_index"] != slot
):
raise ValueError("音频分离输出槽索引冲突")
if profile in CROP_SPLIT_PROFILES:
output_names = {
"AudioCrop": ["AUDIO"],
"LoadAudio": ["AUDIO"],
"PreviewAudio": [],
"AudioSeparation": ["Bass", "Drums", "Other", "Vocals"],
"LoadImage": ["IMAGE", "MASK"],
"PreviewImage": [],
"GuHaiAutoImageSplit": ["分割图像"],
}[ct]
if [s.get("name") for s in node.get("outputs", [])] != output_names:
raise ValueError("源输出槽/名称与固定参考契约不符")
provider = (
"audio-separation-nodes-comfyui"
if ct == "AudioSeparation"
if ct in ("AudioSeparation", "AudioCrop")
else ("comfyui_layerstyle" if ct.startswith("LayerUtility:") else "comfy-core")
)
version = (
@@ -1156,8 +1208,13 @@ def serialize_media_node(node, profile):
"PreviewAudio": "0.3.68",
"SaveAudioMP3": "0.3.71",
"AudioSeparation": "1.4.0",
"AudioCrop": "1.4.0",
}[ct]
if profile == SEPARATION_PROFILE
if profile in (SEPARATION_PROFILE, CROP_PROFILE)
else "885cac3dd323d26a77b69ae904a9a344f0dee7d0"
if ct == "GuHaiAutoImageSplit"
else "0.21.1"
if profile == SPLIT_PROFILE
else _REEL_VERSION
if ct == "LayerUtility: ImageReel"
else _COMPOSIT_VERSION
@@ -1166,10 +1223,18 @@ def serialize_media_node(node, profile):
if profile == MP3_PROFILE
else "0.4.0"
)
if ct == "GuHaiAutoImageSplit":
if props.get("aux_id") != "goohai/Goohaitools-comfyui" or props.get("cnr_id") is not None:
raise ValueError("GuHai要求精确aux_id且无未经证明的cnr_id")
provider_key, provider = "aux_id", "goohai/Goohaitools-comfyui"
else:
provider_key = "cnr_id"
if profile in CROP_SPLIT_PROFILES and props.get("aux_id") is not None:
raise ValueError("参考节点含未证明的额外提供方声明")
# Audio has neither declaration; allow absence only in this labeled profile.
if any(
props.get(k) != v and not (profile == MP3_PROFILE and props.get(k) is None)
for k, v in (("cnr_id", provider), ("ver", version))
for k, v in ((provider_key, provider), ("ver", version))
):
raise ValueError("媒体节点提供方/版本与固定参考冲突")
layout = _MEDIA_LAYOUTS[ct]
@@ -1202,6 +1267,14 @@ def serialize_media_node(node, profile):
"exponential",
):
raise ValueError("AudioSeparation chunk_fade_shape静态枚举不符")
if ct == "GuHaiAutoImageSplit":
# The plugin declares only minimums. 2048 is the pinned frontend's
# default UI maximum, not a plugin/server bound. Never clamp/round.
for name, low in (("水平张数", 1), ("垂直张数", 1), ("移除描边", 0)):
if not low <= result[name] <= 2048:
raise ValueError(f"{name}超出固定参考UI边界")
if result["保存格式"] not in ("PNG", "JPG"):
raise ValueError("GuHai保存格式静态枚举不符")
if ct == "SaveAudioMP3" and result["quality"] not in ("V0", "128k", "320k"):
raise ValueError("MP3 quality静态枚举不符")
if ct == "LayerUtility: ImageReelComposit" and result["color_theme"] not in ("light", "dark"):
@@ -1227,7 +1300,9 @@ def serialize_media_node(node, profile):
sockets = node.get("inputs", [])
if len(sockets) != len(slots) or {s.get("name") for s in sockets} != set(slots):
raise ValueError("媒体输入槽缺失/重复/额外")
if profile == SEPARATION_PROFILE and [s.get("name") for s in sockets] != list(slots):
if profile in (SEPARATION_PROFILE, *CROP_SPLIT_PROFILES) and [
s.get("name") for s in sockets
] != list(slots):
raise ValueError("音频分离参考输入/控件构造顺序不符")
for socket in sockets:
name = socket["name"]
@@ -17,6 +17,7 @@ from .serialization_reference import (
ASR_PROFILE,
AUX_PROFILE,
CASE04_PROFILE,
CROP_SPLIT_PROFILES,
MEDIA_PROFILES,
PREVIEW_PROFILE,
PRIMITIVE_PROFILE,
@@ -63,6 +64,7 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
ASR_PROFILE,
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
AUX_PROFILE,
PRIMITIVE_PROFILE,
PREVIEW_PROFILE,
@@ -126,11 +128,11 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
and (source.get("extra") or {}).get("frontendVersion") != "1.37.11"
):
raise ValueError("PreviewAny 需要显式1.37.11前端声明")
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE) and any(
if profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES) and any(
node.get("type") == "Reroute" for node in source.get("nodes", [])
):
raise ValueError("媒体最小参考仅覆盖直接连线,不扩展虚拟节点")
if profile == SEPARATION_PROFILE and any(
if profile in (SEPARATION_PROFILE, *CROP_SPLIT_PROFILES) and any(
(source.get("extra") or {}).get(k) for k in ("ue_links", "links_added_by_ue")
):
raise ValueError("音频分离参考不覆盖UE附加连线")
@@ -145,7 +147,7 @@ def convert_reference(source: Any, profile: str = PROFILE) -> Conversion:
except (ValueError, TypeError, KeyError, AttributeError, IndexError) as exc:
return Conversion(None, [{"code": "invalid_reference_contract", "message": str(exc)}], True)
result.reference_only = True
if profile in (ASR_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE):
if profile in (ASR_PROFILE, *MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
result.serialization_stage = "restored_saved_state_before_queue_hooks"
return result
@@ -226,7 +228,7 @@ def _convert(
for lid in links:
try:
resolve_reference_link(nodes, links, lid)
if reference_profile in (*MEDIA_PROFILES, SEPARATION_PROFILE):
if reference_profile in (*MEDIA_PROFILES, SEPARATION_PROFILE, *CROP_SPLIT_PROFILES):
link = links[lid]
upstream = nodes[str(link[1])]["outputs"][link[2]]
downstream = nodes[str(link[3])]["inputs"][link[4]]
@@ -284,6 +286,7 @@ def _convert(
ASR_PROFILE,
*MEDIA_PROFILES,
SEPARATION_PROFILE,
*CROP_SPLIT_PROFILES,
)
and ct == "LoadAudio"
):