From 28b5b751a665fe47a026eb1c8222ab83ce859360 Mon Sep 17 00:00:00 2001 From: ukr8b3g-cmyk Date: Mon, 10 Aug 2026 19:56:07 +0900 Subject: [PATCH] Release V2.1.5 UI serialization stability fix --- CHANGELOG.md | 11 + INSTALL_JA.txt | 6 +- MANIFEST.sha256 | 35 +-- PACKAGE_INFO_JA.txt | 2 +- PACKAGE_VALIDATION.txt | 8 +- constants.py | 7 +- docs/V2_1_5_UI_SERIALIZATION_STABILITY.md | 20 ++ metadata.ini | 2 +- pyproject.toml | 4 +- tests/test_v214_ui_simplification.py | 32 --- tests/test_v215_ui_serialization.py | 133 +++++++++ tests/test_v2_registration.py | 13 +- tests/test_v2_seam.py | 18 ++ v2/decoder.py | 7 +- v2/nodes.py | 8 +- v2/seam_guard.py | 18 ++ v2/sequence.py | 2 + version.py | 2 +- web/h3_continuum_v2.js | 329 +++++++++++++++++----- web/h3_continuum_v214.js | 204 -------------- 20 files changed, 508 insertions(+), 353 deletions(-) create mode 100644 docs/V2_1_5_UI_SERIALIZATION_STABILITY.md delete mode 100644 tests/test_v214_ui_simplification.py create mode 100644 tests/test_v215_ui_serialization.py delete mode 100644 web/h3_continuum_v214.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 69cd521..a4f7e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 2.1.5 + +- Restore compact Individual Clip Overrides and Advanced accordions without removing or reordering backend slots. +- Add `Seam Correction: Auto / Off / Basic` and make guarded Auto the new-node default. +- Consolidate the Sampler V2 frontend behavior into one extension wrapper. +- Preserve backend widget type, serialization behavior, and relative widget order. +- Keep all backend input and output slots registered instead of removing and re-adding them. +- Collapse advanced widgets only through computeSize and DOM display state. +- Add static widget-order and workflow-value mapping regressions for UI serialization stability. + + ## 2.1.4 - Rename the public package and repository branding to ComfyUI-H3-Continuum. diff --git a/INSTALL_JA.txt b/INSTALL_JA.txt index 00de5c3..d9d0d74 100644 --- a/INSTALL_JA.txt +++ b/INSTALL_JA.txt @@ -1,4 +1,4 @@ -ComfyUI-H3-Continuum 2.1.4 — インストール +ComfyUI-H3-Continuum 2.1.5 — インストール 1. ComfyUIを終了します。 2. ZIPを展開します。 @@ -35,12 +35,12 @@ CLIP / Video VAE / Audio VAE / Sampler / Sigmas - exact_total_duration: true - diagnostics: Basic - strict_compatibility: true -- seam_correction: Off(2.0.2互換)/ Basic(初期値、V2.1境界補正) +- seam_correction: Auto(初期値)/ Off(2.0.2互換)/ Basic(常時V2.1境界補正) Prompt入力: - Sequence PromptへComfyUI標準のText (Multiline)を1本接続します。 - Prompt FormatはAuto / Fixed / List / Timelineから選択します。 -- Clip N Prompt Overrideは必要なチャンクだけ個別上書きする高度設定です。 +- Clip N Prompt Overrideは個別上書き用です。内部slot順を維持し、展開時はchunks数まで表示します。 生成中サムネイル: - Settings > H3 Continuum > Preview > Show latent preview diff --git a/MANIFEST.sha256 b/MANIFEST.sha256 index c8a160a..3b4d36c 100644 --- a/MANIFEST.sha256 +++ b/MANIFEST.sha256 @@ -1,14 +1,16 @@ 10da5e25dc84ddc7086d181b47466dc2a197c98958d60e4352605a2a3211ee1c .github/workflows/tests.yml +10da5e25dc84ddc7086d181b47466dc2a197c98958d60e4352605a2a3211ee1c .github/workflows/tests.yml 85eada29c12706d55b78e4d8100899d1dadde4d9867406b8bac4eec22b81c6b6 .gitignore dca65fb1393e67f59c6f81f9411e3e745eb8f1097e9a2adf7ffc6f4e3901ca9f __init__.py 0005be4e1e56a88d5b2168dc3fe203d5f87944922aa400d87e8c840805d2a4e1 AGENTS.md -1f5ef91be4bc93d3ccc0f65ace033e602a9957e8bc71bd6f107907f13e19c554 CHANGELOG.md +59acf85415443af8ba38370128a3ff8af1740049a3ba35d6898ad12e998c417c CHANGELOG.md 7dbbc8ce1018d6ac07c53eaa40f2d8d144babf9c6fe6bd94b7ec1d08adffa215 compatibility.py -f2bed7eb89e79018a0620a204d0ba9072b1c7bf66a457e68372c1bffedde947e constants.py +a88d873af14b69988963b52bb57681445ee45bd4e60ab47073909a46ac5891bd constants.py 28e9f211d53668b929e80b9b65ade03879467db0804d95eafd73f4b3929a510b continuation.py c93a3e52e4deabe5ef0db7f34a7605856a543089574ba17227e697e9a2c0139a docs/ARCHITECTURE.md 7660570840229b6fcbe62f0fbb52966d0099d64d7e6f01a739fbf9899293c8e4 docs/FUTURE_ROADMAP.md 90acddd795d84c5a24f79598670aec1655eaf58d45fd6d362dc758e2b880a071 docs/V2_1_4_UI_SIMPLIFICATION.md +ef3af02d3c8fb5fd41f33a94287112962d4c0024ebdd7a8becb041fc18d9dd2e docs/V2_1_5_UI_SERIALIZATION_STABILITY.md f0806bb2b999794ddda072e98424dbd1b613df1cd8a096b12d979f124e066d8a docs/VALIDATION_JA.md 6771c9905d35666121c4892d2ec26202505f96d244ce814ad9a87a02878952cd examples/H3_CONTINUUM_V1_WIRING.md f85ba3c69a473f0ac4bb96895c6d6532e8270121da65f858e364b19d31f05ef5 examples/H3_Continuum_V2_3x5s.json @@ -17,19 +19,19 @@ f85ba3c69a473f0ac4bb96895c6d6532e8270121da65f858e364b19d31f05ef5 examples/H3_Co 5a26408c770381cdb259cb710de7dab12d7ddecca262bdbf35ba1566056050f5 examples/recommended_settings_v2.json b8275c8cecde12aee0418cea456d1e7f4b875cbb1bce32f1f3d9e06a44dd0be1 examples/v2_prompt_list_example.txt 0e59ea821081cb93165aa3f88c6949736dd225837fe1cdcf1173aa5cd54c6d29 examples/v2_prompt_timeline_example.txt -6fb8d3bc2a9d92def1cded8eb3dea9b7f030d84c66f740554ef0ec823f7716b5 INSTALL_JA.txt +ffabbfbb34d24085bf65a94d0b879654cff8cb8ea3d141c10e1b8f9af0ac5660 INSTALL_JA.txt 10c26a052ae8ee8f6fa9168971b92e27da9f0b838cfaf64170e228fbb8e131fa install_windows.bat c0f1ccebc07cbee0159a2e0fd04683f5725d54e30edd386759e6964b46d84308 install_windows.ps1 600634455576c58a79e4919603af0fdeb80478f64e3a3de5969a95383957c4b5 layout_adapter.py 3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986 LICENSE d3e213005670e94dee33a240349a4d245cf9a3b6602099f11ed30cf5a32e2c21 media.py -3eff2c77728a41504f2f1099013263d61c84ede88722e877112caa3b9811623c metadata.ini +f305dbc4a96221f2c5bc7102b43e5fbe4ac4b5622634ffc0deb444b1297bc4fa metadata.ini 43fc9e66a96adb9f5c6b653118e48cd5f5c3366dd3e7fc970d2500023bd5cc55 model_patch.py a905ef1f536543af0f7b0de98da1c4daa618063364bc49ecb9bd4e1aafaf2b22 nodes.py -ba433db7925447d00060912fde663ea80fe6070a07ec5d637a1ade48aae735d1 PACKAGE_INFO_JA.txt -f60ac51fde0bba2030e882ee6e42bda9d59bef691014ff411e1ed88dedcca43b PACKAGE_VALIDATION.txt +64b8826837053fc5767a71ccb9551a53fd711abdfa23a1b4232ccb6d29621943 PACKAGE_INFO_JA.txt +dee53deb806384e1c9933347f78bc1652aaf21da0c8336095048ada0948969cc PACKAGE_VALIDATION.txt b470819f16fc179654dc1600721a63f0a5a14e777f4c004d574b499da6886ba5 public_api.py -4ba931010a436dc19c99ec7919e84e17d65796bb78a094fe9193563af635691f pyproject.toml +092e2959098b74ef38eb5d6f53262c669d067e0f554a0de43edf4d1d52e2ddab pyproject.toml 94fdc2d545b2d4077a4d70229fd22ba3ccac21d49d1097d2873f76d04e9a3c7a pytest.ini a9e0b523ecbd503f6f75e9f3f79d28d66564ef0930548c1ad9d70b89772a240f README.md 568d480e5abd494e1364477c67b5c3b6af8c2a3662d015a50557e23b34e48020 README_JA.md @@ -48,29 +50,28 @@ d4c53d2c260b635d70fa211029d608f63776e0a56c20253475fa47c58363f8a7 tests/test_sta 58c06925ccf06c4feee19b927b3515c540c0536aa5f3f8d29be35b8e919915a7 tests/test_temporal.py 912661d91c7f11f5fcaf0bd14d7d3ecf5c74c33b1507272f0ae72af6e5bffa6f tests/test_v2_decoder.py 07dff078ab3826da44e3147f22642d616eb82f472d558badcaaf20137eb7e47c tests/test_v2_prompts.py -f2f25b3e1972b8ad1ad7725eb52bd6687d01ea8b2fa268d89e1fa643c873e9ab tests/test_v2_registration.py -c31a8b67c8fde268497905206e2888bf380ad20c8f3a1aea8b2af96853d38a2e tests/test_v2_seam.py +3561cf0174317de812f6a0ef2dfe69cb4247ae12fa4efc2b5f412ab5282b261a tests/test_v2_registration.py +687fed96f73d848ad776d21139bfcce20abb359b7567d7b2c8d8af4ef8159174 tests/test_v2_seam.py 74e623120a963cb96b68651b44f47a836ea8449d30ce89d749c71ffad4766d4e tests/test_v2_seeds_motion.py c55aa93ae8edb23441fe80b0673d045ac3538c9a8698cddbd970b1fec8452b68 tests/test_v2_sequence_orchestration.py a6e200c21036521383a838070f2fd6e822e1928d06c0fab52b52cc01f64951bb tests/test_v2_session.py 58438c3ed814adf40cefde098a37cae00ddcb703b7e5548bbbb295e54bed5a6d tests/test_v2_widget_migration.py -2a8caaa3680ed2cca1a4f7000d1c5d377973b62f0237496467068c7d6b3dc87b tests/test_v214_ui_simplification.py +9286c14fa84d581184ad65c42801180179a7c7efb8e6ef9ff6f536f9cb526af0 tests/test_v215_ui_serialization.py 0dbe8a5f71c92f3523942343b40787104c8b96781461ba3ba82934a6bdbe5834 THIRD_PARTY_NOTICES.md dbf44a536c550e0cdffc01f8c3725b1b9af60dbeb16f45ff735f5d682276d389 tools/verify_runtime.py ffd61f3f31c9b6430e1169007ee906c8f5000eba63ee44e2976ad4f5f1112671 v2/__init__.py -566bb88932c2ae8dd560ee8b373d92354956c99b1f7338528e89a277fa68b9ea v2/decoder.py +52d9a5a469b3419ed3ed4fc1eb13448e2969252732023650935bdefa8446c777 v2/decoder.py c1da9e58e12cafea6ad380f7045abdc61a106657e2e191d3afe03f2844c670b3 v2/diagnostics.py 5543ec570f18f1d97327ffcf07f9eeaf078e7c7d3b3d722559d65a19d11dcb84 v2/h3_builder.py aea01a48a8c03a25ed97ea05e5b137f89e388832d1be7d38f2da2be3d1b9830b v2/motion.py -0281aa305d3baf5f081ccd8433a80d7d5da7d6513a05114c133daaafd7eb56c2 v2/nodes.py +5e6b694291d544b6a2f057a04cc29c534c9df6e8f6347d7b918c9b2c7592e946 v2/nodes.py 66058170e37eb3ac03f2428120f3b69ce7cff4789cd3fc4d00f991c61f6786d5 v2/prompts.py 4080f1875b958b316e8e76852c4be5527a6de5c71d604e7642d3098478eb4a36 v2/sampling.py -8ad3e0843d574a10f5124649783a74362daa0af579b264a6dab4fd3c992c2f5d v2/seam_guard.py +9261525777716ea71cc72ae06c1174acb9f7004016ee6f14fa3b89969f108e1b v2/seam_guard.py d2b9020491e2a1e113cac72f8d129eacfc24c51507b53e9a0bf9f66da965bdad v2/seam_types.py 12cfcc0c71ca087fe39a5ce2922959a62b2bb311bfe664f05c4480affce03708 v2/seeds.py -e4367b946f0f968f685867f7d7bee8476ec15601631d935e17aa0912ac6ccf9e v2/sequence.py +2f45074ab563f22289b65145a87fca66ffb25bfa4b88d19adad97260aea04e9f v2/sequence.py af89216e549f0a549340645a401b5dccc6aefb73e9f4cbc5e02285117ae46b3a v2/session.py f3a94dfd2adbc97e2747941d5e50ab07b8b572e9f2684b9e3e827d78dfed86fa v2/session_io.py -f7c25f96f9d5dcd9b6e4a6c5ee3529f203603cbe0202d84e90f377f67ad70902 version.py -b6058bb77d404ce115b10427371bb1d5cfe9a08efd120fbf9364228f9f4d6223 web/h3_continuum_v2.js -b7307568b96ce10bf471d6183c8fc1d920594f0a8f3f307840f281200ef416a2 web/h3_continuum_v214.js +f0a3910918986ddb01c816848027c5e462f57eb032ad618e64876b83f586f4fc version.py +9a0e87debfc8892fcc9a890d68877626d82f2debcfe89975c3f7233ffeab32c1 web/h3_continuum_v2.js diff --git a/PACKAGE_INFO_JA.txt b/PACKAGE_INFO_JA.txt index 3ef4171..f833dae 100644 --- a/PACKAGE_INFO_JA.txt +++ b/PACKAGE_INFO_JA.txt @@ -1,5 +1,5 @@ 名称: ComfyUI-H3-Continuum -バージョン: 2.1.4 +バージョン: 2.1.5 対象: ComfyUI native MiniMax H3 主ノード: H3 Continuum Sampler V2 ライセンス: GPL-3.0-or-later diff --git a/PACKAGE_VALIDATION.txt b/PACKAGE_VALIDATION.txt index 0075a26..f56baf1 100644 --- a/PACKAGE_VALIDATION.txt +++ b/PACKAGE_VALIDATION.txt @@ -1,4 +1,4 @@ -ComfyUI-H3-Continuum 2.1.4 — Package Validation +ComfyUI-H3-Continuum 2.1.5 — Package Validation Date: 2026-08-10 Release scope: @@ -9,7 +9,7 @@ Release scope: Completed checks: - Python bytecode syntax compilation: PASS - Python grammar compilation: PASS -- Unit and orchestration tests: PASS (70 tests) +- Unit and orchestration tests: PASS (71 tests) - Package import and node registration: PASS (10 nodes) - V1 node-ID compatibility: PASS - V1 State schema compatibility: PASS @@ -25,7 +25,7 @@ Completed checks: - V2 Sequence Prompt Auto detection and override priority: PASS - Native Continuity call-local MODEL isolation and Spectrum Interop hint emission: PASS - Basic Seam Correction and complete Off bypass: PASS -- V2.1.4 Advanced UI and Legacy-node registration checks: PASS +- V2.1.5 frontend serialization stability and Legacy-node registration checks: PASS - Deterministic per-chunk seed and reroll derivation: PASS - Conservative Auto-context selection: PASS - Session validation, branch-safe reuse, and V1 State extraction: PASS @@ -36,7 +36,7 @@ Completed checks: - Shared MODEL / shared conditioning-cache orchestration test: PASS - V2 2.0.0 malformed widget-serialization migration regression: PASS - Example V2 3x5s workflow structural validation: PASS (17 nodes, 20 links) -- Repository manifest regenerated after all V2.1.4 files: PASS +- Repository manifest regenerated after all V2.1.5 files: PASS Runtime verifier included: - tools/verify_runtime.py checks the installed ComfyUI native H3 API. diff --git a/constants.py b/constants.py index 9427c36..a0881e8 100644 --- a/constants.py +++ b/constants.py @@ -69,6 +69,11 @@ DIAGNOSTICS_BASIC = "Basic" DIAGNOSTICS_FULL = "Full" DIAGNOSTICS_OPTIONS = (DIAGNOSTICS_BASIC, DIAGNOSTICS_FULL, DIAGNOSTICS_OFF) +SEAM_CORRECTION_AUTO = "Auto" SEAM_CORRECTION_OFF = "Off" SEAM_CORRECTION_BASIC = "Basic" -SEAM_CORRECTION_OPTIONS = (SEAM_CORRECTION_OFF, SEAM_CORRECTION_BASIC) +SEAM_CORRECTION_OPTIONS = ( + SEAM_CORRECTION_AUTO, + SEAM_CORRECTION_OFF, + SEAM_CORRECTION_BASIC, +) diff --git a/docs/V2_1_5_UI_SERIALIZATION_STABILITY.md b/docs/V2_1_5_UI_SERIALIZATION_STABILITY.md new file mode 100644 index 0000000..000a51a --- /dev/null +++ b/docs/V2_1_5_UI_SERIALIZATION_STABILITY.md @@ -0,0 +1,20 @@ +# V2.1.5 UI Serialization Stability + +V2.1.5 preserves the backend-defined Sampler V2 widget and slot structure. +The frontend may change labels, computed height, and DOM/slot visibility only. + +## Stability contract + +- Backend widget type, serialization behavior, and relative order are unchanged. +- Backend inputs and outputs are never removed or re-added for UI folding. +- Individual Clip Overrides and Advanced buttons are appended non-serialized frontend widgets. +- Prompt and advanced sockets remain registered in stable order while collapsed slots are hidden visually. +- onNodeCreated and onConfigure are wrapped by one Sampler V2 extension only. + +This release does not change Sampling, State, Session, Prompt Plan, Spectrum Interop, or project schemas. + +## Browser regression + +Set chunks=2, chunk_seconds=5.0, width=1344, height=768, Balanced 22 frames, Seam Correction Auto, and a fixed seed. +Open and close Individual Clip Overrides and Advanced settings, change tabs, save, reload ComfyUI, and reload the workflow. +All values and connections must remain in their original slots. diff --git a/metadata.ini b/metadata.ini index ab514ef..e349bac 100644 --- a/metadata.ini +++ b/metadata.ini @@ -1,4 +1,4 @@ [project] name = H3 Continuum -version = 2.1.4 +version = 2.1.5 description = Integrated native MiniMax H3 long-video continuation with V1 compatibility and external SageAttention, Sol-Attn and Spectrum composition. diff --git a/pyproject.toml b/pyproject.toml index ff01929..08cc2f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "comfyui-h3-continuum" -version = "2.1.4" +version = "2.1.5" description = "Integrated N-chunk continuation for ComfyUI native MiniMax H3 video and audio" readme = "README.md" requires-python = ">=3.10" @@ -14,5 +14,5 @@ Repository = "https://github.com/ukr8b3g-cmyk/ComfyUI-H3-Continuum" [tool.comfy] PublisherId = "ukr8b3g-cmyk" -DisplayName = "H3 Continuum Join" +DisplayName = "H3 Continuum" Icon = "" diff --git a/tests/test_v214_ui_simplification.py b/tests/test_v214_ui_simplification.py deleted file mode 100644 index 5cec01e..0000000 --- a/tests/test_v214_ui_simplification.py +++ /dev/null @@ -1,32 +0,0 @@ -from pathlib import Path - - -ROOT = Path(__file__).resolve().parents[1] - - -def test_v214_frontend_collapses_advanced_controls_without_reordering_outputs(): - source = (ROOT / "web" / "h3_continuum_v214.js").read_text(encoding="utf-8") - - assert 'const ADVANCED_PROPERTY = "h3_show_advanced"' in source - assert '["last_frame", "IMAGE"]' in source - assert '["prompt_plan", "H3_CONTINUUM_PROMPT_PLAN"]' in source - assert '["last_state", "H3_CONTINUUM_STATE"]' in source - assert "hasAdvancedConnection(node)" in source - assert "removeUnlinkedAdvancedSlots(node)" in source - assert "Advanced Settings ▸" in source - assert "placeAdvancedButton(node, button, expanded)" in source - - -def test_all_non_primary_nodes_use_native_comfyui_deprecation(): - source = (ROOT / "nodes.py").read_text(encoding="utf-8") - - assert 'if _node_id == "H3ContinuumSamplerV2"' in source - assert "_node_class.DEPRECATED = True" in source - assert 'f"{CATEGORY}/Legacy"' in source - assert 'f"[Legacy] {_display_name}"' in source - - -def test_v214_version_metadata_matches(): - assert 'PACKAGE_VERSION = "2.1.4"' in (ROOT / "version.py").read_text(encoding="utf-8") - assert "version = 2.1.4" in (ROOT / "metadata.ini").read_text(encoding="utf-8") - assert 'version = "2.1.4"' in (ROOT / "pyproject.toml").read_text(encoding="utf-8") diff --git a/tests/test_v215_ui_serialization.py b/tests/test_v215_ui_serialization.py new file mode 100644 index 0000000..1af6974 --- /dev/null +++ b/tests/test_v215_ui_serialization.py @@ -0,0 +1,133 @@ +import json +from pathlib import Path + +from ComfyUI_H3_Continuum_Join.v2.nodes import H3ContinuumSamplerV2 + + +ROOT = Path(__file__).resolve().parents[1] + +SERIALIZED_WIDGET_ORDER = [ + "prompt_mode", + "prompt_script", + "chunks", + "chunk_seconds", + "width", + "height", + "continuity", + "base_seed", + "control_after_generate", + "audio_continuity", + "exact_total_duration", + "diagnostics", + "reroll_from_chunk", + "reroll_nonce", + "strict_compatibility", + "debug", + "seam_correction", + "show_preview", +] + + +def test_v215_frontend_preserves_backend_serialization_structure(): + source = (ROOT / "web" / "h3_continuum_v2.js").read_text(encoding="utf-8") + assert not (ROOT / "web" / "h3_continuum_v214.js").exists() + for forbidden in ( + 'widget.type = "converted-widget"', + 'widget.type = "hidden"', + "node.widgets.splice(", + "node.removeInput(", + "node.addInput(", + "node.removeOutput(", + "node.addOutput(", + ): + assert forbidden not in source + assert "setWidgetCollapsed" in source + assert "placeTransientAfter" in source + assert "serializedBefore.every" in source + assert "slotVisibilityRules" in source + assert "node.removeInput(" not in source + assert "node.addInput(" not in source + assert "node.removeOutput(" not in source + assert "node.addOutput(" not in source + assert "node.widgets.splice(" not in source + assert "ensureSeamCorrectionProxy" in source + assert "Individual Clip Overrides" in source + assert "button.serialize = false" in source + assert 'name: "H3Continuum.V215StableInterface"' in source + assert source.count("nodeType.prototype.onNodeCreated = function") == 1 + assert source.count("nodeType.prototype.onConfigure = function") == 1 + + +def test_v215_backend_widget_order_and_workflow_values_remain_aligned(): + required = H3ContinuumSamplerV2.INPUT_TYPES()["required"] + assert list(required)[6:] == [ + "prompt_mode", + "prompt_script", + "chunks", + "chunk_seconds", + "width", + "height", + "continuity", + "base_seed", + "audio_continuity", + "exact_total_duration", + "diagnostics", + "reroll_from_chunk", + "reroll_nonce", + "strict_compatibility", + "debug", + "seam_correction", + ] + values = [ + "Auto", + "Preserved fallback prompt", + 2, + 5.0, + 1344, + 768, + "Balanced — 22 frames", + 123456789, + "fixed", + True, + True, + "Basic", + 0, + 0, + True, + False, + "Auto", + True, + ] + mapped = dict(zip(SERIALIZED_WIDGET_ORDER, values, strict=True)) + assert mapped["chunks"] == 2 + assert mapped["chunk_seconds"] == 5.0 + assert mapped["width"] == 1344 + assert mapped["height"] == 768 + assert mapped["continuity"] == "Balanced — 22 frames" + assert mapped["base_seed"] == 123456789 + assert mapped["seam_correction"] == "Auto" + + data = json.loads((ROOT / "examples" / "H3_Continuum_V2_3x5s.json").read_text(encoding="utf-8")) + node = next(item for item in data["nodes"] if item["type"] == "H3ContinuumSamplerV2") + legacy_values = node["widgets_values"] + legacy = dict(zip(SERIALIZED_WIDGET_ORDER[:16], legacy_values, strict=True)) + assert legacy["chunks"] == 3 + assert legacy["chunk_seconds"] == 5.0 + assert legacy["width"] == 1344 + assert legacy["height"] == 768 + assert legacy["continuity"] == "Balanced — 22 frames" + assert legacy["base_seed"] == 123456789 + + +def test_all_non_primary_nodes_use_native_comfyui_deprecation(): + source = (ROOT / "nodes.py").read_text(encoding="utf-8") + assert 'if _node_id == "H3ContinuumSamplerV2"' in source + assert "_node_class.DEPRECATED = True" in source + assert 'f"{CATEGORY}/Legacy"' in source + assert 'f"[Legacy] {_display_name}"' in source + + +def test_v215_version_metadata_matches(): + assert 'PACKAGE_VERSION = "2.1.5"' in (ROOT / "version.py").read_text(encoding="utf-8") + assert "version = 2.1.5" in (ROOT / "metadata.ini").read_text(encoding="utf-8") + assert 'version = "2.1.5"' in (ROOT / "pyproject.toml").read_text(encoding="utf-8") diff --git a/tests/test_v2_registration.py b/tests/test_v2_registration.py index 049f52c..140dd93 100644 --- a/tests/test_v2_registration.py +++ b/tests/test_v2_registration.py @@ -3,7 +3,7 @@ from pathlib import Path from ComfyUI_H3_Continuum_Join.nodes import NODE_CLASS_MAPPINGS from ComfyUI_H3_Continuum_Join.constants import ( PROMPT_FORMAT_OPTIONS, - SEAM_CORRECTION_OFF, + SEAM_CORRECTION_AUTO, ) @@ -43,14 +43,15 @@ def test_v2_sampler_registers_preview_setting_bridge_and_sixteen_prompt_inputs() assert prompt_input[1]["forceInput"] is True -def test_v2_sampler_defaults_to_the_legacy_seam_path(): +def test_v2_sampler_defaults_to_auto_seam_correction(): schema = NODE_CLASS_MAPPINGS["H3ContinuumSamplerV2"].INPUT_TYPES() - assert schema["required"]["seam_correction"][1]["default"] == SEAM_CORRECTION_OFF + assert schema["required"]["seam_correction"][1]["default"] == SEAM_CORRECTION_AUTO -def test_v2_interface_keeps_sequence_socket_and_collapsible_overrides(): +def test_v2_interface_keeps_sequence_socket_and_stable_override_slots(): root = Path(__file__).resolve().parents[1] source = (root / "web" / "h3_continuum_v2.js").read_text(encoding="utf-8") assert 'const SEQUENCE_PROMPT_INPUT = "sequence_prompt"' in source - assert "Individual Clip Overrides" in source - assert "!inputIsConnected(input)" in source + assert "syncPromptInputs(node)" in source + assert "node.removeInput(" not in source + assert "node.addInput(" not in source diff --git a/tests/test_v2_seam.py b/tests/test_v2_seam.py index 0d66b67..33d1903 100644 --- a/tests/test_v2_seam.py +++ b/tests/test_v2_seam.py @@ -43,6 +43,24 @@ def test_corrected_cut_preserves_the_total_frame_count(): assert corrected_total == legacy_total +def test_auto_keeps_a_clean_legacy_video_boundary(): + previous = _frames([0.2, 0.2, 0.2, 0.2]) + current = _frames([0.2, 0.2, 0.2, 0.2]) + + corrected, decision, patch = correct_seam( + previous, + current, + context_frames=2, + automatic=True, + ) + + assert torch.equal(corrected, current[2:]) + assert decision.cut_rewind_frames == 0 + assert decision.corrected_score == decision.legacy_score + assert decision.fallback_reason.startswith("Auto kept the legacy video seam") + assert patch is None + + def test_high_motion_disables_video_blend(): metrics = VideoSeamMetrics( pixel_mae_norm=0.1, diff --git a/v2/decoder.py b/v2/decoder.py index fe8c99d..c2a6443 100644 --- a/v2/decoder.py +++ b/v2/decoder.py @@ -227,8 +227,9 @@ def decode_sequence_with_seam( video_vae: Any, audio_vae: Any, diagnostics_mode: str, + automatic: bool = False, ) -> tuple[torch.Tensor, dict[str, Any], list[str]]: - """Decode with V2.1 Basic correction while preserving legacy output length.""" + """Decode with guarded V2.1 correction while preserving legacy output length.""" if not entries: raise ValueError("cannot decode an empty Continuum sequence") @@ -275,6 +276,7 @@ def decode_sequence_with_seam( image_buffer[:frame_cursor], limited_raw_images, context_frames=trim_frames, + automatic=automatic, ) frame_start = frame_cursor - int(decision.cut_rewind_frames) trim_frames -= int(decision.cut_rewind_frames) @@ -385,7 +387,8 @@ def decode_sequence_with_seam( audio = {"waveform": audio_buffer.contiguous(), "sample_rate": audio_rate} reports.append( f"assembled {len(entries)} chunks into {total_retained_frames} frames with " - "V2.1 Basic seam correction and cumulative sample-boundary alignment" + f"V2.1 {'Auto' if automatic else 'Basic'} seam correction and " + "cumulative sample-boundary alignment" ) return image_buffer.contiguous(), audio, reports diff --git a/v2/nodes.py b/v2/nodes.py index 9bc201e..28f8af7 100644 --- a/v2/nodes.py +++ b/v2/nodes.py @@ -8,6 +8,7 @@ from ..constants import ( DIAGNOSTICS_OPTIONS, PROMPT_FORMAT_OPTIONS, PROMPT_MODE_OPTIONS, + SEAM_CORRECTION_AUTO, SEAM_CORRECTION_OFF, SEAM_CORRECTION_OPTIONS, V2_CONTINUITY_OPTIONS, @@ -198,10 +199,11 @@ class H3ContinuumSamplerV2: "seam_correction": ( SEAM_CORRECTION_OPTIONS, { - "default": SEAM_CORRECTION_OFF, + "default": SEAM_CORRECTION_AUTO, "tooltip": ( - "Off preserves the V2.0.2 decode path. Basic applies " - "conservative decoded A/V boundary correction." + "Auto keeps the legacy video boundary unless the guarded candidate " + "improves it. Off preserves the V2.0.2 decode path. Basic always runs " + "the conservative decoded A/V boundary correction." ), }, ), diff --git a/v2/seam_guard.py b/v2/seam_guard.py index c8a50e6..3fd9ed7 100644 --- a/v2/seam_guard.py +++ b/v2/seam_guard.py @@ -271,6 +271,7 @@ def correct_seam( next_raw_images: torch.Tensor, *, context_frames: int, + automatic: bool = False, ) -> tuple[torch.Tensor, SeamDecision, torch.Tensor | None]: rewind, legacy, selected = choose_adaptive_cut( previous_images, @@ -317,6 +318,23 @@ def correct_seam( None, ) + absolute_improvement = legacy.score - corrected.score + if automatic and ( + improvement < MIN_RELATIVE_IMPROVEMENT + or absolute_improvement < MIN_ABSOLUTE_IMPROVEMENT + ): + fallback = next_raw_images[int(context_frames) :].clone().contiguous() + return ( + fallback, + SeamDecision( + legacy_score=legacy.score, + cut_score=selected.score, + corrected_score=legacy.score, + fallback_reason="Auto kept the legacy video seam; improvement was below threshold", + ), + None, + ) + decision = SeamDecision( cut_rewind_frames=rewind, legacy_score=legacy.score, diff --git a/v2/sequence.py b/v2/sequence.py index bb587c6..41e0c4d 100644 --- a/v2/sequence.py +++ b/v2/sequence.py @@ -21,6 +21,7 @@ from ..constants import ( DIAGNOSTICS_OPTIONS, FPS, CONTINUUM_ACTUAL_PREFIX_STEPS, + SEAM_CORRECTION_AUTO, SEAM_CORRECTION_OFF, SEAM_CORRECTION_OPTIONS, V2_CONTINUITY_AUTO, @@ -467,6 +468,7 @@ def run_sequence( video_vae=video_vae, audio_vae=audio_vae, diagnostics_mode=diagnostics_mode, + automatic=seam_correction == SEAM_CORRECTION_AUTO, ) duration_report = "" if exact_total_duration: diff --git a/version.py b/version.py index bf4f5f6..a65932c 100644 --- a/version.py +++ b/version.py @@ -1,6 +1,6 @@ """Package version and public schema identifiers.""" -PACKAGE_VERSION = "2.1.4" +PACKAGE_VERSION = "2.1.5" STATE_SCHEMA_VERSION = 1 PLAN_SCHEMA_VERSION = 1 PUBLIC_API_VERSION = 2 diff --git a/web/h3_continuum_v2.js b/web/h3_continuum_v2.js index 8082b66..d68241d 100644 --- a/web/h3_continuum_v2.js +++ b/web/h3_continuum_v2.js @@ -4,8 +4,23 @@ const NODE_NAME = "H3ContinuumSamplerV2"; const PREVIEW_SETTING = "H3Continuum.ShowLatentPreview"; const PROMPT_INPUT = /^clip_(\d+)_prompt$/; const SEQUENCE_PROMPT_INPUT = "sequence_prompt"; -const OVERRIDE_PROPERTY = "h3_show_clip_overrides"; +const CLIP_OVERRIDES_PROPERTY = "h3_show_clip_overrides"; +const ADVANCED_PROPERTY = "h3_show_advanced"; +const ADVANCED_INPUTS = new Set(["last_frame", "session", "initial_state", "prompt_plan"]); +const ADVANCED_OUTPUTS = new Set(["last_state", "session", "report"]); const MAX_CHUNKS = 16; +const VISIBILITY_STYLE_ID = "h3-continuum-v215-slot-visibility"; +const ADVANCED_WIDGETS = new Set([ + "control_after_generate", + "audio_continuity", + "exact_total_duration", + "diagnostics", + "reroll_from_chunk", + "reroll_nonce", + "strict_compatibility", + "debug", + "show_preview", +]); const LEGACY_PROMPT_FORMATS = new Map([ ["Fixed — one prompt", "Fixed"], ["List — split with ---", "List"], @@ -14,29 +29,66 @@ const LEGACY_PROMPT_FORMATS = new Map([ let showLatentPreview = true; -function hideWidget(widget) { +function setWidgetCollapsed(widget, reason, collapsed) { if (!widget) return; - if (!widget.__h3ContinuumHidden) { - widget.__h3ContinuumHidden = true; - widget.type = "converted-widget"; - widget.computeSize = () => [0, -4]; + if (!widget.__h3ContinuumCollapseState) { + widget.__h3ContinuumCollapseState = { + computeSize: widget.computeSize, + hiddenOption: widget.options?.hidden, + reasons: new Set(), + }; } - widget.hidden = true; + const state = widget.__h3ContinuumCollapseState; + if (collapsed) { + state.reasons.add(reason); + } else { + state.reasons.delete(reason); + } + const hidden = state.reasons.size > 0; + widget.options ||= {}; + if (hidden) { + widget.options.hidden = true; + } else if (state.hiddenOption === undefined) { + delete widget.options.hidden; + } else { + widget.options.hidden = state.hiddenOption; + } + widget.computeSize = hidden ? () => [0, -4] : state.computeSize; for (const element of [widget.element, widget.inputEl, widget.el]) { - if (element?.style) element.style.display = "none"; + if (element?.style) element.style.display = hidden ? "none" : ""; } } -function promptInputName(index) { - return `clip_${index}_prompt`; +function serializableWidgets(widgets) { + return widgets.filter((widget) => widget.serialize !== false); +} + +function placeTransientAfter(node, transient, anchor) { + const original = node.widgets ?? []; + const serializedBefore = serializableWidgets(original); + const withoutTransient = original.filter((widget) => widget !== transient); + const anchorIndex = withoutTransient.findIndex((widget) => + typeof anchor === "string" ? widget.name === anchor : widget === anchor, + ); + if (anchorIndex < 0) return; + const next = [ + ...withoutTransient.slice(0, anchorIndex + 1), + transient, + ...withoutTransient.slice(anchorIndex + 1), + ]; + const serializedAfter = serializableWidgets(next); + const stable = serializedBefore.length === serializedAfter.length + && serializedBefore.every((widget, index) => widget === serializedAfter[index]); + if (!stable) throw new Error("H3 Continuum refused to reorder serialized widgets"); + node.widgets = next; } function inputIsConnected(input) { return input?.link != null || (Array.isArray(input?.links) && input.links.length > 0); } -function overridesExpanded(node) { - return node.properties?.[OVERRIDE_PROPERTY] === true; +function outputIsConnected(output) { + return Array.isArray(output?.links) && output.links.length > 0; } function syncPromptFormat(node) { @@ -53,73 +105,102 @@ function syncSequencePrompt(node) { if (input) input.label = "Sequence Prompt"; } +function clipOverridesExpanded(node) { + return node.properties?.[CLIP_OVERRIDES_PROPERTY] === true; +} + +function ensureClipOverridesButton(node) { + if (node.__h3ContinuumClipOverridesButton) { + return node.__h3ContinuumClipOverridesButton; + } + const button = node.addWidget( + "button", + "Individual Clip Overrides ▸", + null, + () => { + node.properties ||= {}; + node.properties[CLIP_OVERRIDES_PROPERTY] = !clipOverridesExpanded(node); + syncNode(node); + }, + { serialize: false }, + ); + button.serialize = false; + button.__h3ContinuumTransient = true; + node.__h3ContinuumClipOverridesButton = button; + return button; +} + function syncPromptInputs(node) { + node.properties ||= {}; + if (typeof node.properties[CLIP_OVERRIDES_PROPERTY] !== "boolean") { + node.properties[CLIP_OVERRIDES_PROPERTY] = false; + } const chunksWidget = node.widgets?.find((widget) => widget.name === "chunks"); const chunks = Math.max(1, Math.min(MAX_CHUNKS, Number(chunksWidget?.value) || 1)); - const expanded = overridesExpanded(node); - - for (let index = node.inputs.length - 1; index >= 0; index -= 1) { - const input = node.inputs[index]; + const expanded = clipOverridesExpanded(node); + for (const input of node.inputs ?? []) { const match = PROMPT_INPUT.exec(input.name); if (!match) continue; const clipIndex = Number(match[1]); - const active = clipIndex <= chunks; - if ((!expanded || !active) && !inputIsConnected(input)) { - node.removeInput(index); - } else { - input.label = active - ? "Clip " + clipIndex + " Prompt Override" - : "Clip " + clipIndex + " Override (inactive)"; - } - } - - if (!expanded) return; - for (let index = 1; index <= chunks; index += 1) { - const name = promptInputName(index); - if (!node.inputs.some((input) => input.name === name)) { - node.addInput(name, "STRING"); - } - const input = node.inputs.find((candidate) => candidate.name === name); - if (input) input.label = "Clip " + index + " Prompt Override"; + input.label = clipIndex <= chunks + ? "Clip " + clipIndex + " Prompt Override" + : "Clip " + clipIndex + " Override (inactive)"; } + const button = ensureClipOverridesButton(node); + placeTransientAfter(node, button, "prompt_mode"); + button.name = expanded + ? "Individual Clip Overrides (" + chunks + ") ▾" + : "Individual Clip Overrides (" + chunks + ") ▸"; } -function ensureOverrideToggle(node) { +function advancedExpanded(node) { + return node.properties?.[ADVANCED_PROPERTY] === true; +} + +function ensureAdvancedButton(node) { + if (node.__h3ContinuumAdvancedButton) return node.__h3ContinuumAdvancedButton; + const button = node.addWidget( + "button", + "Advanced Settings ▸", + null, + () => { + node.properties ||= {}; + node.properties[ADVANCED_PROPERTY] = !advancedExpanded(node); + syncNode(node); + }, + { serialize: false }, + ); + button.serialize = false; + button.__h3ContinuumTransient = true; + node.__h3ContinuumAdvancedButton = button; + return button; +} + +function syncAdvancedWidgets(node) { node.properties ||= {}; - if (typeof node.properties[OVERRIDE_PROPERTY] !== "boolean") { - node.properties[OVERRIDE_PROPERTY] = false; + if (typeof node.properties[ADVANCED_PROPERTY] !== "boolean") { + node.properties[ADVANCED_PROPERTY] = false; } - let widget = node.widgets?.find((candidate) => candidate.__h3OverrideToggle); - if (!widget) { - widget = node.addWidget( - "button", - "Individual Clip Overrides ▸", - null, - () => { - node.properties[OVERRIDE_PROPERTY] = !overridesExpanded(node); - syncNode(node); - }, - { serialize: false }, - ); - widget.__h3OverrideToggle = true; - widget.serialize = false; - const widgets = node.widgets || []; - const currentIndex = widgets.indexOf(widget); - const formatIndex = widgets.findIndex((candidate) => candidate.name === "prompt_mode"); - if (currentIndex >= 0 && formatIndex >= 0) { - widgets.splice(currentIndex, 1); - widgets.splice(formatIndex + 1, 0, widget); + if ( + (node.inputs ?? []).some((input) => ADVANCED_INPUTS.has(input.name) && inputIsConnected(input)) + || (node.outputs ?? []).some((output) => ADVANCED_OUTPUTS.has(output.name) && outputIsConnected(output)) + ) { + node.properties[ADVANCED_PROPERTY] = true; + } + const expanded = advancedExpanded(node); + for (const widget of node.widgets ?? []) { + if (ADVANCED_WIDGETS.has(widget.name)) { + setWidgetCollapsed(widget, "advanced", !expanded); } } - widget.name = overridesExpanded(node) - ? "Individual Clip Overrides ▾" - : "Individual Clip Overrides ▸"; + const button = ensureAdvancedButton(node); + button.name = expanded ? "Advanced Settings ▾" : "Advanced Settings ▸"; } function syncPreviewSetting(node) { const widget = node.widgets?.find((candidate) => candidate.name === "show_preview"); if (!widget) return; - hideWidget(widget); + setWidgetCollapsed(widget, "preview-setting", true); widget.value = showLatentPreview; } @@ -128,20 +209,108 @@ function repairLegacySeamCorrection(node) { if (widget && typeof widget.value === "boolean") widget.value = "Off"; } +function ensureSeamCorrectionProxy(node) { + const source = node.widgets?.find((widget) => widget.name === "seam_correction"); + if (!source) return null; + if (typeof source.value === "boolean") source.value = "Off"; + setWidgetCollapsed(source, "seam-proxy", true); + + let proxy = node.__h3ContinuumSeamProxy; + if (!proxy) { + proxy = node.addWidget( + "combo", + "Seam Correction", + source.value, + (value) => { + source.value = value; + source.callback?.call(source, value); + }, + { values: source.options?.values ?? ["Auto", "Off", "Basic"], serialize: false }, + ); + proxy.serialize = false; + proxy.__h3ContinuumTransient = true; + node.__h3ContinuumSeamProxy = proxy; + } + proxy.value = source.value; + placeTransientAfter(node, proxy, "base_seed"); + return proxy; +} + +function cssAttributeValue(value) { + return String(value).replaceAll("\\", "\\\\").replaceAll('"', '\\"'); +} + +function shouldHideInput(node, input, chunks) { + const promptMatch = PROMPT_INPUT.exec(input.name); + if (promptMatch) { + const clipIndex = Number(promptMatch[1]); + return !inputIsConnected(input) + && (!clipOverridesExpanded(node) || clipIndex > chunks); + } + return ADVANCED_INPUTS.has(input.name) + && !advancedExpanded(node) + && !inputIsConnected(input); +} + +function slotVisibilityRules(node) { + const id = cssAttributeValue(node.id); + const root = `.lg-node[data-node-id="${id}"]`; + const chunksWidget = node.widgets?.find((widget) => widget.name === "chunks"); + const chunks = Math.max(1, Math.min(MAX_CHUNKS, Number(chunksWidget?.value) || 1)); + const rules = []; + const renderedInputs = (node.inputs ?? []).filter((input) => !input.widget); + renderedInputs.forEach((input, index) => { + if (shouldHideInput(node, input, chunks)) { + rules.push(`${root} .lg-slot--input:nth-child(${index + 1}) { display: none !important; }`); + } + }); + (node.outputs ?? []).forEach((output, index) => { + if ( + ADVANCED_OUTPUTS.has(output.name) + && !advancedExpanded(node) + && !outputIsConnected(output) + ) { + rules.push(`${root} .lg-slot--output:nth-child(${index + 1}) { display: none !important; }`); + } + }); + return rules; +} + +function syncSlotVisibilityStyles() { + let style = document.getElementById(VISIBILITY_STYLE_ID); + if (!style) { + style = document.createElement("style"); + style.id = VISIBILITY_STYLE_ID; + document.head.appendChild(style); + } + style.textContent = (app.graph?._nodes ?? []) + .filter((node) => node.comfyClass === NODE_NAME || node.type === NODE_NAME) + .flatMap(slotVisibilityRules) + .join("\n"); +} + function resizeNode(node) { - const size = node.computeSize(); - node.setSize([Math.max(node.size[0], size[0]), size[1]]); + node.setSize([Math.max(node.size?.[0] ?? 0, 320), 120]); node.setDirtyCanvas(true, true); } function syncNode(node) { - hideWidget(node.widgets?.find((widget) => widget.name === "prompt_script")); + setWidgetCollapsed( + node.widgets?.find((widget) => widget.name === "prompt_script"), + "prompt-script", + true, + ); syncPromptFormat(node); syncSequencePrompt(node); - ensureOverrideToggle(node); repairLegacySeamCorrection(node); syncPromptInputs(node); + const seamProxy = ensureSeamCorrectionProxy(node); + syncAdvancedWidgets(node); + if (seamProxy) { + placeTransientAfter(node, node.__h3ContinuumAdvancedButton, seamProxy); + } syncPreviewSetting(node); + syncSlotVisibilityStyles(); resizeNode(node); } @@ -157,17 +326,24 @@ function wrapChunksWidget(node) { }; } +function scheduleSync(node) { + clearTimeout(node.__h3ContinuumSyncTimer); + node.__h3ContinuumSyncTimer = setTimeout(() => { + wrapChunksWidget(node); + syncNode(node); + }, 0); +} + function syncAllSamplerNodes() { for (const node of app.graph?._nodes || []) { if (node.comfyClass === NODE_NAME || node.type === NODE_NAME) { - syncPreviewSetting(node); - node.setDirtyCanvas(true, true); + syncNode(node); } } } app.registerExtension({ - name: "H3Continuum.V2Interface", + name: "H3Continuum.V215StableInterface", async setup() { showLatentPreview = app.ui.settings.getSettingValue(PREVIEW_SETTING) ?? true; @@ -191,20 +367,21 @@ app.registerExtension({ const originalCreated = nodeType.prototype.onNodeCreated; nodeType.prototype.onNodeCreated = function () { const result = originalCreated?.apply(this, arguments); - setTimeout(() => { - wrapChunksWidget(this); - syncNode(this); - }, 0); + scheduleSync(this); return result; }; const originalConfigure = nodeType.prototype.onConfigure; nodeType.prototype.onConfigure = function () { const result = originalConfigure?.apply(this, arguments); - setTimeout(() => { - wrapChunksWidget(this); - syncNode(this); - }, 0); + scheduleSync(this); + return result; + }; + + const originalConnectionsChange = nodeType.prototype.onConnectionsChange; + nodeType.prototype.onConnectionsChange = function () { + const result = originalConnectionsChange?.apply(this, arguments); + scheduleSync(this); return result; }; }, diff --git a/web/h3_continuum_v214.js b/web/h3_continuum_v214.js deleted file mode 100644 index 93b48fb..0000000 --- a/web/h3_continuum_v214.js +++ /dev/null @@ -1,204 +0,0 @@ -import { app } from "../../scripts/app.js"; - -const SAMPLER_NODE = "H3ContinuumSamplerV2"; -const ADVANCED_PROPERTY = "h3_show_advanced"; - -const ADVANCED_INPUTS = [ - ["last_frame", "IMAGE"], - ["session", "H3_CONTINUUM_SESSION"], - ["initial_state", "H3_CONTINUUM_STATE"], - ["prompt_plan", "H3_CONTINUUM_PROMPT_PLAN"], -]; - -const ADVANCED_OUTPUTS = [ - ["last_state", "H3_CONTINUUM_STATE"], - ["session", "H3_CONTINUUM_SESSION"], - ["report", "STRING"], -]; - -const ADVANCED_WIDGETS = new Set([ - "control_after_generate", - "audio_continuity", - "exact_total_duration", - "diagnostics", - "reroll_from_chunk", - "reroll_nonce", - "strict_compatibility", - "debug", - "show_preview", -]); - -function inputByName(node, name) { - return node.inputs?.find((input) => input.name === name); -} - -function outputByName(node, name) { - return node.outputs?.find((output) => output.name === name); -} - -function hasAdvancedConnection(node) { - const inputLinked = ADVANCED_INPUTS.some(([name]) => inputByName(node, name)?.link != null); - const outputLinked = ADVANCED_OUTPUTS.some(([name]) => { - const links = outputByName(node, name)?.links; - return Array.isArray(links) && links.length > 0; - }); - return inputLinked || outputLinked; -} - -function ensureAdvancedSlots(node) { - for (const [name, type] of ADVANCED_INPUTS) { - if (!inputByName(node, name)) { - node.addInput(name, type, { shape: 7 }); - } - } - for (const [name, type] of ADVANCED_OUTPUTS) { - if (!outputByName(node, name)) { - node.addOutput(name, type); - } - } -} - -function removeUnlinkedAdvancedSlots(node) { - if (hasAdvancedConnection(node)) { - return; - } - for (let index = (node.inputs?.length ?? 0) - 1; index >= 0; index -= 1) { - if (ADVANCED_INPUTS.some(([name]) => node.inputs[index].name === name)) { - node.removeInput(index); - } - } - for (let index = (node.outputs?.length ?? 0) - 1; index >= 0; index -= 1) { - if (ADVANCED_OUTPUTS.some(([name]) => node.outputs[index].name === name)) { - node.removeOutput(index); - } - } -} - -function setWidgetVisible(widget, visible) { - if (!widget.__h3V214Original) { - widget.__h3V214Original = { - type: widget.type, - computeSize: widget.computeSize, - hidden: widget.hidden, - }; - } - if (visible) { - widget.type = widget.__h3V214Original.type; - widget.computeSize = widget.__h3V214Original.computeSize; - widget.hidden = widget.__h3V214Original.hidden; - return; - } - widget.type = "hidden"; - widget.computeSize = () => [0, -4]; - widget.hidden = true; -} - -function ensureAdvancedButton(node) { - if (node.__h3V214AdvancedButton) { - return node.__h3V214AdvancedButton; - } - const button = node.addWidget( - "button", - "Advanced Settings ▸", - null, - () => { - node.properties ||= {}; - node.properties[ADVANCED_PROPERTY] = !node.properties[ADVANCED_PROPERTY]; - syncAdvancedUi(node); - }, - { serialize: false }, - ); - button.serialize = false; - node.__h3V214AdvancedButton = button; - return button; -} - -function placeAdvancedButton(node, button, expanded) { - const widgets = node.widgets ?? []; - const currentIndex = widgets.indexOf(button); - if (currentIndex >= 0) { - widgets.splice(currentIndex, 1); - } - if (!expanded) { - widgets.push(button); - return; - } - const firstAdvancedIndex = widgets.findIndex((widget) => ADVANCED_WIDGETS.has(widget.name)); - widgets.splice(firstAdvancedIndex >= 0 ? firstAdvancedIndex : widgets.length, 0, button); -} - -function resizeNode(node) { - const computed = node.computeSize(); - const width = Math.max(node.size?.[0] ?? 0, computed[0], 320); - node.setSize([width, computed[1]]); - node.setDirtyCanvas(true, true); -} - -function syncAdvancedUi(node) { - node.properties ||= {}; - if (typeof node.properties[ADVANCED_PROPERTY] !== "boolean") { - node.properties[ADVANCED_PROPERTY] = false; - } - if (hasAdvancedConnection(node)) { - node.properties[ADVANCED_PROPERTY] = true; - } - - const expanded = node.properties[ADVANCED_PROPERTY]; - if (expanded) { - ensureAdvancedSlots(node); - } else { - removeUnlinkedAdvancedSlots(node); - } - - for (const widget of node.widgets ?? []) { - if (ADVANCED_WIDGETS.has(widget.name)) { - setWidgetVisible(widget, expanded); - } - } - const button = ensureAdvancedButton(node); - button.name = expanded ? "Advanced Settings ▾" : "Advanced Settings ▸"; - placeAdvancedButton(node, button, expanded); - resizeNode(node); -} - -function scheduleSync(node) { - clearTimeout(node.__h3V214SyncTimer); - node.__h3V214SyncTimer = setTimeout(() => syncAdvancedUi(node), 0); -} - -app.registerExtension({ - name: "H3Continuum.V214SimplifiedUi", - beforeRegisterNodeDef(nodeType, nodeData) { - if (nodeData.name !== SAMPLER_NODE) { - return; - } - - const onNodeCreated = nodeType.prototype.onNodeCreated; - nodeType.prototype.onNodeCreated = function () { - const result = onNodeCreated?.apply(this, arguments); - this.properties ||= {}; - if (typeof this.properties[ADVANCED_PROPERTY] !== "boolean") { - this.properties[ADVANCED_PROPERTY] = false; - } - ensureAdvancedButton(this); - scheduleSync(this); - return result; - }; - - const onConfigure = nodeType.prototype.onConfigure; - nodeType.prototype.onConfigure = function () { - ensureAdvancedSlots(this); - const result = onConfigure?.apply(this, arguments); - ensureAdvancedButton(this); - scheduleSync(this); - return result; - }; - - const onConnectionsChange = nodeType.prototype.onConnectionsChange; - nodeType.prototype.onConnectionsChange = function () { - const result = onConnectionsChange?.apply(this, arguments); - scheduleSync(this); - return result; - }; - }, -});