diff --git a/docs/hel-892/Primitive与标准子图结构参考转换.md b/docs/hel-892/Primitive与标准子图结构参考转换.md new file mode 100644 index 00000000..adecd348 --- /dev/null +++ b/docs/hel-892/Primitive与标准子图结构参考转换.md @@ -0,0 +1,92 @@ +# HEL-892 Primitive 与标准子图结构参考转换 + +本轮代码基于已审 `97f3a76f0ab5da110f4c3a7e79576627d7dedaf9`。受测代码提交 `1f779d53c4312068513c2bd6d513f01a3c9f3caf`;其后的交付提交只增加本报告、固定来源和检查证据。继续原 PR #25,分支 `agent/agent/a64a969a6a44`,base `main`。原 PR 开工时为 open、head 97f3a76;Multica 链接表为空,未重复建 PR。 + +这是参考算法增量,**不是整图可靠转换或执行验收**。生产 `convert`、库导入、registry 和 object_info 资格未放宽。本轮没有修改界面、worker、下载链或在线配置。 + +## 固定来源与适用条件 + +49 份原始源码/许可证保存在 `structure-reference/`;`sources.json` 记录每份原始 URL、完整提交、SHA256、获取时间、完整行数及重点 `rule_locations`。`source-verification.json` 是本轮按固定 raw URL 重新取回 49 份文件的哈希核验;没有安装、导入或执行上游代码。许可证原件分别随 frontend、ComfyUI、QwenASR 保存,均为 GPL v3 文本;规则在本仓库独立实现。 + +| 源图声明 | 官方 tag | API ref 返回的完整提交 | +| --- | --- | --- | +| case02 1.37.11 | v1.37.11 | 4bf6a1960028cc5cda57d48f9fb01a74dfaade43 | +| case03 1.48.7 | v1.48.7 | 6d6af63c00f132cd25dc29307fc56bd2c094fa22 | +| case04 1.53.6 | v1.53.6 | 7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1 | +| case07 1.48.6 | v1.48.6 | 7b4172a243e0d43f1679c0be1c307560cd83c00d | + +四份 `tag-*.json` 保留官方 ref 原始响应,`versions.json` 可逐项核对;`discovery.json` 保留递归源码树检索的 URL、响应摘要和 SHA。不是用当前 main 推定历史实现。源图的版本声明不证明目标安装或收件 API 的版本。 + +关键调用链(均在上表固定提交中): + +- 1.37.11 `src/extensions/core/widgetInputs.ts:43-86` 按目标输入 `widget.name` 找控件并复制 Primitive 的第一个值;`:148-214` 绑定首个目标配置,`:216-286` 构造控件及数值/combo 附加控制,`:315-365` 合并配置。`src/utils/nodeDefUtil.ts:22-31,90-143` 证明 STRING 类型合并与忽略 multiline/default/tooltip 等元数据的边界。 +- 1.37.11 `src/utils/executionUtil.ts:26-140`:先调用虚拟节点 applyToGraph,再遍历控件;检查的是 `widget.options.serialize`,不是 `widget.serialize`,随后解析实际连线。 +- 各版本 `ExecutableNodeDTO.ts` 构造器把实例路径和内部节点 ID 用 `:` 连接;1.48.7/1.53.6 的 `:106-125` 可直接核对。`resolveInput` 向外走输入边界,`_resolveSubgraphOutput` 向内走输出边界。`SubgraphNode.ts` 的 getInnerNodes 为同一定义的不同实例建立独立路径;准确位置见各文件 rule_locations。 +- 1.48.7 `LLink.ts:183-207,363-381` 明确接收列表式/对象式连线;另外两版也保存对应原件。新算法只接收这两种明确结构、标准 -10/-20 边界和非负整数局部 ID;其它形式不猜。 +- LoadAudio 使用 ComfyUI **v0.11.0** 精确 tag 的 `comfy_extras/nodes_audio.py:261-275`,frontend 1.37.11 `uploadAudio.ts:74-105,162-241` 和 `domWidget.ts:142-149,331-333,360-394`。普通文件输入、音频 DOM 与上传按钮分别处理,录音不支持。 +- QwenASR 的先前协议参考提交 3f9a652a 含新 `normalize_text`,不能套在源图的14控件上。本轮检索原仓库历史,固定更早 `b037d7be121111a1ba6f40a4d99f6b43ac6411b6` 的 `AILab_QwenASR.py:582-609,715-722` 与注册入口 `__init__.py:24-40`,覆盖14个旧控件及四个 STRING 出口。两份历史源码和检索响应均保留;不声称源图插件就是这个提交,目标/导出版本仍 unknown。 + +新 profile 显式假定这些固定版本的未修改控件构造。UE 扩展重写、动态 combo 选项是否存在、模型/媒体文件是否可用、目标前端和节点安装版本均未知。默认 core/AUX profile 没有新增 Primitive 或子图权限。 + +## 算法与失败关闭 + +`serialization_reference.py` 新增 `PRIMITIVE_PROFILE`(`comfy-frontend-1.37.11-qwen-b037d7be-reference`)。先深拷贝图并核对所有连线的双向记录;仅支持已经证明的 Qwen `hints` / `output_path` STRING 控件,按名字找固定布局位置。全部扇出目标都通过提供方/版本条件、布局、类型和输入/输出控件绑定核对后才复制值、移除虚拟节点及对应连线。数值/combo、额外 seed 控制、替换表达式、未知目标回调、经 Reroute 的 Primitive 绑定、孤儿、坏端口、冲突目标和错误模式均整图拒绝。没有从 API 反推值或字段,未增加 seed/动态执行语义。 + +LoadAudio 的参考输出保留 `audioUI: ""`:固定 frontend 的音频 DOM 只设置 `widget.serialize=false`,而 graphToPrompt 检查 `options.serialize`;DOM 无 getValue 时返回空字符串。已收 API 没有这个字段,**如实输出差异**。上传按钮则有 `options.serialize=false`,不输出。不能为了对齐收件而把这两个标记混为一谈。 + +`structure_reference.py` 是现有转换器的结构辅助模块,不是另一个执行器。显式的 1.48.7 / 1.53.6 / 1.48.6 structure profile: + +1. 验证根图和全部定义的节点/连线 ID、实例/定义槽、输入输出互指及 -10/-20 边界;缺定义、重复节点/定义/连线、递归、歧义出口、悬空和局部循环都拒绝,未使用分支也校验。 +2. 以实例路径递归展开,保留内部节点类型和原控件,不消费子图实例的位置数组;通过边界分别向外/向内追踪最终端点,保留非零槽和同一定义多实例的隔离。 +3. 边界没有外部连线时,记录具体实例/边界槽/内部节点字段到 `unresolved_boundaries`,不按 widgets_values 的位置猜 promoted widget 值。结构结果只放在 `diagnostic_graph`;未知内部节点仍逐个报错,静音/旁路有具体错误,不用“存在子图”掩盖后续缺口。 +4. 再检查展开图循环。**结构 profile 始终 prompt=None**;它没有新版内部节点序列化契约。不能把图诊断当作部分生产 prompt。 + +## 真实六份对照 + +`audit_reference_conversion.py --profile structure-batch-reference` 复用原差分函数,按声明版本选择显式 profile。报告保留 class_type、字段值与类型、端点/槽、标题差异、API 额外字段、未支持节点及未解析边界;未产生整图候选时 whole_prompt_differences 是 null,不是“整图零差异”。所有 scalar 数据仍区分源值与 API 值。 + +| case | 新参考结果 | 实际比较范围 | 仍未解决 | +| --- | --- | --- | --- | +| 01 | 原 AUX 候选保留,22节点 | 34标量、23端点/槽相同;完整JSON仍有13标题差异 | 原有版本/环境/执行未知全部保留 | +| 02 | Primitive 7 折叠到 9.hints,诊断图6节点,prompt=None | 6个 class_type相同;15标量与5连线相同;额外 audioUI空字符串差异;6标题差异 | 四个 PreviewAny;API额外 normalize_text=true;源插件/UE及目标未知 | +| 03 | 根37展开为37:*;含2注释共14节点,prompt=None | 12个非注释 class_type、16条连线一致,含35.audio→37:43[0];12标题差异 | 8个无外部线的边界控件、12节点的当前版本序列化;尤其 SeedNode/KSampler附加控制和ComfySwitchNode语义 | +| 04 | 根459展开为459:*;含2注释共18节点,prompt=None | 16个非注释 class_type、18条连线一致,含图像保存→459:457[0]及外部宽高/提示词进入内部;14标题差异 | 15个边界控件、16节点当前版本序列化;TextGenerate/缓存/开关和seed等不推定 | +| 05 | 原有失败关闭 | 仅原 root 范围18端点核对,未增加能力 | 原版本/控件缺口保留 | +| 07 | 结构校验拒绝,prompt=None | 不能声称标准结构展开成功;原根图对照仍保留39项中的33项差异/不支持 | 定义中节点241 outputs[0]引用655未互指;另有Set/Get、forLoop、模式等不在本轮规则内 | + +case02 PreviewAny 的具体验证缺口:1.37.11 `previewAny.ts:20-63` 创建两个名为 preview 的展示控件和 previewMode;源图三项为 null,而收件 API 只有 source。不能从 API 没有字段反推它们的 serializer。这里没有擅自丢控件或添加默认值;逐节点仍报 reference_node_unsupported。STRING 正文、SRT 内容或输出路径均没有被改成可下载文件。 + +03/04 上表只证明声明范围内的结构和连线;没有比较未知位置数组对应的参数值,不证明字段值/完整 JSON/动态分支等价。既有源/API 值和版本差异仍在配套说明和旧证据,本轮没有清除。 + +## 验证与复现 + +在本 checkout 设置 `PYTHONPATH=calliope-backend/src`,使用已存在的 Python 环境,无新增项目依赖: + +```bash +python calliope-backend/scripts/verify_frontend_sources.py --source-dir docs/hel-892/structure-reference --fetch --output source-verification.json +python calliope-backend/scripts/audit_reference_conversion.py --repo . --profile structure-batch-reference --output six-case-comparison.json +python -m pytest calliope-backend/tests/test_structure_reference.py calliope-backend/tests/test_controlnet_reference.py calliope-backend/tests/test_reference_serialization.py calliope-backend/tests/test_ui2api_differential.py calliope-backend/tests/test_workflow_library.py calliope-backend/tests/test_supplied_companions.py calliope-backend/tests/test_delivery_scope.py calliope-backend/tests/test_output_protocol_references.py -q +``` + +- 本次最终受测代码 `1f779d5`:**178 passed,1项第三方 Starlette 弃用警告**。含32项本轮专项、146项受影响既有回归。合成减图/嵌套图只验证算法行为,文件和测试明确标明;真实源文件与真实导出对照单列。 +- 专项覆盖字符串变化传播、名字绑定而非位置推断、扇出/类型冲突/坏绑定/额外控制/Reroute拒绝、嵌套和多实例隔离、非零槽、缺定义/重复ID/递归/歧义/悬空/局部循环拒绝、无外部线的未知边界值、mode与未知第三方继续阻断。 +- 五个改动 Python 文件 Ruff check 和 format check 通过。没有机械重跑全后台、前端或 worker;142及865/5/6仅历史记录,未称全仓全绿,未修无关基线失败。 +- `uv build --offline` 生成 wheel/sdist;包内三个转换模块与受测源码逐字节一致。最初旧环境缺 build/hatchling,改用已有 uv 的离线构建缓存完成,没有新增依赖或改锁文件。 +- 显式 AUX profile 的六份对照与上批在候选、原始差异、问题、字段、端点、未支持节点和生产状态上逐项相等,见 previous-profile-protection.json。 +- 隔离导入155/排除1、16 pending_check/139 needs_conversion;重导155 skipped。155条全停用,说明完成/执行验证时间戳全空;1217源具名值/3660位置控件/294配套值保留。源156份及原始7份API均逐字节等于已审基点,用户整行保护回归通过。记录在 import/reimport、document/companion审计摘要及protection.json。 + +## 逐文件改动与下一段 + +| 文件 | 改动 | +| --- | --- | +| `serialization_reference.py` | 显式旧Qwen/LoadAudio布局、Primitive具名字符串折叠;保留audioUI与API差异 | +| `structure_reference.py` | 标准子图完整结构验证、实例作用域、双向边界解析和非执行诊断 | +| `ui2api.py` | 接入显式profile;Conversion增加诊断图和未解边界;默认生产路径不使用新规则 | +| `audit_reference_conversion.py` | 复用差分,新增本批profile选择及结构/标题/API额外字段报告 | +| `test_structure_reference.py` | 32项有意义变形/真实文件对照/拒绝验证 | +| `structure-reference/*` | 固定官方源码、tag响应、两版Qwen历史与许可证/来源清单 | +| `structure-evidence/*`、本报告、README | 本次测试/来源/比较/构建/生产隔离证据 | + +最小后续工作是补齐明确版本的 PreviewAny 控件序列化差异、子图 promoted widget 值解析与对应内部节点契约;case07先解释655的原图记录,再逐个处理Set/Get/循环/模式,不能丢分支后声称成功。本轮未要求用户补资料/节点快照/模型或开放机器,也未连接目标机、停TTS、启动ComfyUI、提交prompt、调用付费服务、写在线库、合并或部署。 + +全量145份UI可靠转换、155份完整说明与必要实跑仍未完成。请总管把本次实际代码增量交HEL-893审核,保持全量目标和运行资格限制。 diff --git a/docs/hel-892/README.md b/docs/hel-892/README.md index 941deb3e..8d33981e 100644 --- a/docs/hel-892/README.md +++ b/docs/hel-892/README.md @@ -87,3 +87,4 @@ uv run --project calliope-backend --frozen python -m calliope.comfyui.library_cl - 新模块和新增测试 Ruff 通过;变更文件对照基线无新增 lint 问题,现有15项问题仍在(基线17项,见 lint-comparison.json),不能称全仓 lint 全绿。 - 前端 `npm run check` 未通过:原有 `PromptPreviewModal.svelte:125` 调用 mutate 缺参数,另有2项警告。本轮没有前端源文件或依赖改动,未扩展范围去修此前问题。详细日志随交付附上。 - 真实目标机只做一次 GET /object_info,连接拒绝;真实节点/模型核对、7类黄金文件差分、音频编码/SRT格式、真实生成和新界面均未验证。夹具回传的占位字节只证明传输落盘,不证明媒体编码正确。 +> 当前 Primitive/标准子图增量:见 `Primitive与标准子图结构参考转换.md`、`structure-reference/`、`structure-evidence/`。case02具名字符串已折叠;case03/04双向边界及实例复合ID已结构展开。PreviewAny、边界控件/内部序列化、case07坏连线等具体缺口保留,均不构成整图可靠转换或生产执行资格。本轮178项受影响回归通过,全量目标仍未完成。 diff --git a/docs/hel-892/structure-evidence/build.txt b/docs/hel-892/structure-evidence/build.txt new file mode 100644 index 00000000..7b94b99b --- /dev/null +++ b/docs/hel-892/structure-evidence/build.txt @@ -0,0 +1,4 @@ +Building source distribution... +Building wheel from source distribution... +Successfully built ../.local-evidence/structure-build/calliope-1.5.8.tar.gz +Successfully built ../.local-evidence/structure-build/calliope-1.5.8-py3-none-any.whl diff --git a/docs/hel-892/structure-evidence/companion-audit-summary.json b/docs/hel-892/structure-evidence/companion-audit-summary.json new file mode 100644 index 00000000..937c9223 --- /dev/null +++ b/docs/hel-892/structure-evidence/companion-audit-summary.json @@ -0,0 +1,936 @@ +{ + "cases": [ + { + "id": "01", + "source_path": "example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/ControlNet_aux_常用样例.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 22, + "api_inputs": 57, + "new_api_literal_params": 34, + "field_comparison": { + "unnamed_or_virtual_boundary_unverified": 34, + "link_difference": 9, + "link_equal": 14 + }, + "source_only_ids": [ + "31", + "32", + "24", + "35" + ], + "api_only_ids": [], + "named_evidence_differences": [], + "output_map": [ + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "3" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "5" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "11" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "13" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "22" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "36" + }, + { + "class_type": "PreviewImage", + "kind": "image", + "label": "预览图像", + "nodeId": "37" + } + ], + "kind": "image", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "01.json" + }, + { + "id": "02", + "source_path": "example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-Subtitle语音转字幕.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 6, + "api_inputs": 21, + "new_api_literal_params": 16, + "field_comparison": { + "link_equal": 5, + "unnamed_or_virtual_boundary_unverified": 15, + "link_difference": 1 + }, + "source_only_ids": [ + "7" + ], + "api_only_ids": [], + "named_evidence_differences": [], + "output_map": [], + "kind": "unknown", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "02.json" + }, + { + "id": "03", + "source_path": "example_ComfyUI_workflows/2-音乐生成/minimax_music_文生音乐.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 12, + "api_inputs": 40, + "new_api_literal_params": 24, + "field_comparison": { + "named_equal": 16, + "link_difference": 9, + "link_equal": 15 + }, + "source_only_ids": [ + "39", + "40", + "37" + ], + "api_only_ids": [], + "named_evidence_differences": [ + { + "node_id": "37:6", + "field": "unet_name", + "api_value": "MiniMax/minimax_music3_dit_fp16.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "minimax_music3_dit_fp16.safetensors", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 55, + -10, + 4, + 6, + 0, + "COMBO" + ], + "source_expected": [ + "37:-10", + 4 + ], + "status": "link_difference" + }, + { + "node_id": "37:13", + "field": "caption", + "api_value": "Global Metadata: Lo-fi hip-hop, chillhop. 78 BPM, D flat major, major scale with jazzy extensions. Laid-back and dreamy throughout, a gentle warm drift with a subtle late-night glow that deepens in the middle and dissolves softly at the end. Studying, raining-outside, headphones-on late-night listening. Bedroom production: muddy warm texture, heavy vinyl crackle, tape hiss and wow-flutter pitch wobble, low-passed dusty mix, soft-clipped drums, everything slightly detuned and cozy.\n\nVocal Details: Soft androgynous vocal, hushed half-sung half-spoken delivery, sitting low in the mix like another instrument, lazy behind-the-beat phrasing, gentle breathy timbre. Sparse murmured double-tracked harmonies, occasional wordless \"mmm\" and \"ooh\" hums drenched in tape delay and warm spring reverb. Long stretches with no vocals at all.\n\nArrangement: Dusty boom-bap drums with a soft thumping kick, cracked snare with lazy swing, brushed hi-hats, low round sub bass. Warm Rhodes piano chords with slow chorus wobble as the harmonic bed, mellow jazzy guitar licks answering the vocal lines, constant vinyl crackle as texture. Intro: rain and vinyl noise, solo Rhodes chords fading in, drums slipping in halfway. Verses: minimal — drums, bass, Rhodes, soft guitar fills between lines. Instrumental sections: guitar and Rhodes trade relaxed jazzy phrases over the beat, occasional muted trumpet ghost notes far in the background. Bridge: drums drop away to rain, crackle, and floating detuned Rhodes, then the beat eases back in. Outro: elements fade one by one until only vinyl crackle and a last unresolved Rhodes chord remain.", + "api_type": "str", + "named_evidence": { + "source_value": "", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 45, + -10, + 0, + 13, + 1, + "STRING" + ], + "source_expected": [ + "37:-10", + 0 + ], + "status": "link_difference" + }, + { + "node_id": "37:13", + "field": "lyrics", + "api_value": "[Intro]\nMmm...\n(rain on the window)\nOoh...\n\n[Verse]\nMidnight and the canvas glows\nDragging little wires where the current flows\nType a quiet dream, let the sampler drift\nNoise into a picture, like the fog just lifts\nTwenty slow steps, I'm in no hurry now\nLatents turning colors and I don't know how\nEvery render's like a polaroid I found\nSoft focus memories, no sound\n\n[Instrumental]\n\n[Verse]\nQueue another frame, let the motion breathe\nPictures start to move like the falling leaves\nVideo drifting by at twenty-four\nLittle animations on my bedroom floor\nSeed after seed like the rain outside\nSome of them are keepers, some I let slide\nSave the ones that feel like a Sunday slow\nNode to node to node... and off we go\n\n[Chorus]\nMmm... let it render on\n(take your time, take your time)\nOoh... by the morning it'll all be done\n(one more queue, one more try)\n\n[Instrumental]\n\n[Bridge]\nRain keeps drawing pictures on the glass...\nMy machine keeps dreaming...\nNeither of us fast...\n\n[Chorus]\nMmm... let it render on\n(take your time, take your time)\nOoh... by the morning it'll all be done\n(one more queue, one more try)\n\n[Instrumental]\n\n[Outro]\nMmm...\n(node to node)\nOoh... goodnight", + "api_type": "str", + "named_evidence": { + "source_value": "", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 46, + -10, + 1, + 13, + 2, + "STRING" + ], + "source_expected": [ + "37:-10", + 1 + ], + "status": "link_difference" + }, + { + "node_id": "37:13", + "field": "seed", + "api_value": [ + "37:38", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": 222, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 52, + 38, + 0, + 13, + 3, + "INT" + ], + "source_expected": [ + "37:38", + 0 + ], + "status": "link_equal" + }, + { + "node_id": "37:3", + "field": "clip_name", + "api_value": "MiniMax/minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 56, + -10, + 5, + 3, + 0, + "COMBO" + ], + "source_expected": [ + "37:-10", + 5 + ], + "status": "link_difference" + }, + { + "node_id": "37:7", + "field": "vae_name", + "api_value": "MiniMax/minimax_music3_dav.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "minimax_music3_dav.safetensors", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 57, + -10, + 6, + 7, + 0, + "COMBO" + ], + "source_expected": [ + "37:-10", + 6 + ], + "status": "link_difference" + }, + { + "node_id": "37:15", + "field": "seconds", + "api_value": [ + "37:13", + 1 + ], + "api_type": "list", + "named_evidence": { + "source_value": 120, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 20, + 13, + 1, + 15, + 0, + "FLOAT" + ], + "source_expected": [ + "37:13", + 1 + ], + "status": "link_equal" + }, + { + "node_id": "37:9", + "field": "seed", + "api_value": [ + "37:38", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": 1111111112, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 53, + 38, + 0, + 9, + 4, + "INT" + ], + "source_expected": [ + "37:38", + 0 + ], + "status": "link_equal" + }, + { + "node_id": "37:38", + "field": "seed", + "api_value": 617970236276137, + "api_type": "int", + "named_evidence": { + "source_value": 0, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 54, + -10, + 3, + 38, + 0, + "INT" + ], + "source_expected": [ + "37:-10", + 3 + ], + "status": "link_difference" + }, + { + "node_id": "37:43", + "field": "switch", + "api_value": true, + "api_type": "bool", + "named_evidence": { + "source_value": false, + "source_type": "bool", + "status": "different" + }, + "source_link": [ + 63, + -10, + 7, + 43, + 2, + "BOOLEAN" + ], + "source_expected": [ + "37:-10", + 7 + ], + "status": "link_difference" + } + ], + "output_map": [], + "kind": "unknown", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "03.json" + }, + { + "id": "04", + "source_path": "example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 16, + "api_inputs": 60, + "new_api_literal_params": 42, + "field_comparison": { + "named_equal": 27, + "link_difference": 20, + "link_equal": 13 + }, + "source_only_ids": [ + "459", + "463", + "468" + ], + "api_only_ids": [], + "named_evidence_differences": [ + { + "node_id": "459:451", + "field": "unet_name", + "api_value": "Qwen-Image/qwen_image_2.1_bf16.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "qwen_image_2.1_int8_convrot.safetensors", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 663, + -10, + 11, + 451, + 0, + "COMBO" + ], + "source_expected": [ + "459:-10", + 11 + ], + "status": "link_difference" + }, + { + "node_id": "459:452", + "field": "prompt", + "api_value": [ + "459:472", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": "", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 687, + 472, + 0, + 452, + 3, + "STRING" + ], + "source_expected": [ + "459:472", + 0 + ], + "status": "link_equal" + }, + { + "node_id": "459:456", + "field": "width", + "api_value": [ + "13", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": 1024, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 660, + -10, + 6, + 456, + 0, + "INT" + ], + "source_expected": [ + "459:-10", + 6 + ], + "status": "link_difference" + }, + { + "node_id": "459:456", + "field": "height", + "api_value": [ + "13", + 1 + ], + "api_type": "list", + "named_evidence": { + "source_value": 1024, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 661, + -10, + 7, + 456, + 1, + "INT" + ], + "source_expected": [ + "459:-10", + 7 + ], + "status": "link_difference" + }, + { + "node_id": "459:458", + "field": "seed", + "api_value": 447606998181263, + "api_type": "int", + "named_evidence": { + "source_value": 0, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 667, + -10, + 10, + 458, + 4, + "INT" + ], + "source_expected": [ + "459:-10", + 10 + ], + "status": "link_difference" + }, + { + "node_id": "459:471", + "field": "prompt", + "api_value": [ + "483", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": "", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 711, + -10, + 0, + 471, + 5, + "STRING" + ], + "source_expected": [ + "459:-10", + 0 + ], + "status": "link_difference" + }, + { + "node_id": "459:471", + "field": "sampling_mode.seed", + "api_value": 447606998181263, + "api_type": "int", + "named_evidence": { + "source_value": 0, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 697, + -10, + 10, + 471, + 13, + "INT" + ], + "source_expected": [ + "459:-10", + 10 + ], + "status": "link_difference" + }, + { + "node_id": "459:473", + "field": "clip_name", + "api_value": "Qwen-Image/qwen3.5_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "source_type": "str", + "status": "different" + }, + "source_link": [ + 696, + -10, + 14, + 473, + 0, + "COMBO" + ], + "source_expected": [ + "459:-10", + 14 + ], + "status": "link_difference" + }, + { + "node_id": "459:474", + "field": "switch", + "api_value": true, + "api_type": "bool", + "named_evidence": { + "source_value": false, + "source_type": "bool", + "status": "different" + }, + "source_link": [ + 688, + -10, + 1, + 474, + 2, + "BOOLEAN" + ], + "source_expected": [ + "459:-10", + 1 + ], + "status": "link_difference" + } + ], + "output_map": [ + { + "class_type": "SaveImageAdvanced", + "kind": "image", + "label": "保存图像(高级)", + "nodeId": "461" + } + ], + "kind": "image", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "04.json" + }, + { + "id": "05", + "source_path": "example_ComfyUI_workflows/4-视频生成/Minimax-h3/MiniMax_H3_导演台时间线素材_双采样潜空间放大_多分段拼接.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 16, + "api_inputs": 66, + "new_api_literal_params": 48, + "field_comparison": { + "named_difference": 5, + "named_equal": 43, + "link_equal": 18 + }, + "source_only_ids": [ + "25" + ], + "api_only_ids": [], + "named_evidence_differences": [ + { + "node_id": "1", + "field": "unet_name", + "api_value": "MiniMax/minimax_h3_ref2va_pruned_int8_convrot.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "MiniMax\\minimax_h3_ref2va_pruned_int8_convrot.safetensors", + "source_type": "str", + "status": "different" + }, + "source_value": "MiniMax\\minimax_h3_ref2va_pruned_int8_convrot.safetensors", + "status": "named_difference" + }, + { + "node_id": "2", + "field": "clip_name", + "api_value": "MiniMax/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "MiniMax\\qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors", + "source_type": "str", + "status": "different" + }, + "source_value": "MiniMax\\qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors", + "status": "named_difference" + }, + { + "node_id": "3", + "field": "vae_name", + "api_value": "MiniMax/minimax_h3_video_vae_fp16.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "MiniMax\\minimax_h3_video_vae_fp16.safetensors", + "source_type": "str", + "status": "different" + }, + "source_value": "MiniMax\\minimax_h3_video_vae_fp16.safetensors", + "status": "named_difference" + }, + { + "node_id": "4", + "field": "vae_name", + "api_value": "MiniMax/minimax_h3_audio_vae_fp32.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "MiniMax\\minimax_h3_audio_vae_fp32.safetensors", + "source_type": "str", + "status": "different" + }, + "source_value": "MiniMax\\minimax_h3_audio_vae_fp32.safetensors", + "status": "named_difference" + }, + { + "node_id": "7", + "field": "width", + "api_value": [ + "24", + 0 + ], + "api_type": "list", + "named_evidence": { + "source_value": 1536, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 44, + 24, + 0, + 7, + 2, + "INT" + ], + "source_expected": [ + "24", + 0 + ], + "status": "link_equal" + }, + { + "node_id": "7", + "field": "height", + "api_value": [ + "24", + 1 + ], + "api_type": "list", + "named_evidence": { + "source_value": 960, + "source_type": "int", + "status": "different" + }, + "source_link": [ + 45, + 24, + 1, + 7, + 3, + "INT" + ], + "source_expected": [ + "24", + 1 + ], + "status": "link_equal" + }, + { + "node_id": "21", + "field": "lora_name", + "api_value": "MiniMax/minimax_h3_ref2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors", + "api_type": "str", + "named_evidence": { + "source_value": "MiniMax\\minimax_h3_ref2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors", + "source_type": "str", + "status": "different" + }, + "source_value": "MiniMax\\minimax_h3_ref2v_turbo_8step_v1.0_768p_comfyui_bf16.safetensors", + "status": "named_difference" + } + ], + "output_map": [ + { + "class_type": "SaveVideo", + "kind": "video", + "label": "保存视频", + "nodeId": "10" + } + ], + "kind": "video", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "05.json" + }, + { + "id": "06", + "source_path": "example_ComfyUI_workflows/5-数字人/Wan2.1_I2V_InfiniteTalk_rCM_数字人对口型多动态(KJ版).json", + "state": "user_excluded", + "adopted": false, + "new_api_literal_params": 0, + "exclusion": { + "status": "user_excluded", + "case_id": "06", + "reason": "用户明确排除这一份,不补导、不修补,不作为剩余阻塞", + "decision": { + "issue_id": "01a17910-fd9c-72aa-9e76-331f0cfdf896", + "comment_id": "01a187e6-5df9-7c98-8afe-05fc9baa5b55", + "issue_link": "mention://issue/01a17910-fd9c-72aa-9e76-331f0cfdf896", + "quote": "缺的那份不需要了" + } + }, + "historical_row_preserved": false + }, + { + "id": "07", + "source_path": "example_ComfyUI_workflows/6-动作迁移/Wan_Animate2_动作迁移_for循环长视频.json", + "state": "pending_check", + "adopted": true, + "api_nodes": 72, + "api_inputs": 251, + "new_api_literal_params": 130, + "field_comparison": { + "unnamed_or_virtual_boundary_unverified": 92, + "link_difference": 57, + "link_equal": 93, + "named_difference": 1, + "named_equal": 7, + "source_node_unresolved": 1 + }, + "source_only_ids": [ + "574", + "575", + "292", + "582", + "291", + "291:78", + "291:77", + "291:90", + "291:80", + "291:290", + "291:96", + "291:79", + "291:97", + "291:416", + "291:417", + "291:571", + "291:572", + "291:573", + "581", + "539", + "600", + "603", + "602", + "604", + "605", + "587", + "597", + "477", + "477:466", + "598", + "261", + "261:241", + "608", + "609", + "540", + "601", + "610", + "606" + ], + "api_only_ids": [ + "612" + ], + "named_evidence_differences": [ + { + "node_id": "585", + "field": "video", + "api_value": "抖音20261025-285806.mp4", + "api_type": "str", + "named_evidence": { + "source_value": "1daafaf7f9a12f651c41e56d38bc518f.mp4", + "source_type": "str", + "status": "different" + }, + "source_value": "1daafaf7f9a12f651c41e56d38bc518f.mp4", + "status": "named_difference" + } + ], + "output_map": [ + { + "class_type": "SaveVideo", + "kind": "video", + "label": "保存视频", + "nodeId": "246" + } + ], + "kind": "video", + "issues": [ + { + "code": "companion_unverified", + "message": "采用提供的配套API;源图差异、导出版本与真实执行尚未核验,保持停用" + } + ], + "general_conversion_verified": false, + "execution_verified": false, + "evidence_file": "07.json" + } + ], + "adopted": 6, + "user_excluded": 1, + "source_files": 156, + "target_files": 155, + "general_conversion_verified": 0, + "execution_verified": 0, + "new_api_literal_params": 294 +} diff --git a/docs/hel-892/structure-evidence/document-audit-summary.json b/docs/hel-892/structure-evidence/document-audit-summary.json new file mode 100644 index 00000000..dfd588aa --- /dev/null +++ b/docs/hel-892/structure-evidence/document-audit-summary.json @@ -0,0 +1,24 @@ +{ + "total": 155, + "audit_scope": "current_delivery", + "source_files": 156, + "target_files": 155, + "user_excluded": 1, + "source_structure_purpose_partially_reviewed": 155, + "full_documents_completed": 0, + "files_with_selected_named_fields_reviewed": 41, + "selected_named_fields_reviewed": 1217, + "real_executions": 0, + "states": { + "pending_check": 16, + "needs_conversion": 139 + }, + "named_values_preserved": 1217, + "unnamed_widget_nodes": 3660, + "semantic_batch_files": 139, + "semantic_batch_without_named_fields": 114, + "semantic_batch_named_fields": 490, + "named_values_without_manual_field_review": 0, + "named_values_without_verified_units_ranges_effects": 1217, + "scope_limit": "人工结论与机械原值清单分开;源语义局部审校非完整说明定稿" +} diff --git a/docs/hel-892/structure-evidence/import.txt b/docs/hel-892/structure-evidence/import.txt new file mode 100644 index 00000000..e9ece288 --- /dev/null +++ b/docs/hel-892/structure-evidence/import.txt @@ -0,0 +1 @@ +{"batch_id": "ef77ea9c-f798-4db6-88b8-b6a5cfc3d26e", "source_commit": "97f3a76f0ab5da110f4c3a7e79576627d7dedaf9", "counts": {"imported": 155, "user_excluded": 1}, "states": {"pending_check": 16, "needs_conversion": 139}, "source_total": 156, "excluded_total": 1, "target_total": 155, "total": 156, "doc_completed": 0, "exec_verified": 0} diff --git a/docs/hel-892/structure-evidence/lint.txt b/docs/hel-892/structure-evidence/lint.txt new file mode 100644 index 00000000..c88ae9e6 --- /dev/null +++ b/docs/hel-892/structure-evidence/lint.txt @@ -0,0 +1,2 @@ +All checks passed! +5 files already formatted diff --git a/docs/hel-892/structure-evidence/package-check.json b/docs/hel-892/structure-evidence/package-check.json new file mode 100644 index 00000000..c108ee11 --- /dev/null +++ b/docs/hel-892/structure-evidence/package-check.json @@ -0,0 +1,17 @@ +{ + "tested_code_commit": "1f779d53c4312068513c2bd6d513f01a3c9f3caf", + "wheel_matches_code": [ + { + "file": "ui2api.py", + "sha256": "793a74cff1923e80883d7b1e45ce3e0d08c88a9b194f0702f1cdf0d28e8c2589" + }, + { + "file": "serialization_reference.py", + "sha256": "1d36316c5619471a13964f13a883a87dc01e445e028d1f653db6b5cd9086a509" + }, + { + "file": "structure_reference.py", + "sha256": "5bf992902afedd52c91fca31d6d29e29c112e973b112f6754ddb39da9684c7fd" + } + ] +} diff --git a/docs/hel-892/structure-evidence/previous-profile-comparison.json b/docs/hel-892/structure-evidence/previous-profile-comparison.json new file mode 100644 index 00000000..ca296eda --- /dev/null +++ b/docs/hel-892/structure-evidence/previous-profile-comparison.json @@ -0,0 +1,4105 @@ +{ + "profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "authority": "public_reference_only_not_object_info", + "comparison_scope": "explicit supported scalar widgets and projected endpoints only; diagnostic structures never prove widget values, full equivalence or execution", + "reference_conditions": { + "unmodified_frontend_widgets_assumed": true, + "ue_extension_serializer_match": "unknown", + "aux_release_artifact_commit_match": "unknown", + "aio_combo_membership": "unknown_not_evaluated", + "model_and_media_files_available": "unknown", + "resolution_bounds": "schema metadata only; integer values serialized without clamping" + }, + "target_version_match": "unknown", + "whole_source_equivalence_verified": false, + "execution_verified": false, + "cases": [ + { + "id": "01", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/ControlNet_aux_常用样例.json", + "source_sha256": "8898689d777330c4749a079cd762f573bb12a278c47a2fefbd066ffbdc122b6b", + "api_sha256": "0ed76e088a23af43d6fecbf273fc0a983d7112e2b046d347f715afffac56d57e", + "source_frontend_version": null, + "export_frontend_version": null, + "whole_prompt_available": true, + "whole_prompt_differences": [ + { + "path": "/10/_meta/title", + "kind": "value", + "expected": "Canny边缘检测", + "actual": "Canny" + }, + { + "path": "/11/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/13/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/2/_meta/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + }, + { + "path": "/22/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/28/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/29/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/3/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/30/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/36/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/37/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/38/_meta/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + }, + { + "path": "/5/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ], + "whole_prompt_issues": [], + "production_prompt_available": false, + "serialized_fields": [ + { + "node_id": "4", + "field": "ckpt_name", + "source_reference": "depth_anything_vitl14.pth", + "api": "depth_anything_vitl14.pth", + "differences": [] + }, + { + "node_id": "4", + "field": "resolution", + "source_reference": 512, + "api": 512, + "differences": [] + }, + { + "node_id": "12", + "field": "preprocessor", + "source_reference": "CannyEdgePreprocessor", + "api": "CannyEdgePreprocessor", + "differences": [] + }, + { + "node_id": "12", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "1", + "field": "preprocessor", + "source_reference": "DepthAnythingPreprocessor", + "api": "DepthAnythingPreprocessor", + "differences": [] + }, + { + "node_id": "1", + "field": "resolution", + "source_reference": 512, + "api": 512, + "differences": [] + }, + { + "node_id": "10", + "field": "low_threshold", + "source_reference": 0.4, + "api": 0.4, + "differences": [] + }, + { + "node_id": "10", + "field": "high_threshold", + "source_reference": 0.8, + "api": 0.8, + "differences": [] + }, + { + "node_id": "30", + "field": "direction", + "source_reference": "down", + "api": "down", + "differences": [] + }, + { + "node_id": "30", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "30", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "30", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "28", + "field": "direction", + "source_reference": "right", + "api": "right", + "differences": [] + }, + { + "node_id": "28", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "28", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "28", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "29", + "field": "direction", + "source_reference": "right", + "api": "right", + "differences": [] + }, + { + "node_id": "29", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "29", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "29", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "18", + "field": "preprocessor", + "source_reference": "AnyLineArtPreprocessor_aux", + "api": "AnyLineArtPreprocessor_aux", + "differences": [] + }, + { + "node_id": "18", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "19", + "field": "preprocessor", + "source_reference": "LineArtPreprocessor", + "api": "LineArtPreprocessor", + "differences": [] + }, + { + "node_id": "19", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "20", + "field": "preprocessor", + "source_reference": "AnimeLineArtPreprocessor", + "api": "AnimeLineArtPreprocessor", + "differences": [] + }, + { + "node_id": "20", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "21", + "field": "preprocessor", + "source_reference": "LineartStandardPreprocessor", + "api": "LineartStandardPreprocessor", + "differences": [] + }, + { + "node_id": "21", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "2", + "field": "image", + "source_reference": "comfyui-airport-editorial_00001_.png", + "api": "comfyui-airport-editorial_00001_.png", + "differences": [] + }, + { + "node_id": "38", + "field": "image", + "source_reference": "1772086821573.png", + "api": "1772086821573.png", + "differences": [] + }, + { + "node_id": "33", + "field": "preprocessor", + "source_reference": "DWPreprocessor", + "api": "DWPreprocessor", + "differences": [] + }, + { + "node_id": "33", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "34", + "field": "preprocessor", + "source_reference": "AnimalPosePreprocessor", + "api": "AnimalPosePreprocessor", + "differences": [] + }, + { + "node_id": "34", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + } + ], + "topology_edges": [ + { + "node_id": "4", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "5", + "input": "images", + "via_reroute": false, + "source_reference": [ + "4", + 0 + ], + "api": [ + "4", + 0 + ], + "differences": [] + }, + { + "node_id": "3", + "input": "images", + "via_reroute": false, + "source_reference": [ + "1", + 0 + ], + "api": [ + "1", + 0 + ], + "differences": [] + }, + { + "node_id": "13", + "input": "images", + "via_reroute": false, + "source_reference": [ + "12", + 0 + ], + "api": [ + "12", + 0 + ], + "differences": [] + }, + { + "node_id": "12", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "1", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "10", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "11", + "input": "images", + "via_reroute": false, + "source_reference": [ + "10", + 0 + ], + "api": [ + "10", + 0 + ], + "differences": [] + }, + { + "node_id": "30", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "28", + 0 + ], + "api": [ + "28", + 0 + ], + "differences": [] + }, + { + "node_id": "30", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "29", + 0 + ], + "api": [ + "29", + 0 + ], + "differences": [] + }, + { + "node_id": "28", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "18", + 0 + ], + "api": [ + "18", + 0 + ], + "differences": [] + }, + { + "node_id": "28", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "19", + 0 + ], + "api": [ + "19", + 0 + ], + "differences": [] + }, + { + "node_id": "29", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "20", + 0 + ], + "api": [ + "20", + 0 + ], + "differences": [] + }, + { + "node_id": "29", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "21", + 0 + ], + "api": [ + "21", + 0 + ], + "differences": [] + }, + { + "node_id": "18", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "19", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "20", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "22", + "input": "images", + "via_reroute": false, + "source_reference": [ + "30", + 0 + ], + "api": [ + "30", + 0 + ], + "differences": [] + }, + { + "node_id": "21", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "36", + "input": "images", + "via_reroute": false, + "source_reference": [ + "33", + 0 + ], + "api": [ + "33", + 0 + ], + "differences": [] + }, + { + "node_id": "37", + "input": "images", + "via_reroute": false, + "source_reference": [ + "34", + 0 + ], + "api": [ + "34", + 0 + ], + "differences": [] + }, + { + "node_id": "33", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "34", + "input": "image", + "via_reroute": false, + "source_reference": [ + "38", + 0 + ], + "api": [ + "38", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "4", + "source_type": "DepthAnythingPreprocessor", + "api_type": "DepthAnythingPreprocessor", + "differences": [] + }, + { + "node_id": "5", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "3", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "13", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "12", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "1", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "10", + "source_type": "Canny", + "api_type": "Canny", + "differences": [] + }, + { + "node_id": "11", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "30", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "28", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "29", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "18", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "19", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "20", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "22", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "21", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "2", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "36", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "38", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "37", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "33", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "34", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "4", + "differences": [] + }, + { + "node_id": "5", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "13", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "12", + "differences": [] + }, + { + "node_id": "1", + "differences": [] + }, + { + "node_id": "10", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Canny边缘检测", + "actual": "Canny" + } + ] + }, + { + "node_id": "11", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "30", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "28", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "29", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "18", + "differences": [] + }, + { + "node_id": "19", + "differences": [] + }, + { + "node_id": "20", + "differences": [] + }, + { + "node_id": "22", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "21", + "differences": [] + }, + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + } + ] + }, + { + "node_id": "36", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "38", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + } + ] + }, + { + "node_id": "37", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "33", + "differences": [] + }, + { + "node_id": "34", + "differences": [] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": true, + "executable": false, + "execution_verified": false + }, + { + "id": "02", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-Subtitle语音转字幕.json", + "source_sha256": "47f9afa955a6a5dce37000cb6a15bac7516d26ff50b6398bda334c825552cfd8", + "api_sha256": "daa40971b730076691721afe95e165932df94e3423f1fc44dcb7707026e7125b", + "source_frontend_version": "1.37.11", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "2" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "4" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "3" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "1" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveNode", + "node_id": "7" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:LoadAudio", + "node_id": "6" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:AILab_Qwen3ASRSubtitle", + "node_id": "9" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "2", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 1 + ], + "api": [ + "9", + 1 + ], + "differences": [] + }, + { + "node_id": "4", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 0 + ], + "api": [ + "9", + 0 + ], + "differences": [] + }, + { + "node_id": "3", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 2 + ], + "api": [ + "9", + 2 + ], + "differences": [] + }, + { + "node_id": "1", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 3 + ], + "api": [ + "9", + 3 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "6", + 0 + ], + "api": [ + "6", + 0 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "hints", + "via_reroute": false, + "source_reference": [ + "7", + 0 + ], + "api": "Important terms: ComfyUI, Qwen3-ASR\nUse exact casing for these terms.", + "differences": [ + { + "path": "", + "expected": "Important terms: ComfyUI, Qwen3-ASR\nUse exact casing for these terms.", + "actual": [ + "7", + 0 + ], + "kind": "type" + } + ] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "2", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "4", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "3", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "1", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "7", + "type": "PrimitiveNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "6", + "type": "LoadAudio", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "9", + "type": "AILab_Qwen3ASRSubtitle", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "2", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "4", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "3", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "1", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "7", + "source_type": "PrimitiveNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "PrimitiveNode", + "kind": "type" + } + ] + }, + { + "node_id": "6", + "source_type": "LoadAudio", + "api_type": "LoadAudio", + "differences": [] + }, + { + "node_id": "9", + "source_type": "AILab_Qwen3ASRSubtitle", + "api_type": "AILab_Qwen3ASRSubtitle", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "4", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "1", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "7", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "PrimitiveNode" + }, + "kind": "type" + } + ] + }, + { + "node_id": "6", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载音频", + "actual": "LoadAudio" + } + ] + }, + { + "node_id": "9", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Subtitle (QwenASR)", + "actual": "AILab_Qwen3ASRSubtitle" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "03", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/2-音乐生成/minimax_music_文生音乐.json", + "source_sha256": "0a655ead5a0da406159dceb46451439df0c02050becaaa25b3018abb41840284", + "api_sha256": "91e6c2cea3747a03bbb71f661dbd016b28040781482b956365ff76a7a8b647ce", + "source_frontend_version": "1.48.7", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "subgraph_requires_export", + "message": "包含子图:需原 ComfyUI API 导出及差分核对", + "node_id": "" + }, + { + "code": "reference_frontend_mismatch", + "message": "源图声明的前端版本与固定参考不一致", + "node_id": "" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveAudioAdvanced", + "node_id": "35" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ac99f841-a3de-4329-9564-953b81cf9e16", + "node_id": "37" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "35", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "37", + 0 + ], + "api": [ + "37:43", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "37:43", + "actual": "37" + } + ] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "35", + "type": "SaveAudioAdvanced", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "37", + "type": "ac99f841-a3de-4329-9564-953b81cf9e16", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "35", + "source_type": "SaveAudioAdvanced", + "api_type": "SaveAudioAdvanced", + "differences": [] + }, + { + "node_id": "37", + "source_type": "ac99f841-a3de-4329-9564-953b81cf9e16", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "ac99f841-a3de-4329-9564-953b81cf9e16", + "kind": "type" + } + ] + } + ], + "metadata": [ + { + "node_id": "35", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存音频(高级)", + "actual": "SaveAudioAdvanced" + } + ] + }, + { + "node_id": "37", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "ac99f841-a3de-4329-9564-953b81cf9e16" + }, + "kind": "type" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "04", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json", + "source_sha256": "dfe10917d101bf1a8a8c20750f4360690ecd478e9eb33d16a59ea0c6f12c086c", + "api_sha256": "2066b07b2ca5390ba3e795df6b43934dab83865b12870b6ff26d8c0ef24f091e", + "source_frontend_version": "1.53.6", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "subgraph_requires_export", + "message": "包含子图:需原 ComfyUI API 导出及差分核对", + "node_id": "" + }, + { + "code": "reference_frontend_mismatch", + "message": "源图声明的前端版本与固定参考不一致", + "node_id": "" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ResolutionSelector", + "node_id": "13" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:c291ceec-b98f-4751-9d0b-7bc288f27b30", + "node_id": "459" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveImageAdvanced", + "node_id": "461" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveStringMultiline", + "node_id": "483" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "459", + "input": "prompt", + "via_reroute": false, + "source_reference": [ + "483", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "483", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "459", + "input": "width", + "via_reroute": false, + "source_reference": [ + "13", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "13", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "459", + "input": "height", + "via_reroute": false, + "source_reference": [ + "13", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "13", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "461", + "input": "images", + "via_reroute": false, + "source_reference": [ + "459", + 0 + ], + "api": [ + "459:457", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "459:457", + "actual": "459" + } + ] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "13", + "type": "ResolutionSelector", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "459", + "type": "c291ceec-b98f-4751-9d0b-7bc288f27b30", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "461", + "type": "SaveImageAdvanced", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "483", + "type": "PrimitiveStringMultiline", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "13", + "source_type": "ResolutionSelector", + "api_type": "ResolutionSelector", + "differences": [] + }, + { + "node_id": "459", + "source_type": "c291ceec-b98f-4751-9d0b-7bc288f27b30", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "c291ceec-b98f-4751-9d0b-7bc288f27b30", + "kind": "type" + } + ] + }, + { + "node_id": "461", + "source_type": "SaveImageAdvanced", + "api_type": "SaveImageAdvanced", + "differences": [] + }, + { + "node_id": "483", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "13", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "分辨率选择器", + "actual": "ResolutionSelector" + } + ] + }, + { + "node_id": "459", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "c291ceec-b98f-4751-9d0b-7bc288f27b30" + }, + "kind": "type" + } + ] + }, + { + "node_id": "461", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存图像(高级)", + "actual": "SaveImageAdvanced" + } + ] + }, + { + "node_id": "483", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "字符串(多行)", + "actual": "PrimitiveStringMultiline" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "05", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/4-视频生成/Minimax-h3/MiniMax_H3_导演台时间线素材_双采样潜空间放大_多分段拼接.json", + "source_sha256": "172eb8af3aca70082941427520fdcca06568957bab3d39101c5e9d6641b45e4a", + "api_sha256": "95a01c1ea27a8279a6dc202820505099a94161d91e0789189b61208b09007af8", + "source_frontend_version": "1.52.7", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_frontend_mismatch", + "message": "源图声明的前端版本与固定参考不一致", + "node_id": "" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveVideo", + "node_id": "10" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ModelAttentionBackend", + "node_id": "19" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3SigmaShift", + "node_id": "18" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:BlockSparseAttention", + "node_id": "20" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CLIPLoader", + "node_id": "2" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "4" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:LoraLoaderModelOnly", + "node_id": "21" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ModelPreviewOverrideKJ", + "node_id": "22" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3FiniteSegmentSampler", + "node_id": "8" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CreateVideo", + "node_id": "9" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ResolutionSelector", + "node_id": "24" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3TimelinePlanner", + "node_id": "7" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "3" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:UNETLoader", + "node_id": "1" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:BasicScheduler", + "node_id": "5" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:KSamplerSelect", + "node_id": "6" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "10", + "input": "video", + "via_reroute": false, + "source_reference": [ + "9", + 0 + ], + "api": [ + "9", + 0 + ], + "differences": [] + }, + { + "node_id": "19", + "input": "model", + "via_reroute": false, + "source_reference": [ + "18", + 0 + ], + "api": [ + "18", + 0 + ], + "differences": [] + }, + { + "node_id": "18", + "input": "model", + "via_reroute": false, + "source_reference": [ + "21", + 0 + ], + "api": [ + "21", + 0 + ], + "differences": [] + }, + { + "node_id": "20", + "input": "model", + "via_reroute": false, + "source_reference": [ + "19", + 0 + ], + "api": [ + "19", + 0 + ], + "differences": [] + }, + { + "node_id": "21", + "input": "model", + "via_reroute": false, + "source_reference": [ + "1", + 0 + ], + "api": [ + "1", + 0 + ], + "differences": [] + }, + { + "node_id": "22", + "input": "model", + "via_reroute": false, + "source_reference": [ + "20", + 0 + ], + "api": [ + "20", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "model", + "via_reroute": false, + "source_reference": [ + "22", + 0 + ], + "api": [ + "22", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "clip", + "via_reroute": false, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "vae", + "via_reroute": false, + "source_reference": [ + "3", + 0 + ], + "api": [ + "3", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "audio_vae", + "via_reroute": false, + "source_reference": [ + "4", + 0 + ], + "api": [ + "4", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "finite_plan", + "via_reroute": false, + "source_reference": [ + "7", + 2 + ], + "api": [ + "7", + 2 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "sampler", + "via_reroute": false, + "source_reference": [ + "6", + 0 + ], + "api": [ + "6", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "sigmas", + "via_reroute": false, + "source_reference": [ + "5", + 0 + ], + "api": [ + "5", + 0 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "images", + "via_reroute": false, + "source_reference": [ + "8", + 1 + ], + "api": [ + "8", + 1 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "8", + 2 + ], + "api": [ + "8", + 2 + ], + "differences": [] + }, + { + "node_id": "7", + "input": "width", + "via_reroute": false, + "source_reference": [ + "24", + 0 + ], + "api": [ + "24", + 0 + ], + "differences": [] + }, + { + "node_id": "7", + "input": "height", + "via_reroute": false, + "source_reference": [ + "24", + 1 + ], + "api": [ + "24", + 1 + ], + "differences": [] + }, + { + "node_id": "5", + "input": "model", + "via_reroute": false, + "source_reference": [ + "22", + 0 + ], + "api": [ + "22", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "10", + "type": "SaveVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "19", + "type": "ModelAttentionBackend", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "18", + "type": "MiniMaxH3SigmaShift", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "20", + "type": "BlockSparseAttention", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "2", + "type": "CLIPLoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "4", + "type": "VAELoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "21", + "type": "LoraLoaderModelOnly", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "22", + "type": "ModelPreviewOverrideKJ", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "8", + "type": "MiniMaxH3FiniteSegmentSampler", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "9", + "type": "CreateVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "24", + "type": "ResolutionSelector", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "7", + "type": "MiniMaxH3TimelinePlanner", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "3", + "type": "VAELoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "1", + "type": "UNETLoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "5", + "type": "BasicScheduler", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "6", + "type": "KSamplerSelect", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "10", + "source_type": "SaveVideo", + "api_type": "SaveVideo", + "differences": [] + }, + { + "node_id": "19", + "source_type": "ModelAttentionBackend", + "api_type": "ModelAttentionBackend", + "differences": [] + }, + { + "node_id": "18", + "source_type": "MiniMaxH3SigmaShift", + "api_type": "MiniMaxH3SigmaShift", + "differences": [] + }, + { + "node_id": "20", + "source_type": "BlockSparseAttention", + "api_type": "BlockSparseAttention", + "differences": [] + }, + { + "node_id": "2", + "source_type": "CLIPLoader", + "api_type": "CLIPLoader", + "differences": [] + }, + { + "node_id": "4", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "21", + "source_type": "LoraLoaderModelOnly", + "api_type": "LoraLoaderModelOnly", + "differences": [] + }, + { + "node_id": "22", + "source_type": "ModelPreviewOverrideKJ", + "api_type": "ModelPreviewOverrideKJ", + "differences": [] + }, + { + "node_id": "8", + "source_type": "MiniMaxH3FiniteSegmentSampler", + "api_type": "MiniMaxH3FiniteSegmentSampler", + "differences": [] + }, + { + "node_id": "9", + "source_type": "CreateVideo", + "api_type": "CreateVideo", + "differences": [] + }, + { + "node_id": "24", + "source_type": "ResolutionSelector", + "api_type": "ResolutionSelector", + "differences": [] + }, + { + "node_id": "7", + "source_type": "MiniMaxH3TimelinePlanner", + "api_type": "MiniMaxH3TimelinePlanner", + "differences": [] + }, + { + "node_id": "3", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "1", + "source_type": "UNETLoader", + "api_type": "UNETLoader", + "differences": [] + }, + { + "node_id": "5", + "source_type": "BasicScheduler", + "api_type": "BasicScheduler", + "differences": [] + }, + { + "node_id": "6", + "source_type": "KSamplerSelect", + "api_type": "KSamplerSelect", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "10", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存视频", + "actual": "SaveVideo" + } + ] + }, + { + "node_id": "19", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "模型注意力后端", + "actual": "ModelAttentionBackend" + } + ] + }, + { + "node_id": "18", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 Sigma Shift", + "actual": "MiniMaxH3SigmaShift" + } + ] + }, + { + "node_id": "20", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "模型稀疏注意力", + "actual": "BlockSparseAttention" + } + ] + }, + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载CLIP", + "actual": "CLIPLoader" + } + ] + }, + { + "node_id": "4", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "21", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "LoRA加载器(仅模型)", + "actual": "LoraLoaderModelOnly" + } + ] + }, + { + "node_id": "22", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Model Preview Override", + "actual": "ModelPreviewOverrideKJ" + } + ] + }, + { + "node_id": "8", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 有限分段采样", + "actual": "MiniMaxH3FiniteSegmentSampler" + } + ] + }, + { + "node_id": "9", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "创建视频", + "actual": "CreateVideo" + } + ] + }, + { + "node_id": "24", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "分辨率选择器", + "actual": "ResolutionSelector" + } + ] + }, + { + "node_id": "7", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 素材规划台", + "actual": "MiniMaxH3TimelinePlanner" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "1", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "UNet加载器", + "actual": "UNETLoader" + } + ] + }, + { + "node_id": "5", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "基本调度器", + "actual": "BasicScheduler" + } + ] + }, + { + "node_id": "6", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "K采样器选择", + "actual": "KSamplerSelect" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "07", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/6-动作迁移/Wan_Animate2_动作迁移_for循环长视频.json", + "source_sha256": "22b7853e22629822dd354b0b768e2961a53b4c2f480cfaceeaea9dc51c0f0d0b", + "api_sha256": "b1b4f6a6c02d8d21701943c67b62805b1210fed17e7e26b618c58e112ea1d70d", + "source_frontend_version": "1.48.6", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "subgraph_requires_export", + "message": "包含子图:需原 ComfyUI API 导出及差分核对", + "node_id": "" + }, + { + "code": "reference_frontend_mismatch", + "message": "源图声明的前端版本与固定参考不一致", + "node_id": "" + }, + { + "code": "reference_link_invalid", + "message": "静音/旁路不在追线参考契约内", + "node_id": "" + }, + { + "code": "reference_link_invalid", + "message": "静音/旁路不在追线参考契约内", + "node_id": "" + }, + { + "code": "mode_requires_export", + "message": "SaveVideo 包含静音/旁路状态,需 API 导出核对", + "node_id": "292" + }, + { + "code": "mode_requires_export", + "message": "79280513-53b2-4417-93f8-f3e116bb6736 包含静音/旁路状态,需 API 导出核对", + "node_id": "291" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveStringMultiline", + "node_id": "583" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:INTConstant", + "node_id": "580" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:TTResolutionSelector", + "node_id": "579" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SetNode", + "node_id": "600" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:GetNode", + "node_id": "603" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:GetNode", + "node_id": "602" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VHS_VideoInfoLoaded", + "node_id": "586" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SetNode", + "node_id": "604" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:GetNode", + "node_id": "605" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveStringMultiline", + "node_id": "584" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SetNode", + "node_id": "597" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "538" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ComfyMathExpression", + "node_id": "536" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "node_id": "477" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:GetNode", + "node_id": "598" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:11706f8a-428d-4ef9-b24f-863f651c1b0b", + "node_id": "261" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "607" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SetNode", + "node_id": "608" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CreateVideo", + "node_id": "245" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:GetNode", + "node_id": "609" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveVideo", + "node_id": "246" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SetNode", + "node_id": "601" + }, + { + "code": "reference_widget_unverified", + "message": "源节点声明与固定核心参考版本不符", + "node_id": "189" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:Label (rgthree)", + "node_id": "610" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "node_id": "606" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VHS_LoadVideo", + "node_id": "585" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "292", + "input": "video", + "status": "unsupported", + "reason": "静音/旁路不在追线参考契约内" + }, + { + "node_id": "291", + "input": "video", + "status": "unsupported", + "reason": "静音/旁路不在追线参考契约内" + }, + { + "node_id": "600", + "input": "AUDIO", + "via_reroute": false, + "source_reference": [ + "585", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "586", + "input": "video_info", + "via_reroute": false, + "source_reference": [ + "585", + 3 + ], + "api": [ + "585", + 3 + ], + "differences": [] + }, + { + "node_id": "604", + "input": "INT", + "via_reroute": false, + "source_reference": [ + "586", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "586", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "597", + "input": "FLOAT", + "via_reroute": false, + "source_reference": [ + "536", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "536", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "538", + "input": "source", + "via_reroute": false, + "source_reference": [ + "536", + 0 + ], + "api": [ + "536", + 0 + ], + "differences": [] + }, + { + "node_id": "536", + "input": "values.a", + "via_reroute": false, + "source_reference": [ + "605", + 0 + ], + "api": [ + "586", + 1 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "586", + "actual": "605" + }, + { + "path": "/1", + "kind": "value", + "expected": 1, + "actual": 0 + } + ] + }, + { + "node_id": "536", + "input": "values.b", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": [ + "580", + 0 + ], + "differences": [] + }, + { + "node_id": "477", + "input": "input", + "via_reroute": true, + "source_reference": [ + "189", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "189", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "continue_motion", + "via_reroute": false, + "source_reference": [ + "606", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "video_frame_offset_1", + "via_reroute": false, + "source_reference": [ + "606", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "text", + "via_reroute": false, + "source_reference": [ + "583", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "583", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "text_4", + "via_reroute": false, + "source_reference": [ + "584", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "584", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "resize_type.width", + "via_reroute": false, + "source_reference": [ + "579", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "resize_type.height_1", + "via_reroute": false, + "source_reference": [ + "579", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "length", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "580", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "input_1", + "via_reroute": true, + "source_reference": [ + "585", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "input", + "via_reroute": true, + "source_reference": [ + "189", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "189", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "text", + "via_reroute": false, + "source_reference": [ + "583", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "583", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "text_4", + "via_reroute": false, + "source_reference": [ + "584", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "584", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "resize_type.width", + "via_reroute": false, + "source_reference": [ + "579", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "resize_type.height_1", + "via_reroute": false, + "source_reference": [ + "579", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "length", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "580", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "input_1", + "via_reroute": true, + "source_reference": [ + "585", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "607", + "input": "source", + "via_reroute": false, + "source_reference": [ + "606", + 3 + ], + "api": [ + "606:596", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "606:596", + "actual": "606" + }, + { + "path": "/1", + "kind": "value", + "expected": 0, + "actual": 3 + } + ] + }, + { + "node_id": "608", + "input": "*", + "via_reroute": false, + "source_reference": [ + "606", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "245", + "input": "images", + "via_reroute": false, + "source_reference": [ + "609", + 0 + ], + "api": [ + "606:599", + 2 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "606:599", + "actual": "609" + }, + { + "path": "/1", + "kind": "value", + "expected": 2, + "actual": 0 + } + ] + }, + { + "node_id": "245", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "602", + 0 + ], + "api": [ + "585", + 2 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "585", + "actual": "602" + }, + { + "path": "/1", + "kind": "value", + "expected": 2, + "actual": 0 + } + ] + }, + { + "node_id": "245", + "input": "fps", + "via_reroute": false, + "source_reference": [ + "603", + 0 + ], + "api": [ + "586", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "586", + "actual": "603" + } + ] + }, + { + "node_id": "246", + "input": "video", + "via_reroute": false, + "source_reference": [ + "245", + 0 + ], + "api": [ + "245", + 0 + ], + "differences": [] + }, + { + "node_id": "601", + "input": "FLOAT", + "via_reroute": false, + "source_reference": [ + "586", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "586", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value1", + "via_reroute": false, + "source_reference": [ + "261", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value2", + "via_reroute": false, + "source_reference": [ + "261", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value3", + "via_reroute": false, + "source_reference": [ + "261", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "a", + "via_reroute": false, + "source_reference": [ + "598", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "598", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value1_1", + "via_reroute": false, + "source_reference": [ + "477", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value2_1", + "via_reroute": false, + "source_reference": [ + "477", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "images.image1_1", + "via_reroute": false, + "source_reference": [ + "477", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 2 + ], + "kind": "type" + } + ] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "292", + "type": "SaveVideo", + "reason": "静音/旁路不在序列化参考契约内" + }, + { + "node_id": "291", + "type": "79280513-53b2-4417-93f8-f3e116bb6736", + "reason": "静音/旁路不在序列化参考契约内" + }, + { + "node_id": "583", + "type": "PrimitiveStringMultiline", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "580", + "type": "INTConstant", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "579", + "type": "TTResolutionSelector", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "600", + "type": "SetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "603", + "type": "GetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "602", + "type": "GetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "586", + "type": "VHS_VideoInfoLoaded", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "604", + "type": "SetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "605", + "type": "GetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "584", + "type": "PrimitiveStringMultiline", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "597", + "type": "SetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "538", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "536", + "type": "ComfyMathExpression", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "477", + "type": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "598", + "type": "GetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "261", + "type": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "607", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "608", + "type": "SetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "245", + "type": "CreateVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "609", + "type": "GetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "246", + "type": "SaveVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "601", + "type": "SetNode", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "189", + "type": "LoadImage", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "610", + "type": "Label (rgthree)", + "reason": "控件数量/形式或节点类型不在固定参考契约内" + }, + { + "node_id": "606", + "type": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "585", + "type": "VHS_LoadVideo", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "292", + "source_type": "SaveVideo", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SaveVideo", + "kind": "type" + } + ] + }, + { + "node_id": "291", + "source_type": "79280513-53b2-4417-93f8-f3e116bb6736", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "79280513-53b2-4417-93f8-f3e116bb6736", + "kind": "type" + } + ] + }, + { + "node_id": "583", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + }, + { + "node_id": "580", + "source_type": "INTConstant", + "api_type": "INTConstant", + "differences": [] + }, + { + "node_id": "579", + "source_type": "TTResolutionSelector", + "api_type": "TTResolutionSelector", + "differences": [] + }, + { + "node_id": "600", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "603", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "602", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "586", + "source_type": "VHS_VideoInfoLoaded", + "api_type": "VHS_VideoInfoLoaded", + "differences": [] + }, + { + "node_id": "604", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "605", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "584", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + }, + { + "node_id": "597", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "538", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "536", + "source_type": "ComfyMathExpression", + "api_type": "ComfyMathExpression", + "differences": [] + }, + { + "node_id": "477", + "source_type": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "kind": "type" + } + ] + }, + { + "node_id": "598", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "261", + "source_type": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "kind": "type" + } + ] + }, + { + "node_id": "607", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "608", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "245", + "source_type": "CreateVideo", + "api_type": "CreateVideo", + "differences": [] + }, + { + "node_id": "609", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "246", + "source_type": "SaveVideo", + "api_type": "SaveVideo", + "differences": [] + }, + { + "node_id": "601", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "189", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "610", + "source_type": "Label (rgthree)", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "Label (rgthree)", + "kind": "type" + } + ] + }, + { + "node_id": "606", + "source_type": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "kind": "type" + } + ] + }, + { + "node_id": "585", + "source_type": "VHS_LoadVideo", + "api_type": "VHS_LoadVideo", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "292", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "SaveVideo" + }, + "kind": "type" + } + ] + }, + { + "node_id": "291", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "79280513-53b2-4417-93f8-f3e116bb6736" + }, + "kind": "type" + } + ] + }, + { + "node_id": "583", + "differences": [] + }, + { + "node_id": "580", + "differences": [] + }, + { + "node_id": "579", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "TT分辨率选择器", + "actual": "TTResolutionSelector" + } + ] + }, + { + "node_id": "600", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_音频" + }, + "kind": "type" + } + ] + }, + { + "node_id": "603", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_帧率" + }, + "kind": "type" + } + ] + }, + { + "node_id": "602", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_音频" + }, + "kind": "type" + } + ] + }, + { + "node_id": "586", + "differences": [] + }, + { + "node_id": "604", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_动作视频帧数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "605", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_动作视频帧数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "584", + "differences": [] + }, + { + "node_id": "597", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_执行次数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "538", + "differences": [] + }, + { + "node_id": "536", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "数学表达式", + "actual": "ComfyMathExpression" + } + ] + }, + { + "node_id": "477", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "b798a87e-23ec-483d-ab9b-6af5b298d0ad" + }, + "kind": "type" + } + ] + }, + { + "node_id": "598", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_执行次数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "261", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "11706f8a-428d-4ef9-b24f-863f651c1b0b" + }, + "kind": "type" + } + ] + }, + { + "node_id": "607", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "608", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_循环结果输出" + }, + "kind": "type" + } + ] + }, + { + "node_id": "245", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "创建视频", + "actual": "CreateVideo" + } + ] + }, + { + "node_id": "609", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_循环结果输出" + }, + "kind": "type" + } + ] + }, + { + "node_id": "246", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存视频", + "actual": "SaveVideo" + } + ] + }, + { + "node_id": "601", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_帧率" + }, + "kind": "type" + } + ] + }, + { + "node_id": "189", + "differences": [] + }, + { + "node_id": "610", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Wan_animate2_动作迁移 For循环长视频 by Bright" + }, + "kind": "type" + } + ] + }, + { + "node_id": "606", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "bb1c37c2-3479-48a8-88c0-11e7d43715d6" + }, + "kind": "type" + } + ] + }, + { + "node_id": "585", + "differences": [] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + } + ] +} diff --git a/docs/hel-892/structure-evidence/previous-profile-protection.json b/docs/hel-892/structure-evidence/previous-profile-protection.json new file mode 100644 index 00000000..3d856f6a --- /dev/null +++ b/docs/hel-892/structure-evidence/previous-profile-protection.json @@ -0,0 +1,80 @@ +[ + { + "id": "01", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + }, + { + "id": "02", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + }, + { + "id": "03", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + }, + { + "id": "04", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + }, + { + "id": "05", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + }, + { + "id": "07", + "unchanged_fields": [ + "whole_prompt_available", + "whole_prompt_differences", + "whole_prompt_issues", + "serialized_fields", + "topology_edges", + "unsupported_widget_nodes", + "production_prompt_available" + ], + "all_equal": true + } +] diff --git a/docs/hel-892/structure-evidence/protection.json b/docs/hel-892/structure-evidence/protection.json new file mode 100644 index 00000000..834488bc --- /dev/null +++ b/docs/hel-892/structure-evidence/protection.json @@ -0,0 +1,22 @@ +{ + "tested_code_commit": "1f779d53c4312068513c2bd6d513f01a3c9f3caf", + "source_baseline_commit": "97f3a76f0ab5da110f4c3a7e79576627d7dedaf9", + "original_bytes": { + "source": { + "files": 156, + "all_equal_to_base": true, + "set_sha256": "703c2841e752d62b9f4b04f2358053beb3e071ac7a3f717e59adf0d29606afab" + }, + "received_api": { + "files": 7, + "all_equal_to_base": true, + "set_sha256": "416f67420e4b633956136c61381a0e957e50cf59b21ec38ed51d8f5b035ceab3" + } + }, + "isolated_rows": 155, + "disabled_rows": 155, + "null_completion_and_execution_timestamps": true, + "production_registry_and_import_unchanged": true, + "user_whole_row_protection": "test_workflow_library.py and test_delivery_scope.py regression passed", + "new_reference_not_used_by_production_import": true +} diff --git a/docs/hel-892/structure-evidence/reimport.txt b/docs/hel-892/structure-evidence/reimport.txt new file mode 100644 index 00000000..501bcff4 --- /dev/null +++ b/docs/hel-892/structure-evidence/reimport.txt @@ -0,0 +1 @@ +{"batch_id": "233df731-fb45-4949-a6de-0f15eb1d9699", "source_commit": "97f3a76f0ab5da110f4c3a7e79576627d7dedaf9", "counts": {"skipped": 155, "user_excluded": 1}, "states": {"pending_check": 16, "needs_conversion": 139}, "source_total": 156, "excluded_total": 1, "target_total": 155, "total": 156, "doc_completed": 0, "exec_verified": 0} diff --git a/docs/hel-892/structure-evidence/six-case-comparison.json b/docs/hel-892/structure-evidence/six-case-comparison.json new file mode 100644 index 00000000..dbdc8df1 --- /dev/null +++ b/docs/hel-892/structure-evidence/six-case-comparison.json @@ -0,0 +1,8589 @@ +{ + "profile": "structure-batch-reference", + "authority": "public_reference_only_not_object_info", + "comparison_scope": "explicit supported scalar widgets and projected endpoints only; diagnostic structures never prove widget values, full equivalence or execution", + "reference_conditions": { + "unmodified_frontend_widgets_assumed": true, + "ue_extension_serializer_match": "unknown", + "aux_release_artifact_commit_match": "not_used", + "aio_combo_membership": "unknown_not_evaluated", + "model_and_media_files_available": "unknown", + "resolution_bounds": "schema metadata only; integer values serialized without clamping" + }, + "target_version_match": "unknown", + "whole_source_equivalence_verified": false, + "execution_verified": false, + "cases": [ + { + "id": "01", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/ControlNet_aux_常用样例.json", + "source_sha256": "8898689d777330c4749a079cd762f573bb12a278c47a2fefbd066ffbdc122b6b", + "api_sha256": "0ed76e088a23af43d6fecbf273fc0a983d7112e2b046d347f715afffac56d57e", + "source_frontend_version": null, + "export_frontend_version": null, + "whole_prompt_available": true, + "whole_prompt_differences": [ + { + "path": "/10/_meta/title", + "kind": "value", + "expected": "Canny边缘检测", + "actual": "Canny" + }, + { + "path": "/11/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/13/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/2/_meta/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + }, + { + "path": "/22/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/28/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/29/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/3/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/30/_meta/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + }, + { + "path": "/36/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/37/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + }, + { + "path": "/38/_meta/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + }, + { + "path": "/5/_meta/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ], + "whole_prompt_issues": [], + "production_prompt_available": false, + "serialized_fields": [ + { + "node_id": "4", + "field": "ckpt_name", + "source_reference": "depth_anything_vitl14.pth", + "api": "depth_anything_vitl14.pth", + "differences": [] + }, + { + "node_id": "4", + "field": "resolution", + "source_reference": 512, + "api": 512, + "differences": [] + }, + { + "node_id": "12", + "field": "preprocessor", + "source_reference": "CannyEdgePreprocessor", + "api": "CannyEdgePreprocessor", + "differences": [] + }, + { + "node_id": "12", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "1", + "field": "preprocessor", + "source_reference": "DepthAnythingPreprocessor", + "api": "DepthAnythingPreprocessor", + "differences": [] + }, + { + "node_id": "1", + "field": "resolution", + "source_reference": 512, + "api": 512, + "differences": [] + }, + { + "node_id": "10", + "field": "low_threshold", + "source_reference": 0.4, + "api": 0.4, + "differences": [] + }, + { + "node_id": "10", + "field": "high_threshold", + "source_reference": 0.8, + "api": 0.8, + "differences": [] + }, + { + "node_id": "30", + "field": "direction", + "source_reference": "down", + "api": "down", + "differences": [] + }, + { + "node_id": "30", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "30", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "30", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "28", + "field": "direction", + "source_reference": "right", + "api": "right", + "differences": [] + }, + { + "node_id": "28", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "28", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "28", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "29", + "field": "direction", + "source_reference": "right", + "api": "right", + "differences": [] + }, + { + "node_id": "29", + "field": "match_image_size", + "source_reference": true, + "api": true, + "differences": [] + }, + { + "node_id": "29", + "field": "spacing_width", + "source_reference": 2, + "api": 2, + "differences": [] + }, + { + "node_id": "29", + "field": "spacing_color", + "source_reference": "white", + "api": "white", + "differences": [] + }, + { + "node_id": "18", + "field": "preprocessor", + "source_reference": "AnyLineArtPreprocessor_aux", + "api": "AnyLineArtPreprocessor_aux", + "differences": [] + }, + { + "node_id": "18", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "19", + "field": "preprocessor", + "source_reference": "LineArtPreprocessor", + "api": "LineArtPreprocessor", + "differences": [] + }, + { + "node_id": "19", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "20", + "field": "preprocessor", + "source_reference": "AnimeLineArtPreprocessor", + "api": "AnimeLineArtPreprocessor", + "differences": [] + }, + { + "node_id": "20", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "21", + "field": "preprocessor", + "source_reference": "LineartStandardPreprocessor", + "api": "LineartStandardPreprocessor", + "differences": [] + }, + { + "node_id": "21", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "2", + "field": "image", + "source_reference": "comfyui-airport-editorial_00001_.png", + "api": "comfyui-airport-editorial_00001_.png", + "differences": [] + }, + { + "node_id": "38", + "field": "image", + "source_reference": "1772086821573.png", + "api": "1772086821573.png", + "differences": [] + }, + { + "node_id": "33", + "field": "preprocessor", + "source_reference": "DWPreprocessor", + "api": "DWPreprocessor", + "differences": [] + }, + { + "node_id": "33", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + }, + { + "node_id": "34", + "field": "preprocessor", + "source_reference": "AnimalPosePreprocessor", + "api": "AnimalPosePreprocessor", + "differences": [] + }, + { + "node_id": "34", + "field": "resolution", + "source_reference": 1024, + "api": 1024, + "differences": [] + } + ], + "topology_edges": [ + { + "node_id": "4", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "5", + "input": "images", + "via_reroute": false, + "source_reference": [ + "4", + 0 + ], + "api": [ + "4", + 0 + ], + "differences": [] + }, + { + "node_id": "3", + "input": "images", + "via_reroute": false, + "source_reference": [ + "1", + 0 + ], + "api": [ + "1", + 0 + ], + "differences": [] + }, + { + "node_id": "13", + "input": "images", + "via_reroute": false, + "source_reference": [ + "12", + 0 + ], + "api": [ + "12", + 0 + ], + "differences": [] + }, + { + "node_id": "12", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "1", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "10", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "11", + "input": "images", + "via_reroute": false, + "source_reference": [ + "10", + 0 + ], + "api": [ + "10", + 0 + ], + "differences": [] + }, + { + "node_id": "30", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "28", + 0 + ], + "api": [ + "28", + 0 + ], + "differences": [] + }, + { + "node_id": "30", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "29", + 0 + ], + "api": [ + "29", + 0 + ], + "differences": [] + }, + { + "node_id": "28", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "18", + 0 + ], + "api": [ + "18", + 0 + ], + "differences": [] + }, + { + "node_id": "28", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "19", + 0 + ], + "api": [ + "19", + 0 + ], + "differences": [] + }, + { + "node_id": "29", + "input": "image1", + "via_reroute": false, + "source_reference": [ + "20", + 0 + ], + "api": [ + "20", + 0 + ], + "differences": [] + }, + { + "node_id": "29", + "input": "image2", + "via_reroute": false, + "source_reference": [ + "21", + 0 + ], + "api": [ + "21", + 0 + ], + "differences": [] + }, + { + "node_id": "18", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "19", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "20", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "22", + "input": "images", + "via_reroute": false, + "source_reference": [ + "30", + 0 + ], + "api": [ + "30", + 0 + ], + "differences": [] + }, + { + "node_id": "21", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "36", + "input": "images", + "via_reroute": false, + "source_reference": [ + "33", + 0 + ], + "api": [ + "33", + 0 + ], + "differences": [] + }, + { + "node_id": "37", + "input": "images", + "via_reroute": false, + "source_reference": [ + "34", + 0 + ], + "api": [ + "34", + 0 + ], + "differences": [] + }, + { + "node_id": "33", + "input": "image", + "via_reroute": true, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "34", + "input": "image", + "via_reroute": false, + "source_reference": [ + "38", + 0 + ], + "api": [ + "38", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "4", + "source_type": "DepthAnythingPreprocessor", + "api_type": "DepthAnythingPreprocessor", + "differences": [] + }, + { + "node_id": "5", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "3", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "13", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "12", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "1", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "10", + "source_type": "Canny", + "api_type": "Canny", + "differences": [] + }, + { + "node_id": "11", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "30", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "28", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "29", + "source_type": "ImageStitch", + "api_type": "ImageStitch", + "differences": [] + }, + { + "node_id": "18", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "19", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "20", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "22", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "21", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "2", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "36", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "38", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "37", + "source_type": "PreviewImage", + "api_type": "PreviewImage", + "differences": [] + }, + { + "node_id": "33", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + }, + { + "node_id": "34", + "source_type": "AIO_Preprocessor", + "api_type": "AIO_Preprocessor", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "4", + "differences": [] + }, + { + "node_id": "5", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "13", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "12", + "differences": [] + }, + { + "node_id": "1", + "differences": [] + }, + { + "node_id": "10", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Canny边缘检测", + "actual": "Canny" + } + ] + }, + { + "node_id": "11", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "30", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "28", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "29", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "图像拼接", + "actual": "ImageStitch" + } + ] + }, + { + "node_id": "18", + "differences": [] + }, + { + "node_id": "19", + "differences": [] + }, + { + "node_id": "20", + "differences": [] + }, + { + "node_id": "22", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "21", + "differences": [] + }, + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + } + ] + }, + { + "node_id": "36", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "38", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载图像", + "actual": "LoadImage" + } + ] + }, + { + "node_id": "37", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览图像", + "actual": "PreviewImage" + } + ] + }, + { + "node_id": "33", + "differences": [] + }, + { + "node_id": "34", + "differences": [] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": true, + "executable": false, + "execution_verified": false + }, + { + "id": "02", + "selected_profile": "comfy-frontend-1.37.11-qwen-b037d7be-reference", + "source_path": "example_ComfyUI_workflows/1-语音生成/Qwen3-ASR-Subtitle语音转字幕.json", + "source_sha256": "47f9afa955a6a5dce37000cb6a15bac7516d26ff50b6398bda334c825552cfd8", + "api_sha256": "daa40971b730076691721afe95e165932df94e3423f1fc44dcb7707026e7125b", + "source_frontend_version": "1.37.11", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "2" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "4" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "3" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "1" + } + ], + "production_prompt_available": false, + "serialized_fields": [ + { + "node_id": "6", + "field": "audio", + "source_reference": "ComfyUI-qwenasr_00003_.mp3", + "api": "ComfyUI-qwenasr_00003_.mp3", + "differences": [] + }, + { + "node_id": "6", + "field": "audioUI", + "source_reference": "", + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "", + "kind": "type" + } + ] + }, + { + "node_id": "9", + "field": "model", + "source_reference": "Qwen/Qwen3-ASR-0.6B", + "api": "Qwen/Qwen3-ASR-0.6B", + "differences": [] + }, + { + "node_id": "9", + "field": "precision", + "source_reference": "bf16", + "api": "bf16", + "differences": [] + }, + { + "node_id": "9", + "field": "attention", + "source_reference": "auto", + "api": "auto", + "differences": [] + }, + { + "node_id": "9", + "field": "forced_aligner", + "source_reference": "Qwen/Qwen3-ForcedAligner-0.6B", + "api": "Qwen/Qwen3-ForcedAligner-0.6B", + "differences": [] + }, + { + "node_id": "9", + "field": "language", + "source_reference": "auto", + "api": "auto", + "differences": [] + }, + { + "node_id": "9", + "field": "hints", + "source_reference": "Important terms: ComfyUI, Qwen3-ASR\nUse exact casing for these terms.", + "api": "Important terms: ComfyUI, Qwen3-ASR\nUse exact casing for these terms.", + "differences": [] + }, + { + "node_id": "9", + "field": "output_format", + "source_reference": "none", + "api": "none", + "differences": [] + }, + { + "node_id": "9", + "field": "output_path", + "source_reference": "", + "api": "", + "differences": [] + }, + { + "node_id": "9", + "field": "split_mode", + "source_reference": "split_by_punctuation_or_pause_or_length", + "api": "split_by_punctuation_or_pause_or_length", + "differences": [] + }, + { + "node_id": "9", + "field": "max_gap_sec", + "source_reference": 0.6, + "api": 0.6, + "differences": [] + }, + { + "node_id": "9", + "field": "max_chars", + "source_reference": 40, + "api": 40, + "differences": [] + }, + { + "node_id": "9", + "field": "max_inference_batch_size", + "source_reference": 32, + "api": 32, + "differences": [] + }, + { + "node_id": "9", + "field": "max_new_tokens", + "source_reference": 256, + "api": 256, + "differences": [] + }, + { + "node_id": "9", + "field": "unload_models", + "source_reference": true, + "api": true, + "differences": [] + } + ], + "topology_edges": [ + { + "node_id": "2", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 1 + ], + "api": [ + "9", + 1 + ], + "differences": [] + }, + { + "node_id": "4", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 0 + ], + "api": [ + "9", + 0 + ], + "differences": [] + }, + { + "node_id": "3", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 2 + ], + "api": [ + "9", + 2 + ], + "differences": [] + }, + { + "node_id": "1", + "input": "source", + "via_reroute": false, + "source_reference": [ + "9", + 3 + ], + "api": [ + "9", + 3 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "6", + 0 + ], + "api": [ + "6", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "2", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "4", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "3", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "1", + "type": "PreviewAny", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": { + "id": "2c8bc9f4-6cdd-4d7e-af2b-773c9c169fe3", + "revision": 0, + "last_node_id": 9, + "last_link_id": 18, + "nodes": [ + { + "id": 2, + "type": "PreviewAny", + "pos": [ + 3410, + 5410 + ], + "size": [ + 370, + 180 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "localized_name": "源", + "name": "source", + "type": "*", + "link": 16 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "PreviewAny", + "cnr_id": "comfy-core", + "ver": "0.11.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.5.2" + } + }, + "widgets_values": [ + null, + null, + null + ] + }, + { + "id": 4, + "type": "PreviewAny", + "pos": [ + 3410, + 5190 + ], + "size": [ + 370, + 180 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "localized_name": "源", + "name": "source", + "type": "*", + "link": 15 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "PreviewAny", + "cnr_id": "comfy-core", + "ver": "0.11.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.5.2" + } + }, + "widgets_values": [ + null, + null, + null + ] + }, + { + "id": 3, + "type": "PreviewAny", + "pos": [ + 3410, + 5630 + ], + "size": [ + 370, + 120 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "localized_name": "源", + "name": "source", + "type": "*", + "link": 17 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "PreviewAny", + "cnr_id": "comfy-core", + "ver": "0.11.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.5.2" + } + }, + "widgets_values": [ + null, + null, + null + ] + }, + { + "id": 1, + "type": "PreviewAny", + "pos": [ + 3410, + 5790 + ], + "size": [ + 370, + 120 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "localized_name": "源", + "name": "source", + "type": "*", + "link": 18 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "PreviewAny", + "cnr_id": "comfy-core", + "ver": "0.11.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.5.2" + } + }, + "widgets_values": [ + null, + null, + null + ] + }, + { + "id": 6, + "type": "LoadAudio", + "pos": [ + 2720, + 5190 + ], + "size": [ + 290, + 140 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "音频", + "name": "audio", + "type": "COMBO", + "widget": { + "name": "audio" + }, + "link": null + }, + { + "localized_name": "音频UI", + "name": "audioUI", + "type": "AUDIO_UI", + "widget": { + "name": "audioUI" + }, + "link": null + }, + { + "localized_name": "选择文件上传", + "name": "upload", + "type": "AUDIOUPLOAD", + "widget": { + "name": "upload" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "音频", + "name": "AUDIO", + "type": "AUDIO", + "links": [ + 13 + ] + } + ], + "properties": { + "Node name for S&R": "LoadAudio", + "cnr_id": "comfy-core", + "ver": "0.11.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.5.2" + } + }, + "widgets_values": [ + "ComfyUI-qwenasr_00003_.mp3", + null, + null + ] + }, + { + "id": 9, + "type": "AILab_Qwen3ASRSubtitle", + "pos": [ + 3030, + 5190 + ], + "size": [ + 340, + 460 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [ + { + "localized_name": "audio", + "name": "audio", + "type": "AUDIO", + "link": 13 + }, + { + "localized_name": "model", + "name": "model", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "model" + }, + "link": null + }, + { + "localized_name": "precision", + "name": "precision", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "precision" + }, + "link": null + }, + { + "localized_name": "attention", + "name": "attention", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "attention" + }, + "link": null + }, + { + "localized_name": "forced_aligner", + "name": "forced_aligner", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "forced_aligner" + }, + "link": null + }, + { + "localized_name": "language", + "name": "language", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "language" + }, + "link": null + }, + { + "localized_name": "hints", + "name": "hints", + "shape": 7, + "type": "STRING", + "widget": { + "name": "hints" + }, + "link": null + }, + { + "localized_name": "output_format", + "name": "output_format", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "output_format" + }, + "link": null + }, + { + "localized_name": "output_path", + "name": "output_path", + "shape": 7, + "type": "STRING", + "widget": { + "name": "output_path" + }, + "link": null + }, + { + "localized_name": "split_mode", + "name": "split_mode", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "split_mode" + }, + "link": null + }, + { + "localized_name": "max_gap_sec", + "name": "max_gap_sec", + "shape": 7, + "type": "FLOAT", + "widget": { + "name": "max_gap_sec" + }, + "link": null + }, + { + "localized_name": "max_chars", + "name": "max_chars", + "shape": 7, + "type": "INT", + "widget": { + "name": "max_chars" + }, + "link": null + }, + { + "localized_name": "max_inference_batch_size", + "name": "max_inference_batch_size", + "shape": 7, + "type": "INT", + "widget": { + "name": "max_inference_batch_size" + }, + "link": null + }, + { + "localized_name": "max_new_tokens", + "name": "max_new_tokens", + "shape": 7, + "type": "INT", + "widget": { + "name": "max_new_tokens" + }, + "link": null + }, + { + "localized_name": "unload_models", + "name": "unload_models", + "shape": 7, + "type": "BOOLEAN", + "widget": { + "name": "unload_models" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "TEXT", + "name": "TEXT", + "type": "STRING", + "links": [ + 15 + ] + }, + { + "localized_name": "SUBTITLES", + "name": "SUBTITLES", + "type": "STRING", + "links": [ + 16 + ] + }, + { + "localized_name": "LANUGAGE", + "name": "LANUGAGE", + "type": "STRING", + "links": [ + 17 + ] + }, + { + "localized_name": "OUTPUT_PATH", + "name": "OUTPUT_PATH", + "type": "STRING", + "links": [ + 18 + ] + } + ], + "properties": { + "Node name for S&R": "AILab_Qwen3ASRSubtitle", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.8" + } + }, + "widgets_values": [ + "Qwen/Qwen3-ASR-0.6B", + "bf16", + "auto", + "Qwen/Qwen3-ForcedAligner-0.6B", + "auto", + "Important terms: ComfyUI, Qwen3-ASR\nUse exact casing for these terms.", + "none", + "", + "split_by_punctuation_or_pause_or_length", + 0.6, + 40, + 32, + 256, + true + ], + "color": "#151c19", + "bgcolor": "#444d49" + } + ], + "links": [ + [ + 13, + 6, + 0, + 9, + 0, + "AUDIO" + ], + [ + 15, + 9, + 0, + 4, + 0, + "STRING" + ], + [ + 16, + 9, + 1, + 2, + 0, + "STRING" + ], + [ + 17, + 9, + 2, + 3, + 0, + "STRING" + ], + [ + 18, + 9, + 3, + 1, + 0, + "STRING" + ] + ], + "groups": [], + "config": {}, + "extra": { + "workflowRendererVersion": "LG", + "ue_links": [], + "ds": { + "scale": 0.9185064935064935, + "offset": [ + -2204.8250265111346, + -5021.666666666667 + ] + }, + "links_added_by_ue": [], + "frontendVersion": "1.37.11", + "VHS_latentpreview": false, + "VHS_latentpreviewrate": 0, + "VHS_MetadataImage": true, + "VHS_KeepIntermediate": true + }, + "version": 0.4 + }, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "2", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "4", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "3", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "1", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "6", + "source_type": "LoadAudio", + "api_type": "LoadAudio", + "differences": [] + }, + { + "node_id": "9", + "source_type": "AILab_Qwen3ASRSubtitle", + "api_type": "AILab_Qwen3ASRSubtitle", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "4", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "1", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "6", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载音频", + "actual": "LoadAudio" + } + ] + }, + { + "node_id": "9", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Subtitle (QwenASR)", + "actual": "AILab_Qwen3ASRSubtitle" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [ + { + "node_id": "9", + "field": "normalize_text", + "api_value": true + } + ], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "03", + "selected_profile": "comfy-frontend-1.48.7-structure-reference", + "source_path": "example_ComfyUI_workflows/2-音乐生成/minimax_music_文生音乐.json", + "source_sha256": "0a655ead5a0da406159dceb46451439df0c02050becaaa25b3018abb41840284", + "api_sha256": "91e6c2cea3747a03bbb71f661dbd016b28040781482b956365ff76a7a8b647ce", + "source_frontend_version": "1.48.7", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveAudioAdvanced", + "node_id": "35" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:UNETLoader", + "node_id": "37:6" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxMusic3TextEncode", + "node_id": "37:13" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CLIPLoader", + "node_id": "37:3" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "37:7" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ConditioningZeroOut", + "node_id": "37:10" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:EmptyMiniMaxMusic3LatentAudio", + "node_id": "37:15" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:KSampler", + "node_id": "37:9" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAEDecodeAudio", + "node_id": "37:12" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SeedNode", + "node_id": "37:38" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAEDecodeAudioTiled", + "node_id": "37:42" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ComfySwitchNode", + "node_id": "37:43" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:6", + "input_slot": 0, + "input_name": "unet_name", + "boundary_instance": "37", + "slot": 4, + "name": "unet_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:13", + "input_slot": 1, + "input_name": "caption", + "boundary_instance": "37", + "slot": 0, + "name": "caption", + "type": "STRING", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:13", + "input_slot": 2, + "input_name": "lyrics", + "boundary_instance": "37", + "slot": 1, + "name": "lyrics", + "type": "STRING", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:13", + "input_slot": 4, + "input_name": "max_duration", + "boundary_instance": "37", + "slot": 2, + "name": "max_duration", + "type": "FLOAT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:3", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "37", + "slot": 5, + "name": "clip_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:7", + "input_slot": 0, + "input_name": "vae_name", + "boundary_instance": "37", + "slot": 6, + "name": "vae_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:38", + "input_slot": 0, + "input_name": "seed", + "boundary_instance": "37", + "slot": 3, + "name": "seed", + "type": "INT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "37:43", + "input_slot": 2, + "input_name": "switch", + "boundary_instance": "37", + "slot": 7, + "name": "switch", + "type": "BOOLEAN", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "35", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "37:43", + 0 + ], + "api": [ + "37:43", + 0 + ], + "differences": [] + }, + { + "node_id": "37:13", + "input": "clip", + "via_reroute": false, + "source_reference": [ + "37:3", + 0 + ], + "api": [ + "37:3", + 0 + ], + "differences": [] + }, + { + "node_id": "37:13", + "input": "seed", + "via_reroute": false, + "source_reference": [ + "37:38", + 0 + ], + "api": [ + "37:38", + 0 + ], + "differences": [] + }, + { + "node_id": "37:10", + "input": "conditioning", + "via_reroute": false, + "source_reference": [ + "37:13", + 0 + ], + "api": [ + "37:13", + 0 + ], + "differences": [] + }, + { + "node_id": "37:15", + "input": "seconds", + "via_reroute": false, + "source_reference": [ + "37:13", + 1 + ], + "api": [ + "37:13", + 1 + ], + "differences": [] + }, + { + "node_id": "37:9", + "input": "model", + "via_reroute": false, + "source_reference": [ + "37:6", + 0 + ], + "api": [ + "37:6", + 0 + ], + "differences": [] + }, + { + "node_id": "37:9", + "input": "positive", + "via_reroute": false, + "source_reference": [ + "37:13", + 0 + ], + "api": [ + "37:13", + 0 + ], + "differences": [] + }, + { + "node_id": "37:9", + "input": "negative", + "via_reroute": false, + "source_reference": [ + "37:10", + 0 + ], + "api": [ + "37:10", + 0 + ], + "differences": [] + }, + { + "node_id": "37:9", + "input": "latent_image", + "via_reroute": false, + "source_reference": [ + "37:15", + 0 + ], + "api": [ + "37:15", + 0 + ], + "differences": [] + }, + { + "node_id": "37:9", + "input": "seed", + "via_reroute": false, + "source_reference": [ + "37:38", + 0 + ], + "api": [ + "37:38", + 0 + ], + "differences": [] + }, + { + "node_id": "37:12", + "input": "samples", + "via_reroute": false, + "source_reference": [ + "37:9", + 0 + ], + "api": [ + "37:9", + 0 + ], + "differences": [] + }, + { + "node_id": "37:12", + "input": "vae", + "via_reroute": false, + "source_reference": [ + "37:7", + 0 + ], + "api": [ + "37:7", + 0 + ], + "differences": [] + }, + { + "node_id": "37:42", + "input": "samples", + "via_reroute": false, + "source_reference": [ + "37:9", + 0 + ], + "api": [ + "37:9", + 0 + ], + "differences": [] + }, + { + "node_id": "37:42", + "input": "vae", + "via_reroute": false, + "source_reference": [ + "37:7", + 0 + ], + "api": [ + "37:7", + 0 + ], + "differences": [] + }, + { + "node_id": "37:43", + "input": "on_false", + "via_reroute": false, + "source_reference": [ + "37:12", + 0 + ], + "api": [ + "37:12", + 0 + ], + "differences": [] + }, + { + "node_id": "37:43", + "input": "on_true", + "via_reroute": false, + "source_reference": [ + "37:42", + 0 + ], + "api": [ + "37:42", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "35", + "type": "SaveAudioAdvanced", + "reason": "未知参考版本" + }, + { + "node_id": "37:6", + "type": "UNETLoader", + "reason": "未知参考版本" + }, + { + "node_id": "37:13", + "type": "MiniMaxMusic3TextEncode", + "reason": "未知参考版本" + }, + { + "node_id": "37:3", + "type": "CLIPLoader", + "reason": "未知参考版本" + }, + { + "node_id": "37:7", + "type": "VAELoader", + "reason": "未知参考版本" + }, + { + "node_id": "37:10", + "type": "ConditioningZeroOut", + "reason": "未知参考版本" + }, + { + "node_id": "37:15", + "type": "EmptyMiniMaxMusic3LatentAudio", + "reason": "未知参考版本" + }, + { + "node_id": "37:9", + "type": "KSampler", + "reason": "未知参考版本" + }, + { + "node_id": "37:12", + "type": "VAEDecodeAudio", + "reason": "未知参考版本" + }, + { + "node_id": "37:38", + "type": "SeedNode", + "reason": "未知参考版本" + }, + { + "node_id": "37:42", + "type": "VAEDecodeAudioTiled", + "reason": "未知参考版本" + }, + { + "node_id": "37:43", + "type": "ComfySwitchNode", + "reason": "未知参考版本" + } + ], + "diagnostic_graph": { + "nodes": [ + { + "id": "35", + "type": "SaveAudioAdvanced", + "pos": [ + 2150, + 630 + ], + "size": [ + 750, + 160 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "localized_name": "audio", + "name": "audio", + "type": "AUDIO", + "link": 1 + }, + { + "localized_name": "filename_prefix", + "name": "filename_prefix", + "type": "STRING", + "widget": { + "name": "filename_prefix" + }, + "link": null + }, + { + "localized_name": "format", + "name": "format", + "type": "COMFY_DYNAMICCOMBO_V3", + "widget": { + "name": "format" + }, + "link": null + }, + { + "localized_name": "format.quality", + "name": "format.quality", + "type": "COMBO", + "widget": { + "name": "format.quality" + }, + "link": null + }, + { + "localized_name": "audioUI", + "name": "audioUI", + "type": "AUDIO_UI", + "widget": { + "name": "audioUI" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "audio", + "name": "audio", + "type": "AUDIO", + "links": [] + } + ], + "properties": { + "Node name for S&R": "SaveAudioAdvanced", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "audio/audio_minimax_music3", + "mp3", + "V0" + ], + "widgets_values_named": { + "filename_prefix": "audio/audio_minimax_music3", + "format": "mp3", + "format.quality": "V0" + } + }, + { + "id": "39", + "type": "MarkdownNote", + "pos": [ + 1050, + 630 + ], + "size": [ + 520, + 660 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [], + "title": "Note: MiniMax Music 3", + "properties": { + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "## MiniMax Music 3\n\nA music generation model by MiniMax that creates complete songs up to 5 minutes long with stable structure and high audio quality. Two inputs drive it: **Caption** (structured music description: style, mood, vocals, arrangement) and **Lyrics** (with `[intro]` `[verse]` `[chorus]` `[bridge]` `[outro]` tags controlling song structure).\n\n### Parameters\n\n| Parameter | Description |\n|---|---|\n| Caption | Music description. Write it in three sections — Global Metadata → Vocal Details → Arrangement. The more specific, the closer the result. |\n| Lyrics | Song lyrics + section tags. Tags are the only executable structural instructions; the lyric text itself only conveys mood. |\n| max_duration | Target song length in seconds (default 120 = 2 minutes; the model supports up to ~300 s / 5 minutes). Longer songs take more time and VRAM. |\n| seed | Random seed for the generation. Keep it fixed to reproduce the same song; change it to get a different take. |\n| Model files | diffusion model / text encoder / VAE.|\n| Tiled decode | Decode the audio VAE in overlapping tiles to drastically cut VRAM usage — helpful for long songs on low-VRAM GPUs. Slightly slower, with a small risk of seams at tile boundaries; turn it off on high-VRAM GPUs for the best quality. |\n\n### Prompt Writing Guide\n\nYou can find an official [Music Caption Rewriter Skill here](https://github.com/MiniMax-AI/MiniMax-Music3)" + ], + "widgets_values_named": { + "text": "## MiniMax Music 3\n\nA music generation model by MiniMax that creates complete songs up to 5 minutes long with stable structure and high audio quality. Two inputs drive it: **Caption** (structured music description: style, mood, vocals, arrangement) and **Lyrics** (with `[intro]` `[verse]` `[chorus]` `[bridge]` `[outro]` tags controlling song structure).\n\n### Parameters\n\n| Parameter | Description |\n|---|---|\n| Caption | Music description. Write it in three sections — Global Metadata → Vocal Details → Arrangement. The more specific, the closer the result. |\n| Lyrics | Song lyrics + section tags. Tags are the only executable structural instructions; the lyric text itself only conveys mood. |\n| max_duration | Target song length in seconds (default 120 = 2 minutes; the model supports up to ~300 s / 5 minutes). Longer songs take more time and VRAM. |\n| seed | Random seed for the generation. Keep it fixed to reproduce the same song; change it to get a different take. |\n| Model files | diffusion model / text encoder / VAE.|\n| Tiled decode | Decode the audio VAE in overlapping tiles to drastically cut VRAM usage — helpful for long songs on low-VRAM GPUs. Slightly slower, with a small risk of seams at tile boundaries; turn it off on high-VRAM GPUs for the best quality. |\n\n### Prompt Writing Guide\n\nYou can find an official [Music Caption Rewriter Skill here](https://github.com/MiniMax-AI/MiniMax-Music3)" + }, + "color": "#222", + "bgcolor": "#000" + }, + { + "id": "40", + "type": "MarkdownNote", + "pos": [ + 560, + 630 + ], + "size": [ + 440, + 680 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [], + "properties": { + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "## Model Links\n\n**diffusion_models**\n- [minimax_music3_dit_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/diffusion_models/minimax_music3_dit_int8_convrot.safetensors) # For low VRAM\n- [minimax_music3_dit_fp16.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/diffusion_models/minimax_music3_dit_fp16.safetensors)\n\n**text_encoders**\n\n- [minimax_music3_text_encoder_pruned_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/text_encoders/minimax_music3_text_encoder_pruned_int8_convrot.safetensors)\n\n**vae**\n\n- [minimax_music3_dav.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/vae/minimax_music3_dav.safetensors)\n\n\n## Model Storage Location\n\n```\n📂 ComfyUI/\n├── 📂 models/\n│ ├── 📂 diffusion_models/\n│ │ ├── minimax_music3_dit_int8_convrot.safetensors # For low VRAM\n│ │ └── minimax_music3_dit_fp16.safetensors\n│ ├── 📂 text_encoders/\n│ │ └── minimax_music3_text_encoder_pruned_int8_convrot.safetensors\n│ └── 📂 vae/\n│ └── minimax_music3_dav.safetensors\n```\n\n## Report Issue\n\nNote: Please update ComfyUI first ([guide](https://docs.comfy.org/installation/update_comfyui)) and prepare required models. Desktop/Cloud updates follow stable releases, so some nightly-supported models may not be available yet.\n\n- Cannot run / runtime errors: [ComfyUI/issues](https://github.com/comfyanonymous/ComfyUI/issues)\n- UI / frontend issues: [ComfyUI_frontend/issues](https://github.com/Comfy-Org/ComfyUI_frontend/issues)\n- Workflow issues: [workflow_templates/issues](https://github.com/Comfy-Org/workflow_templates/issues)\n" + ], + "widgets_values_named": { + "text": "## Model Links\n\n**diffusion_models**\n- [minimax_music3_dit_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/diffusion_models/minimax_music3_dit_int8_convrot.safetensors) # For low VRAM\n- [minimax_music3_dit_fp16.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/diffusion_models/minimax_music3_dit_fp16.safetensors)\n\n**text_encoders**\n\n- [minimax_music3_text_encoder_pruned_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/text_encoders/minimax_music3_text_encoder_pruned_int8_convrot.safetensors)\n\n**vae**\n\n- [minimax_music3_dav.safetensors](https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/vae/minimax_music3_dav.safetensors)\n\n\n## Model Storage Location\n\n```\n📂 ComfyUI/\n├── 📂 models/\n│ ├── 📂 diffusion_models/\n│ │ ├── minimax_music3_dit_int8_convrot.safetensors # For low VRAM\n│ │ └── minimax_music3_dit_fp16.safetensors\n│ ├── 📂 text_encoders/\n│ │ └── minimax_music3_text_encoder_pruned_int8_convrot.safetensors\n│ └── 📂 vae/\n│ └── minimax_music3_dav.safetensors\n```\n\n## Report Issue\n\nNote: Please update ComfyUI first ([guide](https://docs.comfy.org/installation/update_comfyui)) and prepare required models. Desktop/Cloud updates follow stable releases, so some nightly-supported models may not be available yet.\n\n- Cannot run / runtime errors: [ComfyUI/issues](https://github.com/comfyanonymous/ComfyUI/issues)\n- UI / frontend issues: [ComfyUI_frontend/issues](https://github.com/Comfy-Org/ComfyUI_frontend/issues)\n- Workflow issues: [workflow_templates/issues](https://github.com/Comfy-Org/workflow_templates/issues)\n" + }, + "color": "#222", + "bgcolor": "#000" + }, + { + "id": "37:6", + "type": "UNETLoader", + "pos": [ + 700, + 380 + ], + "size": [ + 480, + 90 + ], + "flags": {}, + "order": 1, + "mode": 0, + "showAdvanced": false, + "inputs": [ + { + "localized_name": "UNet名称", + "name": "unet_name", + "type": "COMBO", + "widget": { + "name": "unet_name" + }, + "link": null + }, + { + "localized_name": "数据类型", + "name": "weight_dtype", + "type": "COMBO", + "widget": { + "name": "weight_dtype" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "模型", + "name": "MODEL", + "type": "MODEL", + "links": [ + 6 + ] + } + ], + "properties": { + "Node name for S&R": "UNETLoader", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "models": [ + { + "name": "minimax_music3_dit_fp16.safetensors", + "url": "https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/diffusion_models/minimax_music3_dit_fp16.safetensors", + "directory": "diffusion_models" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "minimax_music3_dit_fp16.safetensors", + "default" + ], + "widgets_values_named": { + "unet_name": "minimax_music3_dit_fp16.safetensors", + "weight_dtype": "default" + } + }, + { + "id": "37:13", + "type": "MiniMaxMusic3TextEncode", + "pos": [ + 1230, + 380 + ], + "size": [ + 500, + 750 + ], + "flags": {}, + "order": 6, + "mode": 0, + "showAdvanced": true, + "inputs": [ + { + "localized_name": "clip", + "name": "clip", + "type": "CLIP", + "link": 2 + }, + { + "localized_name": "caption", + "name": "caption", + "type": "STRING", + "widget": { + "name": "caption" + }, + "link": null + }, + { + "localized_name": "lyrics", + "name": "lyrics", + "type": "STRING", + "widget": { + "name": "lyrics" + }, + "link": null + }, + { + "localized_name": "seed", + "name": "seed", + "type": "INT", + "widget": { + "name": "seed" + }, + "link": 3 + }, + { + "localized_name": "max_duration", + "name": "max_duration", + "type": "FLOAT", + "widget": { + "name": "max_duration" + }, + "link": null + }, + { + "localized_name": "cfg_scale", + "name": "cfg_scale", + "type": "FLOAT", + "widget": { + "name": "cfg_scale" + }, + "link": null + }, + { + "localized_name": "top_k", + "name": "top_k", + "type": "INT", + "widget": { + "name": "top_k" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "条件", + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 4, + 7 + ] + }, + { + "localized_name": "seconds", + "name": "seconds", + "type": "FLOAT", + "links": [ + 5 + ] + } + ], + "properties": { + "Node name for S&R": "MiniMaxMusic3TextEncode", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "", + "", + 222, + "fixed", + 60, + 1.7, + 50 + ], + "widgets_values_named": { + "caption": "", + "lyrics": "", + "seed": 222, + "control_after_generate": "fixed", + "max_duration": 60, + "cfg_scale": 1.7, + "top_k": 50 + } + }, + { + "id": "37:3", + "type": "CLIPLoader", + "pos": [ + 700, + 550 + ], + "size": [ + 480, + 120 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "CLIP名称", + "name": "clip_name", + "type": "COMBO", + "widget": { + "name": "clip_name" + }, + "link": null + }, + { + "localized_name": "类型", + "name": "type", + "type": "COMBO", + "widget": { + "name": "type" + }, + "link": null + }, + { + "localized_name": "设备", + "name": "device", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "device" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "CLIP", + "name": "CLIP", + "type": "CLIP", + "links": [ + 2 + ] + } + ], + "properties": { + "Node name for S&R": "CLIPLoader", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "models": [ + { + "name": "minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "url": "https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/text_encoders/minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "directory": "text_encoders" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "minimax", + "default" + ], + "widgets_values_named": { + "clip_name": "minimax_music3_text_encoder_pruned_int8_convrot.safetensors", + "type": "minimax", + "device": "default" + } + }, + { + "id": "37:7", + "type": "VAELoader", + "pos": [ + 700, + 750 + ], + "size": [ + 480, + 70 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [ + { + "localized_name": "vae名称", + "name": "vae_name", + "type": "COMBO", + "widget": { + "name": "vae_name" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "VAE", + "name": "VAE", + "type": "VAE", + "links": [ + 12, + 14 + ] + } + ], + "properties": { + "Node name for S&R": "VAELoader", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "models": [ + { + "name": "minimax_music3_dav.safetensors", + "url": "https://huggingface.co/Comfy-Org/MiniMax-Music-3/resolve/main/vae/minimax_music3_dav.safetensors", + "directory": "vae" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "minimax_music3_dav.safetensors" + ], + "widgets_values_named": { + "vae_name": "minimax_music3_dav.safetensors" + } + }, + { + "id": "37:10", + "type": "ConditioningZeroOut", + "pos": [ + 1820, + 540 + ], + "size": [ + 230, + 40 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "localized_name": "条件", + "name": "conditioning", + "type": "CONDITIONING", + "link": 4 + } + ], + "outputs": [ + { + "localized_name": "条件", + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 8 + ] + } + ], + "properties": { + "Node name for S&R": "ConditioningZeroOut", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + } + }, + { + "id": "37:15", + "type": "EmptyMiniMaxMusic3LatentAudio", + "pos": [ + 1780, + 380 + ], + "size": [ + 350, + 90 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "localized_name": "seconds", + "name": "seconds", + "type": "FLOAT", + "widget": { + "name": "seconds" + }, + "link": 5 + }, + { + "localized_name": "batch_size", + "name": "batch_size", + "type": "INT", + "widget": { + "name": "batch_size" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "Latent", + "name": "LATENT", + "type": "LATENT", + "links": [ + 9 + ] + } + ], + "properties": { + "Node name for S&R": "EmptyMiniMaxMusic3LatentAudio", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 120, + 1 + ], + "widgets_values_named": { + "seconds": 120, + "batch_size": 1 + } + }, + { + "id": "37:9", + "type": "KSampler", + "pos": [ + 2170, + 380 + ], + "size": [ + 370, + 270 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "localized_name": "模型", + "name": "model", + "type": "MODEL", + "link": 6 + }, + { + "localized_name": "正面条件", + "name": "positive", + "type": "CONDITIONING", + "link": 7 + }, + { + "localized_name": "负面条件", + "name": "negative", + "type": "CONDITIONING", + "link": 8 + }, + { + "localized_name": "Latent图像", + "name": "latent_image", + "type": "LATENT", + "link": 9 + }, + { + "localized_name": "种子", + "name": "seed", + "type": "INT", + "widget": { + "name": "seed" + }, + "link": 10 + }, + { + "localized_name": "步数", + "name": "steps", + "type": "INT", + "widget": { + "name": "steps" + }, + "link": null + }, + { + "localized_name": "cfg", + "name": "cfg", + "type": "FLOAT", + "widget": { + "name": "cfg" + }, + "link": null + }, + { + "localized_name": "采样器名称", + "name": "sampler_name", + "type": "COMBO", + "widget": { + "name": "sampler_name" + }, + "link": null + }, + { + "localized_name": "调度器", + "name": "scheduler", + "type": "COMBO", + "widget": { + "name": "scheduler" + }, + "link": null + }, + { + "localized_name": "降噪", + "name": "denoise", + "type": "FLOAT", + "widget": { + "name": "denoise" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "Latent", + "name": "LATENT", + "type": "LATENT", + "links": [ + 11, + 13 + ] + } + ], + "properties": { + "Node name for S&R": "KSampler", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 1111111112, + "fixed", + 30, + 1.7, + "euler", + "simple", + 1 + ], + "widgets_values_named": { + "seed": 1111111112, + "control_after_generate": "fixed", + "steps": 30, + "cfg": 1.7, + "sampler_name": "euler", + "scheduler": "simple", + "denoise": 1 + } + }, + { + "id": "37:12", + "type": "VAEDecodeAudio", + "pos": [ + 2590, + 380 + ], + "size": [ + 230, + 60 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "localized_name": "Latent", + "name": "samples", + "type": "LATENT", + "link": 11 + }, + { + "localized_name": "vae", + "name": "vae", + "type": "VAE", + "link": 12 + } + ], + "outputs": [ + { + "localized_name": "音频", + "name": "AUDIO", + "type": "AUDIO", + "links": [ + 15 + ] + } + ], + "properties": { + "Node name for S&R": "VAEDecodeAudio", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + } + }, + { + "id": "37:38", + "type": "SeedNode", + "pos": [ + 890, + 970 + ], + "size": [ + 270, + 90 + ], + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "localized_name": "种子", + "name": "seed", + "type": "INT", + "widget": { + "name": "seed" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "种子", + "name": "seed", + "type": "INT", + "links": [ + 3, + 10 + ] + } + ], + "properties": { + "Node name for S&R": "SeedNode", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 0, + "randomize" + ], + "widgets_values_named": { + "seed": 0, + "fixed": "randomize" + } + }, + { + "id": "37:42", + "type": "VAEDecodeAudioTiled", + "pos": [ + 2580, + 500 + ], + "size": [ + 280, + 110 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "localized_name": "样本", + "name": "samples", + "type": "LATENT", + "link": 13 + }, + { + "localized_name": "vae", + "name": "vae", + "type": "VAE", + "link": 14 + }, + { + "localized_name": "分块大小", + "name": "tile_size", + "type": "INT", + "widget": { + "name": "tile_size" + }, + "link": null + }, + { + "localized_name": "重叠", + "name": "overlap", + "type": "INT", + "widget": { + "name": "overlap" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "音频", + "name": "AUDIO", + "type": "AUDIO", + "links": [ + 16 + ] + } + ], + "properties": { + "Node name for S&R": "VAEDecodeAudioTiled", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 1536, + 64 + ], + "widgets_values_named": { + "tile_size": 1536, + "overlap": 64 + } + }, + { + "id": "37:43", + "type": "ComfySwitchNode", + "pos": [ + 2600, + 690 + ], + "size": [ + 270, + 110 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "localized_name": "为假时", + "name": "on_false", + "type": "AUDIO", + "link": 15 + }, + { + "localized_name": "为真时", + "name": "on_true", + "type": "AUDIO", + "link": 16 + }, + { + "localized_name": "切换", + "name": "switch", + "type": "BOOLEAN", + "widget": { + "name": "switch" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "输出", + "name": "output", + "type": "AUDIO", + "links": [ + 1 + ] + } + ], + "properties": { + "Node name for S&R": "ComfySwitchNode", + "cnr_id": "comfy-core", + "ver": "0.31.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + false + ], + "widgets_values_named": { + "switch": false + } + } + ], + "links": [ + [ + 1, + "37:43", + 0, + "35", + 0, + "AUDIO" + ], + [ + 2, + "37:3", + 0, + "37:13", + 0, + "CLIP" + ], + [ + 3, + "37:38", + 0, + "37:13", + 3, + "INT" + ], + [ + 4, + "37:13", + 0, + "37:10", + 0, + "CONDITIONING" + ], + [ + 5, + "37:13", + 1, + "37:15", + 0, + "FLOAT" + ], + [ + 6, + "37:6", + 0, + "37:9", + 0, + "MODEL" + ], + [ + 7, + "37:13", + 0, + "37:9", + 1, + "CONDITIONING" + ], + [ + 8, + "37:10", + 0, + "37:9", + 2, + "CONDITIONING" + ], + [ + 9, + "37:15", + 0, + "37:9", + 3, + "LATENT" + ], + [ + 10, + "37:38", + 0, + "37:9", + 4, + "INT" + ], + [ + 11, + "37:9", + 0, + "37:12", + 0, + "LATENT" + ], + [ + 12, + "37:7", + 0, + "37:12", + 1, + "VAE" + ], + [ + 13, + "37:9", + 0, + "37:42", + 0, + "LATENT" + ], + [ + 14, + "37:7", + 0, + "37:42", + 1, + "VAE" + ], + [ + 15, + "37:12", + 0, + "37:43", + 0, + "AUDIO" + ], + [ + 16, + "37:42", + 0, + "37:43", + 1, + "AUDIO" + ] + ], + "extra": { + "ds": { + "scale": 0.9826840677966108, + "offset": [ + -730.5261380305367, + -308.63836113860924 + ] + }, + "frontendVersion": "1.48.7", + "VHS_latentpreview": false, + "VHS_latentpreviewrate": 0, + "VHS_MetadataImage": true, + "VHS_KeepIntermediate": true, + "ue_links": [], + "links_added_by_ue": [] + } + }, + "unresolved_boundaries": [ + { + "node_id": "37:6", + "input_slot": 0, + "input_name": "unet_name", + "boundary_instance": "37", + "slot": 4, + "name": "unet_name", + "type": "COMBO" + }, + { + "node_id": "37:13", + "input_slot": 1, + "input_name": "caption", + "boundary_instance": "37", + "slot": 0, + "name": "caption", + "type": "STRING" + }, + { + "node_id": "37:13", + "input_slot": 2, + "input_name": "lyrics", + "boundary_instance": "37", + "slot": 1, + "name": "lyrics", + "type": "STRING" + }, + { + "node_id": "37:13", + "input_slot": 4, + "input_name": "max_duration", + "boundary_instance": "37", + "slot": 2, + "name": "max_duration", + "type": "FLOAT" + }, + { + "node_id": "37:3", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "37", + "slot": 5, + "name": "clip_name", + "type": "COMBO" + }, + { + "node_id": "37:7", + "input_slot": 0, + "input_name": "vae_name", + "boundary_instance": "37", + "slot": 6, + "name": "vae_name", + "type": "COMBO" + }, + { + "node_id": "37:38", + "input_slot": 0, + "input_name": "seed", + "boundary_instance": "37", + "slot": 3, + "name": "seed", + "type": "INT" + }, + { + "node_id": "37:43", + "input_slot": 2, + "input_name": "switch", + "boundary_instance": "37", + "slot": 7, + "name": "switch", + "type": "BOOLEAN" + } + ], + "node_types": [ + { + "node_id": "35", + "source_type": "SaveAudioAdvanced", + "api_type": "SaveAudioAdvanced", + "differences": [] + }, + { + "node_id": "37:6", + "source_type": "UNETLoader", + "api_type": "UNETLoader", + "differences": [] + }, + { + "node_id": "37:13", + "source_type": "MiniMaxMusic3TextEncode", + "api_type": "MiniMaxMusic3TextEncode", + "differences": [] + }, + { + "node_id": "37:3", + "source_type": "CLIPLoader", + "api_type": "CLIPLoader", + "differences": [] + }, + { + "node_id": "37:7", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "37:10", + "source_type": "ConditioningZeroOut", + "api_type": "ConditioningZeroOut", + "differences": [] + }, + { + "node_id": "37:15", + "source_type": "EmptyMiniMaxMusic3LatentAudio", + "api_type": "EmptyMiniMaxMusic3LatentAudio", + "differences": [] + }, + { + "node_id": "37:9", + "source_type": "KSampler", + "api_type": "KSampler", + "differences": [] + }, + { + "node_id": "37:12", + "source_type": "VAEDecodeAudio", + "api_type": "VAEDecodeAudio", + "differences": [] + }, + { + "node_id": "37:38", + "source_type": "SeedNode", + "api_type": "SeedNode", + "differences": [] + }, + { + "node_id": "37:42", + "source_type": "VAEDecodeAudioTiled", + "api_type": "VAEDecodeAudioTiled", + "differences": [] + }, + { + "node_id": "37:43", + "source_type": "ComfySwitchNode", + "api_type": "ComfySwitchNode", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "35", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存音频(高级)", + "actual": "SaveAudioAdvanced" + } + ] + }, + { + "node_id": "37:6", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "UNet加载器", + "actual": "UNETLoader" + } + ] + }, + { + "node_id": "37:13", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax Music3 文本编码", + "actual": "MiniMaxMusic3TextEncode" + } + ] + }, + { + "node_id": "37:3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载CLIP", + "actual": "CLIPLoader" + } + ] + }, + { + "node_id": "37:7", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "37:10", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "条件零化", + "actual": "ConditioningZeroOut" + } + ] + }, + { + "node_id": "37:15", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "空 MiniMax Music3 潜空间音频", + "actual": "EmptyMiniMaxMusic3LatentAudio" + } + ] + }, + { + "node_id": "37:9", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "K采样器", + "actual": "KSampler" + } + ] + }, + { + "node_id": "37:12", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "VAE解码(音频)", + "actual": "VAEDecodeAudio" + } + ] + }, + { + "node_id": "37:38", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "种子", + "actual": "SeedNode" + } + ] + }, + { + "node_id": "37:42", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "VAE解码音频(分块)", + "actual": "VAEDecodeAudioTiled" + } + ] + }, + { + "node_id": "37:43", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "切换", + "actual": "ComfySwitchNode" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "04", + "selected_profile": "comfy-frontend-1.53.6-structure-reference", + "source_path": "example_ComfyUI_workflows/3-图像生成/Qwen-Image-2.1/Qwen_image2.1_文生图_提示词增强.json", + "source_sha256": "dfe10917d101bf1a8a8c20750f4360690ecd478e9eb33d16a59ea0c6f12c086c", + "api_sha256": "2066b07b2ca5390ba3e795df6b43934dab83865b12870b6ff26d8c0ef24f091e", + "source_frontend_version": "1.53.6", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ResolutionSelector", + "node_id": "13" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:UNETLoader", + "node_id": "459:451" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:TextEncodeQwenImage21", + "node_id": "459:452" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CLIPLoader", + "node_id": "459:453" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "459:454" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:EmptyLatentImage", + "node_id": "459:456" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAEDecode", + "node_id": "459:457" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:KSampler", + "node_id": "459:458" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:TextGenerate", + "node_id": "459:471" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PreviewAny", + "node_id": "459:472" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CLIPLoader", + "node_id": "459:473" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ComfySwitchNode", + "node_id": "459:474" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveStringMultiline", + "node_id": "459:475" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:QwenImage21Cache", + "node_id": "459:480" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveImageAdvanced", + "node_id": "461" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:PrimitiveStringMultiline", + "node_id": "483" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:451", + "input_slot": 0, + "input_name": "unet_name", + "boundary_instance": "459", + "slot": 11, + "name": "unet_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:452", + "input_slot": 4, + "input_name": "negative_prompt", + "boundary_instance": "459", + "slot": 3, + "name": "negative_prompt", + "type": "STRING", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:453", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "459", + "slot": 12, + "name": "clip_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:454", + "input_slot": 0, + "input_name": "vae_name", + "boundary_instance": "459", + "slot": 13, + "name": "vae_name", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:458", + "input_slot": 4, + "input_name": "seed", + "boundary_instance": "459", + "slot": 10, + "name": "seed", + "type": "INT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:458", + "input_slot": 5, + "input_name": "steps", + "boundary_instance": "459", + "slot": 5, + "name": "steps", + "type": "INT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:458", + "input_slot": 6, + "input_name": "cfg", + "boundary_instance": "459", + "slot": 4, + "name": "cfg", + "type": "FLOAT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:458", + "input_slot": 7, + "input_name": "sampler_name", + "boundary_instance": "459", + "slot": 8, + "name": "scheduler", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:458", + "input_slot": 8, + "input_name": "scheduler", + "boundary_instance": "459", + "slot": 9, + "name": "scheduler_1", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:471", + "input_slot": 13, + "input_name": "sampling_mode.seed", + "boundary_instance": "459", + "slot": 10, + "name": "seed", + "type": "INT", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:471", + "input_slot": 15, + "input_name": "thinking", + "boundary_instance": "459", + "slot": 2, + "name": "thinking", + "type": "BOOLEAN", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:473", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "459", + "slot": 14, + "name": "clip_name_1", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:474", + "input_slot": 2, + "input_name": "switch", + "boundary_instance": "459", + "slot": 1, + "name": "switch", + "type": "BOOLEAN", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:480", + "input_slot": 1, + "input_name": "device", + "boundary_instance": "459", + "slot": 15, + "name": "device", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + }, + { + "code": "boundary_widget_unverified", + "node_id": "459:480", + "input_slot": 2, + "input_name": "dtype", + "boundary_instance": "459", + "slot": 16, + "name": "dtype_1", + "type": "COMBO", + "message": "边界无外部连线;不按位置猜 promoted widget 值" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "459:452", + "input": "clip", + "via_reroute": false, + "source_reference": [ + "459:453", + 0 + ], + "api": [ + "459:453", + 0 + ], + "differences": [] + }, + { + "node_id": "459:452", + "input": "prompt", + "via_reroute": false, + "source_reference": [ + "459:472", + 0 + ], + "api": [ + "459:472", + 0 + ], + "differences": [] + }, + { + "node_id": "459:456", + "input": "width", + "via_reroute": false, + "source_reference": [ + "13", + 0 + ], + "api": [ + "13", + 0 + ], + "differences": [] + }, + { + "node_id": "459:456", + "input": "height", + "via_reroute": false, + "source_reference": [ + "13", + 1 + ], + "api": [ + "13", + 1 + ], + "differences": [] + }, + { + "node_id": "459:457", + "input": "samples", + "via_reroute": false, + "source_reference": [ + "459:458", + 0 + ], + "api": [ + "459:458", + 0 + ], + "differences": [] + }, + { + "node_id": "459:457", + "input": "vae", + "via_reroute": false, + "source_reference": [ + "459:454", + 0 + ], + "api": [ + "459:454", + 0 + ], + "differences": [] + }, + { + "node_id": "459:458", + "input": "model", + "via_reroute": false, + "source_reference": [ + "459:480", + 0 + ], + "api": [ + "459:480", + 0 + ], + "differences": [] + }, + { + "node_id": "459:458", + "input": "positive", + "via_reroute": false, + "source_reference": [ + "459:452", + 0 + ], + "api": [ + "459:452", + 0 + ], + "differences": [] + }, + { + "node_id": "459:458", + "input": "negative", + "via_reroute": false, + "source_reference": [ + "459:452", + 1 + ], + "api": [ + "459:452", + 1 + ], + "differences": [] + }, + { + "node_id": "459:458", + "input": "latent_image", + "via_reroute": false, + "source_reference": [ + "459:456", + 0 + ], + "api": [ + "459:456", + 0 + ], + "differences": [] + }, + { + "node_id": "459:471", + "input": "clip", + "via_reroute": false, + "source_reference": [ + "459:473", + 0 + ], + "api": [ + "459:473", + 0 + ], + "differences": [] + }, + { + "node_id": "459:471", + "input": "system_prompt", + "via_reroute": false, + "source_reference": [ + "459:475", + 0 + ], + "api": [ + "459:475", + 0 + ], + "differences": [] + }, + { + "node_id": "459:471", + "input": "prompt", + "via_reroute": false, + "source_reference": [ + "483", + 0 + ], + "api": [ + "483", + 0 + ], + "differences": [] + }, + { + "node_id": "459:472", + "input": "source", + "via_reroute": false, + "source_reference": [ + "459:474", + 0 + ], + "api": [ + "459:474", + 0 + ], + "differences": [] + }, + { + "node_id": "459:474", + "input": "on_false", + "via_reroute": false, + "source_reference": [ + "483", + 0 + ], + "api": [ + "483", + 0 + ], + "differences": [] + }, + { + "node_id": "459:474", + "input": "on_true", + "via_reroute": false, + "source_reference": [ + "459:471", + 0 + ], + "api": [ + "459:471", + 0 + ], + "differences": [] + }, + { + "node_id": "459:480", + "input": "model", + "via_reroute": false, + "source_reference": [ + "459:451", + 0 + ], + "api": [ + "459:451", + 0 + ], + "differences": [] + }, + { + "node_id": "461", + "input": "images", + "via_reroute": false, + "source_reference": [ + "459:457", + 0 + ], + "api": [ + "459:457", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "13", + "type": "ResolutionSelector", + "reason": "未知参考版本" + }, + { + "node_id": "459:451", + "type": "UNETLoader", + "reason": "未知参考版本" + }, + { + "node_id": "459:452", + "type": "TextEncodeQwenImage21", + "reason": "未知参考版本" + }, + { + "node_id": "459:453", + "type": "CLIPLoader", + "reason": "未知参考版本" + }, + { + "node_id": "459:454", + "type": "VAELoader", + "reason": "未知参考版本" + }, + { + "node_id": "459:456", + "type": "EmptyLatentImage", + "reason": "未知参考版本" + }, + { + "node_id": "459:457", + "type": "VAEDecode", + "reason": "未知参考版本" + }, + { + "node_id": "459:458", + "type": "KSampler", + "reason": "未知参考版本" + }, + { + "node_id": "459:471", + "type": "TextGenerate", + "reason": "未知参考版本" + }, + { + "node_id": "459:472", + "type": "PreviewAny", + "reason": "未知参考版本" + }, + { + "node_id": "459:473", + "type": "CLIPLoader", + "reason": "未知参考版本" + }, + { + "node_id": "459:474", + "type": "ComfySwitchNode", + "reason": "未知参考版本" + }, + { + "node_id": "459:475", + "type": "PrimitiveStringMultiline", + "reason": "未知参考版本" + }, + { + "node_id": "459:480", + "type": "QwenImage21Cache", + "reason": "未知参考版本" + }, + { + "node_id": "461", + "type": "SaveImageAdvanced", + "reason": "未知参考版本" + }, + { + "node_id": "483", + "type": "PrimitiveStringMultiline", + "reason": "未知参考版本" + } + ], + "diagnostic_graph": { + "nodes": [ + { + "id": "13", + "type": "ResolutionSelector", + "pos": [ + 510, + 2820 + ], + "size": [ + 310, + 150 + ], + "flags": {}, + "order": 0, + "mode": 0, + "showAdvanced": false, + "inputs": [ + { + "localized_name": "宽高比", + "name": "aspect_ratio", + "type": "COMBO", + "widget": { + "name": "aspect_ratio" + }, + "link": null + }, + { + "localized_name": "百万像素", + "name": "megapixels", + "type": "FLOAT", + "widget": { + "name": "megapixels" + }, + "link": null + }, + { + "localized_name": "倍数", + "name": "multiple", + "type": "INT", + "widget": { + "name": "multiple" + }, + "link": null + }, + { + "localized_name": "preview", + "name": "preview", + "shape": 7, + "type": "RESOLUTION_PREVIEW", + "widget": { + "name": "preview" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "宽度", + "name": "width", + "type": "INT", + "links": [ + 3 + ] + }, + { + "localized_name": "高度", + "name": "height", + "type": "INT", + "links": [ + 4 + ] + } + ], + "properties": { + "Node name for S&R": "ResolutionSelector", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "3:4 (Portrait Standard)", + 1.5, + 8 + ], + "widgets_values_named": { + "aspect_ratio": "3:4 (Portrait Standard)", + "megapixels": 1.5, + "multiple": 8 + } + }, + { + "id": "459:451", + "type": "UNETLoader", + "pos": [ + -190, + 410 + ], + "size": [ + 510, + 90 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "localized_name": "UNet名称", + "name": "unet_name", + "type": "COMBO", + "widget": { + "name": "unet_name" + }, + "link": null + }, + { + "localized_name": "数据类型", + "name": "weight_dtype", + "type": "COMBO", + "widget": { + "name": "weight_dtype" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "模型", + "name": "MODEL", + "type": "MODEL", + "links": [ + 17 + ] + } + ], + "properties": { + "Node name for S&R": "UNETLoader", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "models": [ + { + "name": "qwen_image_2.1_int8_convrot.safetensors", + "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/diffusion_models/qwen_image_2.1_int8_convrot.safetensors", + "directory": "diffusion_models" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "qwen_image_2.1_int8_convrot.safetensors", + "default" + ], + "widgets_values_named": { + "unet_name": "qwen_image_2.1_int8_convrot.safetensors", + "weight_dtype": "default" + } + }, + { + "id": "459:452", + "type": "TextEncodeQwenImage21", + "pos": [ + 440, + 410 + ], + "size": [ + 530, + 680 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [ + { + "localized_name": "clip", + "name": "clip", + "type": "CLIP", + "link": 1 + }, + { + "localized_name": "image_1", + "name": "images.image_1", + "shape": 7, + "type": "IMAGE", + "link": null + }, + { + "localized_name": "vae", + "name": "vae", + "shape": 7, + "type": "VAE", + "link": null + }, + { + "localized_name": "prompt", + "name": "prompt", + "type": "STRING", + "widget": { + "name": "prompt" + }, + "link": 2 + }, + { + "localized_name": "negative_prompt", + "name": "negative_prompt", + "type": "STRING", + "widget": { + "name": "negative_prompt" + }, + "link": null + }, + { + "localized_name": "resolution", + "name": "resolution", + "type": "INT", + "widget": { + "name": "resolution" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "positive", + "name": "positive", + "type": "CONDITIONING", + "links": [ + 8 + ] + }, + { + "localized_name": "negative", + "name": "negative", + "type": "CONDITIONING", + "links": [ + 9 + ] + }, + { + "localized_name": "latent", + "name": "latent", + "type": "LATENT", + "links": [] + } + ], + "properties": { + "Node name for S&R": "TextEncodeQwenImage21", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "", + "", + 1024 + ], + "widgets_values_named": { + "prompt": "", + "negative_prompt": "", + "resolution": 1024 + } + }, + { + "id": "459:453", + "type": "CLIPLoader", + "pos": [ + -190, + 570 + ], + "size": [ + 510, + 120 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "localized_name": "CLIP名称", + "name": "clip_name", + "type": "COMBO", + "widget": { + "name": "clip_name" + }, + "link": null + }, + { + "localized_name": "类型", + "name": "type", + "type": "COMBO", + "widget": { + "name": "type" + }, + "link": null + }, + { + "localized_name": "设备", + "name": "device", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "device" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "CLIP", + "name": "CLIP", + "type": "CLIP", + "links": [ + 1 + ] + } + ], + "properties": { + "Node name for S&R": "CLIPLoader", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "models": [ + { + "name": "qwen3vl_8b_int8_convrot.safetensors", + "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3vl_8b_int8_convrot.safetensors", + "directory": "text_encoders" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "qwen3vl_8b_int8_convrot.safetensors", + "qwen_image", + "default" + ], + "widgets_values_named": { + "clip_name": "qwen3vl_8b_int8_convrot.safetensors", + "type": "qwen_image", + "device": "default" + } + }, + { + "id": "459:454", + "type": "VAELoader", + "pos": [ + -190, + 770 + ], + "size": [ + 510, + 70 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "localized_name": "vae名称", + "name": "vae_name", + "type": "COMBO", + "widget": { + "name": "vae_name" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "VAE", + "name": "VAE", + "type": "VAE", + "links": [ + 6 + ] + } + ], + "properties": { + "Node name for S&R": "VAELoader", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "models": [ + { + "name": "qwen_image_2.1_vae_bf16.safetensors", + "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/vae/qwen_image_2.1_vae_bf16.safetensors", + "directory": "vae" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "qwen_image_2.1_vae_bf16.safetensors" + ], + "widgets_values_named": { + "vae_name": "qwen_image_2.1_vae_bf16.safetensors" + } + }, + { + "id": "459:456", + "type": "EmptyLatentImage", + "pos": [ + -70, + 1010 + ], + "size": [ + 300, + 120 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "localized_name": "宽度", + "name": "width", + "type": "INT", + "widget": { + "name": "width" + }, + "link": 3 + }, + { + "localized_name": "高度", + "name": "height", + "type": "INT", + "widget": { + "name": "height" + }, + "link": 4 + }, + { + "localized_name": "批量大小", + "name": "batch_size", + "type": "INT", + "widget": { + "name": "batch_size" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "Latent", + "name": "LATENT", + "type": "LATENT", + "links": [ + 10 + ] + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 1024, + 1024, + 1 + ], + "widgets_values_named": { + "width": 1024, + "height": 1024, + "batch_size": 1 + } + }, + { + "id": "459:457", + "type": "VAEDecode", + "pos": [ + 1620, + 660 + ], + "size": [ + 230, + 60 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "localized_name": "Latent", + "name": "samples", + "type": "LATENT", + "link": 5 + }, + { + "localized_name": "vae", + "name": "vae", + "type": "VAE", + "link": 6 + } + ], + "outputs": [ + { + "localized_name": "图像", + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 18 + ] + } + ], + "properties": { + "Node name for S&R": "VAEDecode", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + } + }, + { + "id": "459:458", + "type": "KSampler", + "pos": [ + 1180, + 640 + ], + "size": [ + 270, + 480 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "localized_name": "模型", + "name": "model", + "type": "MODEL", + "link": 7 + }, + { + "localized_name": "正面条件", + "name": "positive", + "type": "CONDITIONING", + "link": 8 + }, + { + "localized_name": "负面条件", + "name": "negative", + "type": "CONDITIONING", + "link": 9 + }, + { + "localized_name": "Latent图像", + "name": "latent_image", + "type": "LATENT", + "link": 10 + }, + { + "localized_name": "种子", + "name": "seed", + "type": "INT", + "widget": { + "name": "seed" + }, + "link": null + }, + { + "localized_name": "步数", + "name": "steps", + "type": "INT", + "widget": { + "name": "steps" + }, + "link": null + }, + { + "localized_name": "cfg", + "name": "cfg", + "type": "FLOAT", + "widget": { + "name": "cfg" + }, + "link": null + }, + { + "localized_name": "采样器名称", + "name": "sampler_name", + "type": "COMBO", + "widget": { + "name": "sampler_name" + }, + "link": null + }, + { + "localized_name": "调度器", + "name": "scheduler", + "type": "COMBO", + "widget": { + "name": "scheduler" + }, + "link": null + }, + { + "localized_name": "降噪", + "name": "denoise", + "type": "FLOAT", + "widget": { + "name": "denoise" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "Latent", + "name": "LATENT", + "type": "LATENT", + "links": [ + 5 + ] + } + ], + "properties": { + "Node name for S&R": "KSampler", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + 0, + "fixed", + 25, + 1, + "euler", + "simple", + 1 + ], + "widgets_values_named": { + "seed": 0, + "control_after_generate": "fixed", + "steps": 25, + "cfg": 1, + "sampler_name": "euler", + "scheduler": "simple", + "denoise": 1 + } + }, + { + "id": "459:471", + "type": "TextGenerate", + "pos": [ + 470, + -420 + ], + "size": [ + 400, + 460 + ], + "flags": {}, + "order": 8, + "mode": 0, + "showAdvanced": true, + "inputs": [ + { + "localized_name": "clip", + "name": "clip", + "type": "CLIP", + "link": 11 + }, + { + "localized_name": "图像", + "name": "image", + "shape": 7, + "type": "IMAGE", + "link": null + }, + { + "localized_name": "视频", + "name": "video", + "shape": 7, + "type": "IMAGE", + "link": null + }, + { + "localized_name": "音频", + "name": "audio", + "shape": 7, + "type": "AUDIO", + "link": null + }, + { + "localized_name": "system_prompt", + "name": "system_prompt", + "shape": 7, + "type": "STRING", + "link": 12 + }, + { + "localized_name": "提示词", + "name": "prompt", + "type": "STRING", + "widget": { + "name": "prompt" + }, + "link": 13 + }, + { + "localized_name": "最大长度", + "name": "max_length", + "type": "INT", + "widget": { + "name": "max_length" + }, + "link": null + }, + { + "localized_name": "采样模式", + "name": "sampling_mode", + "type": "COMFY_DYNAMICCOMBO_V3", + "widget": { + "name": "sampling_mode" + }, + "link": null + }, + { + "localized_name": "温度", + "name": "sampling_mode.temperature", + "type": "FLOAT", + "widget": { + "name": "sampling_mode.temperature" + }, + "link": null + }, + { + "localized_name": "Top K", + "name": "sampling_mode.top_k", + "type": "INT", + "widget": { + "name": "sampling_mode.top_k" + }, + "link": null + }, + { + "localized_name": "Top P", + "name": "sampling_mode.top_p", + "type": "FLOAT", + "widget": { + "name": "sampling_mode.top_p" + }, + "link": null + }, + { + "localized_name": "最小概率", + "name": "sampling_mode.min_p", + "type": "FLOAT", + "widget": { + "name": "sampling_mode.min_p" + }, + "link": null + }, + { + "localized_name": "重复惩罚", + "name": "sampling_mode.repetition_penalty", + "type": "FLOAT", + "widget": { + "name": "sampling_mode.repetition_penalty" + }, + "link": null + }, + { + "localized_name": "种子", + "name": "sampling_mode.seed", + "type": "INT", + "widget": { + "name": "sampling_mode.seed" + }, + "link": null + }, + { + "localized_name": "presence_penalty", + "name": "sampling_mode.presence_penalty", + "shape": 7, + "type": "FLOAT", + "widget": { + "name": "sampling_mode.presence_penalty" + }, + "link": null + }, + { + "localized_name": "思考模式", + "name": "thinking", + "shape": 7, + "type": "BOOLEAN", + "widget": { + "name": "thinking" + }, + "link": null + }, + { + "localized_name": "use_default_template", + "name": "use_default_template", + "shape": 7, + "type": "BOOLEAN", + "widget": { + "name": "use_default_template" + }, + "link": null + }, + { + "localized_name": "mtp", + "name": "mtp", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "mtp" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "生成文本", + "name": "generated_text", + "type": "STRING", + "links": [ + 16 + ] + }, + { + "localized_name": "thinking", + "name": "thinking", + "type": "STRING", + "links": [] + } + ], + "properties": { + "Node name for S&R": "TextGenerate", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "", + 4096, + "on", + 1, + 20, + 0.95, + 0, + 1.05, + 0, + 0, + false, + false, + "auto" + ], + "widgets_values_named": { + "prompt": "", + "max_length": 4096, + "sampling_mode": "on", + "sampling_mode.temperature": 1, + "sampling_mode.top_k": 20, + "sampling_mode.top_p": 0.95, + "sampling_mode.min_p": 0, + "sampling_mode.repetition_penalty": 1.05, + "sampling_mode.seed": 0, + "sampling_mode.presence_penalty": 0, + "thinking": false, + "use_default_template": false, + "mtp": "auto" + } + }, + { + "id": "459:472", + "type": "PreviewAny", + "pos": [ + 990, + -250 + ], + "size": [ + 470, + 430 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "localized_name": "源", + "name": "source", + "type": "*", + "link": 14 + } + ], + "outputs": [ + { + "localized_name": "字符串", + "name": "STRING", + "type": "STRING", + "links": [ + 2 + ] + } + ], + "properties": { + "Node name for S&R": "PreviewAny", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [], + "widgets_values_named": {} + }, + { + "id": "459:473", + "type": "CLIPLoader", + "pos": [ + -180, + -420 + ], + "size": [ + 530, + 120 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "localized_name": "CLIP名称", + "name": "clip_name", + "type": "COMBO", + "widget": { + "name": "clip_name" + }, + "link": null + }, + { + "localized_name": "类型", + "name": "type", + "type": "COMBO", + "widget": { + "name": "type" + }, + "link": null + }, + { + "localized_name": "设备", + "name": "device", + "shape": 7, + "type": "COMBO", + "widget": { + "name": "device" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "CLIP", + "name": "CLIP", + "type": "CLIP", + "links": [ + 11 + ] + } + ], + "properties": { + "Node name for S&R": "CLIPLoader", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "models": [ + { + "name": "qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "url": "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "directory": "text_encoders" + } + ], + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "stable_diffusion", + "default" + ], + "widgets_values_named": { + "clip_name": "qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors", + "type": "stable_diffusion", + "device": "default" + } + }, + { + "id": "459:474", + "type": "ComfySwitchNode", + "pos": [ + 990, + -420 + ], + "size": [ + 270, + 80 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "localized_name": "为假时", + "name": "on_false", + "shape": 7, + "type": "STRING", + "link": 15 + }, + { + "localized_name": "为真时", + "name": "on_true", + "shape": 7, + "type": "STRING", + "link": 16 + }, + { + "localized_name": "切换", + "name": "switch", + "type": "BOOLEAN", + "widget": { + "name": "switch" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "输出", + "name": "output", + "type": "STRING", + "links": [ + 14 + ] + } + ], + "properties": { + "Node name for S&R": "ComfySwitchNode", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + false + ], + "widgets_values_named": { + "switch": false + } + }, + { + "id": "459:475", + "type": "PrimitiveStringMultiline", + "pos": [ + -180, + -180 + ], + "size": [ + 530, + 270 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [ + { + "localized_name": "值", + "name": "value", + "type": "STRING", + "widget": { + "name": "value" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "字符串", + "name": "STRING", + "type": "STRING", + "links": [ + 12 + ] + } + ], + "title": "Text (System Prompt)", + "properties": { + "Node name for S&R": "PrimitiveStringMultiline", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "<|im_start|>system\n# Image Prompt Rewriting Expert\n\nYou turn a user's image request into one long English paragraph that describes the\nfinished image as if you were looking at it, plus the aspect ratio it should be\nrendered at. You are not talking to the user and not talking to a renderer: you are\nan observer reporting what is in the frame.\n\nWork through the eight steps below in order. Each step commits one decision; later\nsteps never revise an earlier one.\n\n## Step 1 — Read the brief and split it in two\n\nList what the user has fixed and what they have left open.\n\nFixed, and it must survive into your description unchanged: every string of text\nthey want shown, every named object, every count, every stated colour, every stated\nposition, and the aspect ratio if they gave one. Copy their text strings character\nfor character, in their own script, including punctuation and spacing.\n\nA third thing they may give you is an instruction about the job rather than about the\npicture — \"use double quotes\", \"no hard-edged blocks\", \"4K, no noise\", \"make sure the\ntext is sharp\". That is not content. Obey it silently where it applies and never echo\nit: the description states what is in the frame, never what must be done.\n\nOpen, and you must decide it: everything they did not mention. A three-word request\nand a three-hundred-word request both become a description of the same size, so a\nshort brief means you are inventing most of the frame, not writing less.\n\n## Step 2 — Fix the frame\n\nDecide the orientation from the subject, then pick the ratio.\n\nIf the user states a ratio, use it. Otherwise: `3:2` for anything horizontal and\n`2:3` for anything vertical — these are the two defaults and cover most images.\nUse `1:1` for a square badge, icon, album cover or single centred emblem, `16:9`\nfor a wide cinematic or presentation frame, `1:2` or `9:16` for a phone screen or a\ntall standing banner. `3:4`, `2:1`, `21:9`, `4:3`, `9:21`, `4:5`, `3:1`, `5:4`,\n`1:3` exist but only when the subject or the user really calls for them.\n\nThe ratio lives only in the `wh_ratio` field. Never write a ratio, a resolution, or\na pixel count into the description itself.\n\n## Step 3 — Write the opening sentence\n\nOne sentence, around twenty words. Name the medium, the style, the subject, and the\nbackground or palette; usually name the orientation too:\n\n`The image is a ⟨vertical / wide / square / tall⟩ ⟨style⟩ ⟨photograph · poster · illustration · scene · portrait · infographic · close-up · graphic · page · card · sheet · logo⟩ of ⟨subject⟩, ⟨the background and its palette⟩.`\n\n`This is a …` or a bare `A vertical realistic photograph of …` work equally well. The\nmedium noun is the one part that is never omitted.\n\nThe style word goes here — realistic, photorealistic, minimalist, flat-vector,\ncinematic, watercolour, isometric, editorial, hand-drawn, 3D-rendered, retro. Name\nit once here; you may echo it in the closing sentence.\n\n## Step 4 — Inventory before you write\n\nBefore any more prose, settle two lists.\n\nEvery element that will appear, each with a place in the frame: upper-left,\nacross the top, on the far right, in the lower-third, in the centre, in front of,\nbehind, tucked into the corner. You will need eight to fourteen such positional\nphrases, about ten typically, and they must reach the corners, the edges and the\ncentre — not cluster in the middle.\n\nEvery piece of text that will be legible in the image, in reading order.\n\n## Step 5 — Walk the frame\n\nNow describe it in order. Which order depends on how the frame is filled.\n\n**If the frame is divided into regions** — a poster, a page, an interface, a layout, a\nwide scene with several things in it — walk the regions:\n\n1. The background and the surface it sits on — this comes immediately after the\n opening sentence, not at the end.\n2. The top band: headline, header bar, sky, ceiling, whatever occupies the top edge.\n3. Down and across the body of the frame: left side, then centre, then right side.\n Give each region one or two sentences.\n4. The bottom band: footer, foreground, ground plane, base row.\n\n**If one subject fills the frame** — a portrait, a close-up, a single object — walk\nthe subject instead: the background and how far it falls off, then the subject's pose\nand where it is placed in the frame, then head and face, then body and each garment or\nsurface, then what is held or touching it, then whatever little is left at the edges.\nKeep using positional phrases inside the subject — in the upper-left of the frame,\nbehind the left shoulder, along the lower edge — so the frame stays locatable.\n\nRoughly a third of your sentences should open on the positional phrase itself —\n\"On the right side of the frame, …\", \"In the upper-left corner, …\", \"Across the\nlower third, …\" — so the reader always knows where they are looking.\n\nKeep it to one paragraph. Break to a new paragraph only when the image is genuinely\nbuilt from stacked regions — panels, cards, sections, slides — and then one\nparagraph per region, each opening on where that region sits.\n\n## Step 6 — Set every piece of text\n\nSkip this step if nothing in the image is meant to be read — a third of images have\nno legible text at all, and inventing signage for them is a mistake.\n\nOtherwise, for each string from your Step 4 list, in reading order, name where it sits,\nwhat it looks like, and what it says: `a bold black headline across the top reads \"…\"`.\n\nPut the string in straight double quotes, in its own script — Chinese, Russian,\nKorean, Japanese and Arabic text stays in Chinese, Russian, Korean, Japanese and\nArabic. Give its weight, colour, case and relative size. Describe a line break as a\nsecond line rather than putting a real newline inside the string. If a mark is not meant\nto be read — distant signage, a label behind glass, dense body copy — call it\nblurred, indistinct, or too small to read rather than inventing letters. If the image contains a chart\nor a table, its axes, tick labels, legend entries, series and cell values are text\ntoo: write them out.\n\n## Step 7 — Give the lighting its own sentence\n\nEvery image has light in it, and the description always accounts for it: the source,\nits direction, its quality, and the shadows and highlights it leaves. Soft diffused\ndaylight from a window on the left, hard overhead studio light, warm low sun, flat\neven ambient light for a diagram.\n\nOnce the contents are placed, give it a sentence of its own — `The lighting is …` —\nor, if the light is what makes a particular surface look the way it does, fold it into\nthat surface's sentence. Either way it is stated explicitly, not left implied.\n\n## Step 8 — Close with the whole frame\n\nEnd on a single sentence that steps back:\n\n`The overall composition ⟨is / uses / feels⟩ …`\n\n`The composition is …`, `The overall design …`, `The overall mood …`, `The overall\npalette …` and `The image has …` are the same move. Cover balance and symmetry, the\npalette, the style, and the mood in that one sentence. Write exactly one such\nsentence — do not follow it with a second summary.\n\n## Throughout\n\n**Size.** The description runs about twenty sentences and four to five hundred words,\nroughly twenty-five words a sentence. That is the same size whether the brief was three\nwords or three hundred: a dense frame with many regions and a lot of text runs longer, a\nsingle quiet subject runs shorter, but a thin brief never buys a thin description.\n\n**Observe, don't instruct.** Present tense, third person, declarative. No \"you\", no\n\"create\", no \"make sure\", no \"the AI should\". No quality boosters — no \"masterpiece\",\n\"8K\", \"highly detailed\", \"award-winning\".\n\n**Hedge what you cannot be certain of.** An observer describing a picture says\n\"appears to be\", \"likely\", \"suggesting\", and offers a pair — \"a notebook\nor a tablet\", \"wood or dark laminate\" — when the thing is genuinely ambiguous. Do\nthis often; it is the natural register here. Be flatly definite only about what the\nuser fixed.\n\n**Name colours with a modifier, almost never bare.** Deep navy, muted olive, pale\ncream, warm terracotta, soft dusty rose, blue-grey, off-white, charcoal, brownish-\ngreen. Hex codes only if the user gave them.\n\n**Give the material, not just the noun.** Brushed metal, matte plastic, glossy\nceramic, coarse linen, weathered wood, frosted glass, grain, scuffs, condensation,\nvisible brush strokes, paper fibre.\n\n**Enumerate; never summarise.** \"Several items\" and \"various decorations\" are not\ndescriptions. Say what each thing is. Write small counts as words — three, five,\ntwelve — and if something is partly hidden, say so and describe the visible part.\n\n**People get their observable surface.** Build, posture, where they are looking,\nexpression, hair, skin tone, and each garment with its colour and material. Age is a\nlife stage or a decade — a child, a teenager, a young adult, middle-aged, elderly,\nin her thirties — never a number of years. If a face is turned away or cropped, say\nthat instead of describing it.\n\n**Objects by class, not by brand.** A silver laptop, a mirrorless camera, a compact\nhatchback — unless the user named the brand. Photographic and design vocabulary is\nwelcome: shallow depth of field, bokeh, backlit, close-up, negative space,\ngrid, drop shadow.\n\n**Everything holds together physically.** Shadows fall away from the light, reflections\nmatch what is in front of the surface, scale is consistent between neighbouring\nobjects, and a surface reacts to what sits on it. If the user asked for something\nimpossible, describe it as the image shows it and let the rest of the scene stay\ncoherent around it.\n\n## Language\n\nThe description is always in English, whatever language the request arrives in. The\nonly exception is text shown inside the image, which stays in its own script.\n\n## Output format\n\n- Return the description and nothing else: one continuous paragraph of English, in a single line\nstarting on the very first character of your reply.\n- No JSON, no braces, no key names, no labels, no headings, no markdown, no code fences, and no quotation marks around the paragraph.\n- No preamble, no acknowledgement, no explanation, no summary, no notes, no closing remarks, no questions.\n- No ratio, no resolution, no pixel count, no timestamps.\n\nYour whole reply is used as the image prompt, so every extra word you add becomes part of the image.\n<|im_end|>" + ], + "widgets_values_named": { + "value": "<|im_start|>system\n# Image Prompt Rewriting Expert\n\nYou turn a user's image request into one long English paragraph that describes the\nfinished image as if you were looking at it, plus the aspect ratio it should be\nrendered at. You are not talking to the user and not talking to a renderer: you are\nan observer reporting what is in the frame.\n\nWork through the eight steps below in order. Each step commits one decision; later\nsteps never revise an earlier one.\n\n## Step 1 — Read the brief and split it in two\n\nList what the user has fixed and what they have left open.\n\nFixed, and it must survive into your description unchanged: every string of text\nthey want shown, every named object, every count, every stated colour, every stated\nposition, and the aspect ratio if they gave one. Copy their text strings character\nfor character, in their own script, including punctuation and spacing.\n\nA third thing they may give you is an instruction about the job rather than about the\npicture — \"use double quotes\", \"no hard-edged blocks\", \"4K, no noise\", \"make sure the\ntext is sharp\". That is not content. Obey it silently where it applies and never echo\nit: the description states what is in the frame, never what must be done.\n\nOpen, and you must decide it: everything they did not mention. A three-word request\nand a three-hundred-word request both become a description of the same size, so a\nshort brief means you are inventing most of the frame, not writing less.\n\n## Step 2 — Fix the frame\n\nDecide the orientation from the subject, then pick the ratio.\n\nIf the user states a ratio, use it. Otherwise: `3:2` for anything horizontal and\n`2:3` for anything vertical — these are the two defaults and cover most images.\nUse `1:1` for a square badge, icon, album cover or single centred emblem, `16:9`\nfor a wide cinematic or presentation frame, `1:2` or `9:16` for a phone screen or a\ntall standing banner. `3:4`, `2:1`, `21:9`, `4:3`, `9:21`, `4:5`, `3:1`, `5:4`,\n`1:3` exist but only when the subject or the user really calls for them.\n\nThe ratio lives only in the `wh_ratio` field. Never write a ratio, a resolution, or\na pixel count into the description itself.\n\n## Step 3 — Write the opening sentence\n\nOne sentence, around twenty words. Name the medium, the style, the subject, and the\nbackground or palette; usually name the orientation too:\n\n`The image is a ⟨vertical / wide / square / tall⟩ ⟨style⟩ ⟨photograph · poster · illustration · scene · portrait · infographic · close-up · graphic · page · card · sheet · logo⟩ of ⟨subject⟩, ⟨the background and its palette⟩.`\n\n`This is a …` or a bare `A vertical realistic photograph of …` work equally well. The\nmedium noun is the one part that is never omitted.\n\nThe style word goes here — realistic, photorealistic, minimalist, flat-vector,\ncinematic, watercolour, isometric, editorial, hand-drawn, 3D-rendered, retro. Name\nit once here; you may echo it in the closing sentence.\n\n## Step 4 — Inventory before you write\n\nBefore any more prose, settle two lists.\n\nEvery element that will appear, each with a place in the frame: upper-left,\nacross the top, on the far right, in the lower-third, in the centre, in front of,\nbehind, tucked into the corner. You will need eight to fourteen such positional\nphrases, about ten typically, and they must reach the corners, the edges and the\ncentre — not cluster in the middle.\n\nEvery piece of text that will be legible in the image, in reading order.\n\n## Step 5 — Walk the frame\n\nNow describe it in order. Which order depends on how the frame is filled.\n\n**If the frame is divided into regions** — a poster, a page, an interface, a layout, a\nwide scene with several things in it — walk the regions:\n\n1. The background and the surface it sits on — this comes immediately after the\n opening sentence, not at the end.\n2. The top band: headline, header bar, sky, ceiling, whatever occupies the top edge.\n3. Down and across the body of the frame: left side, then centre, then right side.\n Give each region one or two sentences.\n4. The bottom band: footer, foreground, ground plane, base row.\n\n**If one subject fills the frame** — a portrait, a close-up, a single object — walk\nthe subject instead: the background and how far it falls off, then the subject's pose\nand where it is placed in the frame, then head and face, then body and each garment or\nsurface, then what is held or touching it, then whatever little is left at the edges.\nKeep using positional phrases inside the subject — in the upper-left of the frame,\nbehind the left shoulder, along the lower edge — so the frame stays locatable.\n\nRoughly a third of your sentences should open on the positional phrase itself —\n\"On the right side of the frame, …\", \"In the upper-left corner, …\", \"Across the\nlower third, …\" — so the reader always knows where they are looking.\n\nKeep it to one paragraph. Break to a new paragraph only when the image is genuinely\nbuilt from stacked regions — panels, cards, sections, slides — and then one\nparagraph per region, each opening on where that region sits.\n\n## Step 6 — Set every piece of text\n\nSkip this step if nothing in the image is meant to be read — a third of images have\nno legible text at all, and inventing signage for them is a mistake.\n\nOtherwise, for each string from your Step 4 list, in reading order, name where it sits,\nwhat it looks like, and what it says: `a bold black headline across the top reads \"…\"`.\n\nPut the string in straight double quotes, in its own script — Chinese, Russian,\nKorean, Japanese and Arabic text stays in Chinese, Russian, Korean, Japanese and\nArabic. Give its weight, colour, case and relative size. Describe a line break as a\nsecond line rather than putting a real newline inside the string. If a mark is not meant\nto be read — distant signage, a label behind glass, dense body copy — call it\nblurred, indistinct, or too small to read rather than inventing letters. If the image contains a chart\nor a table, its axes, tick labels, legend entries, series and cell values are text\ntoo: write them out.\n\n## Step 7 — Give the lighting its own sentence\n\nEvery image has light in it, and the description always accounts for it: the source,\nits direction, its quality, and the shadows and highlights it leaves. Soft diffused\ndaylight from a window on the left, hard overhead studio light, warm low sun, flat\neven ambient light for a diagram.\n\nOnce the contents are placed, give it a sentence of its own — `The lighting is …` —\nor, if the light is what makes a particular surface look the way it does, fold it into\nthat surface's sentence. Either way it is stated explicitly, not left implied.\n\n## Step 8 — Close with the whole frame\n\nEnd on a single sentence that steps back:\n\n`The overall composition ⟨is / uses / feels⟩ …`\n\n`The composition is …`, `The overall design …`, `The overall mood …`, `The overall\npalette …` and `The image has …` are the same move. Cover balance and symmetry, the\npalette, the style, and the mood in that one sentence. Write exactly one such\nsentence — do not follow it with a second summary.\n\n## Throughout\n\n**Size.** The description runs about twenty sentences and four to five hundred words,\nroughly twenty-five words a sentence. That is the same size whether the brief was three\nwords or three hundred: a dense frame with many regions and a lot of text runs longer, a\nsingle quiet subject runs shorter, but a thin brief never buys a thin description.\n\n**Observe, don't instruct.** Present tense, third person, declarative. No \"you\", no\n\"create\", no \"make sure\", no \"the AI should\". No quality boosters — no \"masterpiece\",\n\"8K\", \"highly detailed\", \"award-winning\".\n\n**Hedge what you cannot be certain of.** An observer describing a picture says\n\"appears to be\", \"likely\", \"suggesting\", and offers a pair — \"a notebook\nor a tablet\", \"wood or dark laminate\" — when the thing is genuinely ambiguous. Do\nthis often; it is the natural register here. Be flatly definite only about what the\nuser fixed.\n\n**Name colours with a modifier, almost never bare.** Deep navy, muted olive, pale\ncream, warm terracotta, soft dusty rose, blue-grey, off-white, charcoal, brownish-\ngreen. Hex codes only if the user gave them.\n\n**Give the material, not just the noun.** Brushed metal, matte plastic, glossy\nceramic, coarse linen, weathered wood, frosted glass, grain, scuffs, condensation,\nvisible brush strokes, paper fibre.\n\n**Enumerate; never summarise.** \"Several items\" and \"various decorations\" are not\ndescriptions. Say what each thing is. Write small counts as words — three, five,\ntwelve — and if something is partly hidden, say so and describe the visible part.\n\n**People get their observable surface.** Build, posture, where they are looking,\nexpression, hair, skin tone, and each garment with its colour and material. Age is a\nlife stage or a decade — a child, a teenager, a young adult, middle-aged, elderly,\nin her thirties — never a number of years. If a face is turned away or cropped, say\nthat instead of describing it.\n\n**Objects by class, not by brand.** A silver laptop, a mirrorless camera, a compact\nhatchback — unless the user named the brand. Photographic and design vocabulary is\nwelcome: shallow depth of field, bokeh, backlit, close-up, negative space,\ngrid, drop shadow.\n\n**Everything holds together physically.** Shadows fall away from the light, reflections\nmatch what is in front of the surface, scale is consistent between neighbouring\nobjects, and a surface reacts to what sits on it. If the user asked for something\nimpossible, describe it as the image shows it and let the rest of the scene stay\ncoherent around it.\n\n## Language\n\nThe description is always in English, whatever language the request arrives in. The\nonly exception is text shown inside the image, which stays in its own script.\n\n## Output format\n\n- Return the description and nothing else: one continuous paragraph of English, in a single line\nstarting on the very first character of your reply.\n- No JSON, no braces, no key names, no labels, no headings, no markdown, no code fences, and no quotation marks around the paragraph.\n- No preamble, no acknowledgement, no explanation, no summary, no notes, no closing remarks, no questions.\n- No ratio, no resolution, no pixel count, no timestamps.\n\nYour whole reply is used as the image prompt, so every extra word you add becomes part of the image.\n<|im_end|>" + } + }, + { + "id": "459:480", + "type": "QwenImage21Cache", + "pos": [ + 1190, + 460 + ], + "size": [ + 270, + 90 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "localized_name": "model", + "name": "model", + "type": "MODEL", + "link": 17 + }, + { + "localized_name": "device", + "name": "device", + "type": "COMBO", + "widget": { + "name": "device" + }, + "link": null + }, + { + "localized_name": "dtype", + "name": "dtype", + "type": "COMBO", + "widget": { + "name": "dtype" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "模型", + "name": "MODEL", + "type": "MODEL", + "links": [ + 7 + ] + } + ], + "properties": { + "Node name for S&R": "QwenImage21Cache", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "auto", + "default" + ], + "widgets_values_named": { + "device": "auto", + "dtype": "default" + } + }, + { + "id": "461", + "type": "SaveImageAdvanced", + "pos": [ + 1400, + 2460 + ], + "size": [ + 850, + 610 + ], + "flags": { + "pinned": true + }, + "order": 5, + "mode": 0, + "inputs": [ + { + "localized_name": "图像", + "name": "images", + "type": "IMAGE", + "link": 18 + }, + { + "localized_name": "文件名前缀", + "name": "filename_prefix", + "type": "STRING", + "widget": { + "name": "filename_prefix" + }, + "link": null + }, + { + "localized_name": "格式", + "name": "format", + "type": "COMFY_DYNAMICCOMBO_V3", + "widget": { + "name": "format" + }, + "link": null + }, + { + "localized_name": "位深度", + "name": "format.bit_depth", + "type": "COMBO", + "widget": { + "name": "format.bit_depth" + }, + "link": null + }, + { + "localized_name": "输入色彩空间", + "name": "format.input_color_space", + "type": "COMBO", + "widget": { + "name": "format.input_color_space" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "images", + "name": "images", + "type": "IMAGE", + "links": [] + } + ], + "properties": { + "Node name for S&R": "SaveImageAdvanced", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "image/Qwen_image_2.1", + "png", + "8-bit", + "sRGB" + ], + "widgets_values_named": { + "filename_prefix": "image/Qwen_image_2.1", + "format": "png", + "format.bit_depth": "8-bit", + "format.input_color_space": "sRGB" + } + }, + { + "id": "463", + "type": "MarkdownNote", + "pos": [ + -350, + 2470 + ], + "size": [ + 420, + 620 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [], + "title": "Note: Model links", + "properties": { + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "Guide: [Subgraph](https://docs.comfy.org/interface/features/subgraph)\n\n## Model Links\n\n- [Hugging Face:Comfy-Org/Qwen-Image-2.1](https://huggingface.co/Comfy-Org/Qwen-Image-2.1)\n- [ModelScope:Comfy-Org/Qwen-Image-2.1](https://modelscope.cn/models/Comfy-Org/Qwen-Image-2.1)\n\n**diffusion_models**\n\n- [qwen_image_2.1_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/diffusion_models/qwen_image_2.1_int8_convrot.safetensors)\n\n**text_encoders**\n\n- [qwen3vl_8b_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3vl_8b_int8_convrot.safetensors)\n- [qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors)\n\n**vae**\n\n- [qwen_image_2.1_vae_bf16.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/vae/qwen_image_2.1_vae_bf16.safetensors)\n\n\n## Model Storage Location\n\n```\n📂 ComfyUI/\n├── 📂 models/\n│ ├── 📂 diffusion_models/\n│ │ └── qwen_image_2.1_int8_convrot.safetensors\n│ ├── 📂 text_encoders/\n│ │ ├── qwen3vl_8b_int8_convrot.safetensors\n│ │ └── qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors\n│ └── 📂 vae/\n│ └── qwen_image_2.1_vae_bf16.safetensors\n```\n\n## Report Issue\n\nNote: Please update ComfyUI first ([guide](https://docs.comfy.org/installation/update_comfyui)) and prepare required models. Desktop/Cloud updates follow stable releases, so some nightly-supported models may not be available yet.\n\n- Cannot run / runtime errors: [ComfyUI/issues](https://github.com/comfyanonymous/ComfyUI/issues)\n- UI / frontend issues: [ComfyUI_frontend/issues](https://github.com/Comfy-Org/ComfyUI_frontend/issues)\n- Workflow issues: [workflow_templates/issues](https://github.com/Comfy-Org/workflow_templates/issues)\n" + ], + "widgets_values_named": { + "text": "Guide: [Subgraph](https://docs.comfy.org/interface/features/subgraph)\n\n## Model Links\n\n- [Hugging Face:Comfy-Org/Qwen-Image-2.1](https://huggingface.co/Comfy-Org/Qwen-Image-2.1)\n- [ModelScope:Comfy-Org/Qwen-Image-2.1](https://modelscope.cn/models/Comfy-Org/Qwen-Image-2.1)\n\n**diffusion_models**\n\n- [qwen_image_2.1_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/diffusion_models/qwen_image_2.1_int8_convrot.safetensors)\n\n**text_encoders**\n\n- [qwen3vl_8b_int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3vl_8b_int8_convrot.safetensors)\n- [qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/text_encoders/qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors)\n\n**vae**\n\n- [qwen_image_2.1_vae_bf16.safetensors](https://huggingface.co/Comfy-Org/Qwen-Image-2.1/resolve/main/vae/qwen_image_2.1_vae_bf16.safetensors)\n\n\n## Model Storage Location\n\n```\n📂 ComfyUI/\n├── 📂 models/\n│ ├── 📂 diffusion_models/\n│ │ └── qwen_image_2.1_int8_convrot.safetensors\n│ ├── 📂 text_encoders/\n│ │ ├── qwen3vl_8b_int8_convrot.safetensors\n│ │ └── qwen3.5_9b_qwen_image_2.1_pe_t2i.int8_convrot.safetensors\n│ └── 📂 vae/\n│ └── qwen_image_2.1_vae_bf16.safetensors\n```\n\n## Report Issue\n\nNote: Please update ComfyUI first ([guide](https://docs.comfy.org/installation/update_comfyui)) and prepare required models. Desktop/Cloud updates follow stable releases, so some nightly-supported models may not be available yet.\n\n- Cannot run / runtime errors: [ComfyUI/issues](https://github.com/comfyanonymous/ComfyUI/issues)\n- UI / frontend issues: [ComfyUI_frontend/issues](https://github.com/Comfy-Org/ComfyUI_frontend/issues)\n- Workflow issues: [workflow_templates/issues](https://github.com/Comfy-Org/workflow_templates/issues)\n" + }, + "color": "#222", + "bgcolor": "#000" + }, + { + "id": "468", + "type": "MarkdownNote", + "pos": [ + 100, + 2470 + ], + "size": [ + 350, + 240 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [], + "title": "Note: Usage", + "properties": { + "ue_properties": { + "widget_ue_connectable": {}, + "version": "7.8", + "input_ue_unconnectable": {} + } + }, + "widgets_values": [ + "## Size\nQwen Image 2.1 has native 2K (2048*2048) support for direct output.\n\nOutput size comes from ResolutionSelector (width/height). Default is 1 megapixel (1024*1024). For native 2K, set 1:1 and 4 megapixels (2048*2048). Prefer multiples of 32.\n\n## Transparent Image\n\nTo generate a transparent image, wrap the prompt like this and replace the middle with the subject:\n\n---\nThis is an RGBA format image with transparency. `[your description]`. The image has an alpha channel and a transparent background.\n\n---\nSave as PNG to keep the alpha channel.\n\n## Parameters\n\n- prompt: what to generate. For RGBA, see Note: transparent.\n- negative_prompt: unused while cfg is 1.\n- cfg: keep 1 for the Qwen Image 2.1 official path. Raise it only if you use a negative prompt.\n- steps: Qwen Image 2.1 official pipeline uses about 40-50 with euler. This template starts at 25. More advanced samplers need fewer steps.\n" + ], + "widgets_values_named": { + "text": "## Size\nQwen Image 2.1 has native 2K (2048*2048) support for direct output.\n\nOutput size comes from ResolutionSelector (width/height). Default is 1 megapixel (1024*1024). For native 2K, set 1:1 and 4 megapixels (2048*2048). Prefer multiples of 32.\n\n## Transparent Image\n\nTo generate a transparent image, wrap the prompt like this and replace the middle with the subject:\n\n---\nThis is an RGBA format image with transparency. `[your description]`. The image has an alpha channel and a transparent background.\n\n---\nSave as PNG to keep the alpha channel.\n\n## Parameters\n\n- prompt: what to generate. For RGBA, see Note: transparent.\n- negative_prompt: unused while cfg is 1.\n- cfg: keep 1 for the Qwen Image 2.1 official path. Raise it only if you use a negative prompt.\n- steps: Qwen Image 2.1 official pipeline uses about 40-50 with euler. This template starts at 25. More advanced samplers need fewer steps.\n" + }, + "color": "#222", + "bgcolor": "#000" + }, + { + "id": "483", + "type": "PrimitiveStringMultiline", + "pos": [ + 490, + 2480 + ], + "size": [ + 370, + 280 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "localized_name": "值", + "name": "value", + "type": "STRING", + "widget": { + "name": "value" + }, + "link": null + } + ], + "outputs": [ + { + "localized_name": "字符串", + "name": "STRING", + "type": "STRING", + "links": [ + 13, + 15 + ] + } + ], + "properties": { + "Node name for S&R": "PrimitiveStringMultiline", + "cnr_id": "comfy-core", + "ver": "0.38.0", + "ue_properties": { + "widget_ue_connectable": {}, + "input_ue_unconnectable": {}, + "version": "7.8" + } + }, + "widgets_values": [ + "角色设定卡,国风清雅,宣纸米白背景,淡青灰晕染。左侧为22岁中国女性面部特写,温婉沉静,鹅蛋脸,远山黛眉,杏眼深茶褐,淡樱粉唇,乌黑长发半绾青玉簪,鬓角碎发,淡水珍珠耳钉。右侧为人物三视图:正面、侧面、背面,全身站姿,7.5头身,双手交叠身前,身姿端庄。身穿雨过天青真丝提花缎改良旗袍,立领,短袖,收腰,A字裙摆,长至小腿中下部,两侧开衩至膝上,手绘水墨竹纹,竹节深青勾勒,竹叶淡青晕染,竹节形深青盘扣5枚,领口袖口开衩深青细滚边,同色真丝内衬,米白真丝绣花鞋低跟竹叶刺绣。右下角服装细节放大:领口竹节盘扣、水墨竹纹、袖口滚边、开衩暗扣、青玉簪、珍珠耳钉、绣花鞋、提花暗纹。底部色卡:雨过天青、深青、月白、玉色、墨青、珍珠白。画面留出文字框区域:左上标题框、左侧角色信息框、右侧三视图标注框、下方服装说明框、底部设计说明框。柔和自然光,工笔国风,超高细节,角色设计参考图,干净排版。" + ], + "widgets_values_named": { + "value": "角色设定卡,国风清雅,宣纸米白背景,淡青灰晕染。左侧为22岁中国女性面部特写,温婉沉静,鹅蛋脸,远山黛眉,杏眼深茶褐,淡樱粉唇,乌黑长发半绾青玉簪,鬓角碎发,淡水珍珠耳钉。右侧为人物三视图:正面、侧面、背面,全身站姿,7.5头身,双手交叠身前,身姿端庄。身穿雨过天青真丝提花缎改良旗袍,立领,短袖,收腰,A字裙摆,长至小腿中下部,两侧开衩至膝上,手绘水墨竹纹,竹节深青勾勒,竹叶淡青晕染,竹节形深青盘扣5枚,领口袖口开衩深青细滚边,同色真丝内衬,米白真丝绣花鞋低跟竹叶刺绣。右下角服装细节放大:领口竹节盘扣、水墨竹纹、袖口滚边、开衩暗扣、青玉簪、珍珠耳钉、绣花鞋、提花暗纹。底部色卡:雨过天青、深青、月白、玉色、墨青、珍珠白。画面留出文字框区域:左上标题框、左侧角色信息框、右侧三视图标注框、下方服装说明框、底部设计说明框。柔和自然光,工笔国风,超高细节,角色设计参考图,干净排版。" + } + } + ], + "links": [ + [ + 1, + "459:453", + 0, + "459:452", + 0, + "CLIP" + ], + [ + 2, + "459:472", + 0, + "459:452", + 3, + "STRING" + ], + [ + 3, + "13", + 0, + "459:456", + 0, + "INT" + ], + [ + 4, + "13", + 1, + "459:456", + 1, + "INT" + ], + [ + 5, + "459:458", + 0, + "459:457", + 0, + "LATENT" + ], + [ + 6, + "459:454", + 0, + "459:457", + 1, + "VAE" + ], + [ + 7, + "459:480", + 0, + "459:458", + 0, + "MODEL" + ], + [ + 8, + "459:452", + 0, + "459:458", + 1, + "CONDITIONING" + ], + [ + 9, + "459:452", + 1, + "459:458", + 2, + "CONDITIONING" + ], + [ + 10, + "459:456", + 0, + "459:458", + 3, + "LATENT" + ], + [ + 11, + "459:473", + 0, + "459:471", + 0, + "CLIP" + ], + [ + 12, + "459:475", + 0, + "459:471", + 4, + "STRING" + ], + [ + 13, + "483", + 0, + "459:471", + 5, + "STRING" + ], + [ + 14, + "459:474", + 0, + "459:472", + 0, + "STRING" + ], + [ + 15, + "483", + 0, + "459:474", + 0, + "STRING" + ], + [ + 16, + "459:471", + 0, + "459:474", + 1, + "STRING" + ], + [ + 17, + "459:451", + 0, + "459:480", + 0, + "MODEL" + ], + [ + 18, + "459:457", + 0, + "461", + 0, + "IMAGE" + ] + ], + "extra": { + "frontendVersion": "1.53.6", + "VHS_latentpreview": false, + "VHS_latentpreviewrate": 0, + "VHS_MetadataImage": true, + "VHS_KeepIntermediate": true, + "ue_links": [], + "links_added_by_ue": [], + "ds": { + "scale": 1.4255683750168113, + "offset": [ + -400.4819012765797, + -2387.517758813288 + ] + } + } + }, + "unresolved_boundaries": [ + { + "node_id": "459:451", + "input_slot": 0, + "input_name": "unet_name", + "boundary_instance": "459", + "slot": 11, + "name": "unet_name", + "type": "COMBO" + }, + { + "node_id": "459:452", + "input_slot": 4, + "input_name": "negative_prompt", + "boundary_instance": "459", + "slot": 3, + "name": "negative_prompt", + "type": "STRING" + }, + { + "node_id": "459:453", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "459", + "slot": 12, + "name": "clip_name", + "type": "COMBO" + }, + { + "node_id": "459:454", + "input_slot": 0, + "input_name": "vae_name", + "boundary_instance": "459", + "slot": 13, + "name": "vae_name", + "type": "COMBO" + }, + { + "node_id": "459:458", + "input_slot": 4, + "input_name": "seed", + "boundary_instance": "459", + "slot": 10, + "name": "seed", + "type": "INT" + }, + { + "node_id": "459:458", + "input_slot": 5, + "input_name": "steps", + "boundary_instance": "459", + "slot": 5, + "name": "steps", + "type": "INT" + }, + { + "node_id": "459:458", + "input_slot": 6, + "input_name": "cfg", + "boundary_instance": "459", + "slot": 4, + "name": "cfg", + "type": "FLOAT" + }, + { + "node_id": "459:458", + "input_slot": 7, + "input_name": "sampler_name", + "boundary_instance": "459", + "slot": 8, + "name": "scheduler", + "type": "COMBO" + }, + { + "node_id": "459:458", + "input_slot": 8, + "input_name": "scheduler", + "boundary_instance": "459", + "slot": 9, + "name": "scheduler_1", + "type": "COMBO" + }, + { + "node_id": "459:471", + "input_slot": 13, + "input_name": "sampling_mode.seed", + "boundary_instance": "459", + "slot": 10, + "name": "seed", + "type": "INT" + }, + { + "node_id": "459:471", + "input_slot": 15, + "input_name": "thinking", + "boundary_instance": "459", + "slot": 2, + "name": "thinking", + "type": "BOOLEAN" + }, + { + "node_id": "459:473", + "input_slot": 0, + "input_name": "clip_name", + "boundary_instance": "459", + "slot": 14, + "name": "clip_name_1", + "type": "COMBO" + }, + { + "node_id": "459:474", + "input_slot": 2, + "input_name": "switch", + "boundary_instance": "459", + "slot": 1, + "name": "switch", + "type": "BOOLEAN" + }, + { + "node_id": "459:480", + "input_slot": 1, + "input_name": "device", + "boundary_instance": "459", + "slot": 15, + "name": "device", + "type": "COMBO" + }, + { + "node_id": "459:480", + "input_slot": 2, + "input_name": "dtype", + "boundary_instance": "459", + "slot": 16, + "name": "dtype_1", + "type": "COMBO" + } + ], + "node_types": [ + { + "node_id": "13", + "source_type": "ResolutionSelector", + "api_type": "ResolutionSelector", + "differences": [] + }, + { + "node_id": "459:451", + "source_type": "UNETLoader", + "api_type": "UNETLoader", + "differences": [] + }, + { + "node_id": "459:452", + "source_type": "TextEncodeQwenImage21", + "api_type": "TextEncodeQwenImage21", + "differences": [] + }, + { + "node_id": "459:453", + "source_type": "CLIPLoader", + "api_type": "CLIPLoader", + "differences": [] + }, + { + "node_id": "459:454", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "459:456", + "source_type": "EmptyLatentImage", + "api_type": "EmptyLatentImage", + "differences": [] + }, + { + "node_id": "459:457", + "source_type": "VAEDecode", + "api_type": "VAEDecode", + "differences": [] + }, + { + "node_id": "459:458", + "source_type": "KSampler", + "api_type": "KSampler", + "differences": [] + }, + { + "node_id": "459:471", + "source_type": "TextGenerate", + "api_type": "TextGenerate", + "differences": [] + }, + { + "node_id": "459:472", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "459:473", + "source_type": "CLIPLoader", + "api_type": "CLIPLoader", + "differences": [] + }, + { + "node_id": "459:474", + "source_type": "ComfySwitchNode", + "api_type": "ComfySwitchNode", + "differences": [] + }, + { + "node_id": "459:475", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + }, + { + "node_id": "459:480", + "source_type": "QwenImage21Cache", + "api_type": "QwenImage21Cache", + "differences": [] + }, + { + "node_id": "461", + "source_type": "SaveImageAdvanced", + "api_type": "SaveImageAdvanced", + "differences": [] + }, + { + "node_id": "483", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "13", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "分辨率选择器", + "actual": "ResolutionSelector" + } + ] + }, + { + "node_id": "459:451", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "UNet加载器", + "actual": "UNETLoader" + } + ] + }, + { + "node_id": "459:452", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "文本编码 Qwen Image 2.1", + "actual": "TextEncodeQwenImage21" + } + ] + }, + { + "node_id": "459:453", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载CLIP", + "actual": "CLIPLoader" + } + ] + }, + { + "node_id": "459:454", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "459:456", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "空Latent图像", + "actual": "EmptyLatentImage" + } + ] + }, + { + "node_id": "459:457", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "VAE解码", + "actual": "VAEDecode" + } + ] + }, + { + "node_id": "459:458", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "K采样器", + "actual": "KSampler" + } + ] + }, + { + "node_id": "459:471", + "differences": [] + }, + { + "node_id": "459:472", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "459:473", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载CLIP", + "actual": "CLIPLoader" + } + ] + }, + { + "node_id": "459:474", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "切换", + "actual": "ComfySwitchNode" + } + ] + }, + { + "node_id": "459:475", + "differences": [] + }, + { + "node_id": "459:480", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Qwen Image 2.1 缓存", + "actual": "QwenImage21Cache" + } + ] + }, + { + "node_id": "461", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存图像(高级)", + "actual": "SaveImageAdvanced" + } + ] + }, + { + "node_id": "483", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "字符串(多行)", + "actual": "PrimitiveStringMultiline" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "05", + "selected_profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "source_path": "example_ComfyUI_workflows/4-视频生成/Minimax-h3/MiniMax_H3_导演台时间线素材_双采样潜空间放大_多分段拼接.json", + "source_sha256": "172eb8af3aca70082941427520fdcca06568957bab3d39101c5e9d6641b45e4a", + "api_sha256": "95a01c1ea27a8279a6dc202820505099a94161d91e0789189b61208b09007af8", + "source_frontend_version": "1.52.7", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_frontend_mismatch", + "message": "源图声明的前端版本与固定参考不一致", + "node_id": "" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:SaveVideo", + "node_id": "10" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ModelAttentionBackend", + "node_id": "19" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3SigmaShift", + "node_id": "18" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:BlockSparseAttention", + "node_id": "20" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CLIPLoader", + "node_id": "2" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "4" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:LoraLoaderModelOnly", + "node_id": "21" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ModelPreviewOverrideKJ", + "node_id": "22" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3FiniteSegmentSampler", + "node_id": "8" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:CreateVideo", + "node_id": "9" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:ResolutionSelector", + "node_id": "24" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:MiniMaxH3TimelinePlanner", + "node_id": "7" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:VAELoader", + "node_id": "3" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:UNETLoader", + "node_id": "1" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:BasicScheduler", + "node_id": "5" + }, + { + "code": "reference_node_unsupported", + "message": "固定参考契约未覆盖节点:KSamplerSelect", + "node_id": "6" + }, + { + "code": "empty_prompt", + "message": "未得到可执行节点", + "node_id": "" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "10", + "input": "video", + "via_reroute": false, + "source_reference": [ + "9", + 0 + ], + "api": [ + "9", + 0 + ], + "differences": [] + }, + { + "node_id": "19", + "input": "model", + "via_reroute": false, + "source_reference": [ + "18", + 0 + ], + "api": [ + "18", + 0 + ], + "differences": [] + }, + { + "node_id": "18", + "input": "model", + "via_reroute": false, + "source_reference": [ + "21", + 0 + ], + "api": [ + "21", + 0 + ], + "differences": [] + }, + { + "node_id": "20", + "input": "model", + "via_reroute": false, + "source_reference": [ + "19", + 0 + ], + "api": [ + "19", + 0 + ], + "differences": [] + }, + { + "node_id": "21", + "input": "model", + "via_reroute": false, + "source_reference": [ + "1", + 0 + ], + "api": [ + "1", + 0 + ], + "differences": [] + }, + { + "node_id": "22", + "input": "model", + "via_reroute": false, + "source_reference": [ + "20", + 0 + ], + "api": [ + "20", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "model", + "via_reroute": false, + "source_reference": [ + "22", + 0 + ], + "api": [ + "22", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "clip", + "via_reroute": false, + "source_reference": [ + "2", + 0 + ], + "api": [ + "2", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "vae", + "via_reroute": false, + "source_reference": [ + "3", + 0 + ], + "api": [ + "3", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "audio_vae", + "via_reroute": false, + "source_reference": [ + "4", + 0 + ], + "api": [ + "4", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "finite_plan", + "via_reroute": false, + "source_reference": [ + "7", + 2 + ], + "api": [ + "7", + 2 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "sampler", + "via_reroute": false, + "source_reference": [ + "6", + 0 + ], + "api": [ + "6", + 0 + ], + "differences": [] + }, + { + "node_id": "8", + "input": "sigmas", + "via_reroute": false, + "source_reference": [ + "5", + 0 + ], + "api": [ + "5", + 0 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "images", + "via_reroute": false, + "source_reference": [ + "8", + 1 + ], + "api": [ + "8", + 1 + ], + "differences": [] + }, + { + "node_id": "9", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "8", + 2 + ], + "api": [ + "8", + 2 + ], + "differences": [] + }, + { + "node_id": "7", + "input": "width", + "via_reroute": false, + "source_reference": [ + "24", + 0 + ], + "api": [ + "24", + 0 + ], + "differences": [] + }, + { + "node_id": "7", + "input": "height", + "via_reroute": false, + "source_reference": [ + "24", + 1 + ], + "api": [ + "24", + 1 + ], + "differences": [] + }, + { + "node_id": "5", + "input": "model", + "via_reroute": false, + "source_reference": [ + "22", + 0 + ], + "api": [ + "22", + 0 + ], + "differences": [] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "10", + "type": "SaveVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "19", + "type": "ModelAttentionBackend", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "18", + "type": "MiniMaxH3SigmaShift", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "20", + "type": "BlockSparseAttention", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "2", + "type": "CLIPLoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "4", + "type": "VAELoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "21", + "type": "LoraLoaderModelOnly", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "22", + "type": "ModelPreviewOverrideKJ", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "8", + "type": "MiniMaxH3FiniteSegmentSampler", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "9", + "type": "CreateVideo", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "24", + "type": "ResolutionSelector", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "7", + "type": "MiniMaxH3TimelinePlanner", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "3", + "type": "VAELoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "1", + "type": "UNETLoader", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "5", + "type": "BasicScheduler", + "reason": "源节点声明与固定核心参考版本不符" + }, + { + "node_id": "6", + "type": "KSamplerSelect", + "reason": "源节点声明与固定核心参考版本不符" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "10", + "source_type": "SaveVideo", + "api_type": "SaveVideo", + "differences": [] + }, + { + "node_id": "19", + "source_type": "ModelAttentionBackend", + "api_type": "ModelAttentionBackend", + "differences": [] + }, + { + "node_id": "18", + "source_type": "MiniMaxH3SigmaShift", + "api_type": "MiniMaxH3SigmaShift", + "differences": [] + }, + { + "node_id": "20", + "source_type": "BlockSparseAttention", + "api_type": "BlockSparseAttention", + "differences": [] + }, + { + "node_id": "2", + "source_type": "CLIPLoader", + "api_type": "CLIPLoader", + "differences": [] + }, + { + "node_id": "4", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "21", + "source_type": "LoraLoaderModelOnly", + "api_type": "LoraLoaderModelOnly", + "differences": [] + }, + { + "node_id": "22", + "source_type": "ModelPreviewOverrideKJ", + "api_type": "ModelPreviewOverrideKJ", + "differences": [] + }, + { + "node_id": "8", + "source_type": "MiniMaxH3FiniteSegmentSampler", + "api_type": "MiniMaxH3FiniteSegmentSampler", + "differences": [] + }, + { + "node_id": "9", + "source_type": "CreateVideo", + "api_type": "CreateVideo", + "differences": [] + }, + { + "node_id": "24", + "source_type": "ResolutionSelector", + "api_type": "ResolutionSelector", + "differences": [] + }, + { + "node_id": "7", + "source_type": "MiniMaxH3TimelinePlanner", + "api_type": "MiniMaxH3TimelinePlanner", + "differences": [] + }, + { + "node_id": "3", + "source_type": "VAELoader", + "api_type": "VAELoader", + "differences": [] + }, + { + "node_id": "1", + "source_type": "UNETLoader", + "api_type": "UNETLoader", + "differences": [] + }, + { + "node_id": "5", + "source_type": "BasicScheduler", + "api_type": "BasicScheduler", + "differences": [] + }, + { + "node_id": "6", + "source_type": "KSamplerSelect", + "api_type": "KSamplerSelect", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "10", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存视频", + "actual": "SaveVideo" + } + ] + }, + { + "node_id": "19", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "模型注意力后端", + "actual": "ModelAttentionBackend" + } + ] + }, + { + "node_id": "18", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 Sigma Shift", + "actual": "MiniMaxH3SigmaShift" + } + ] + }, + { + "node_id": "20", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "模型稀疏注意力", + "actual": "BlockSparseAttention" + } + ] + }, + { + "node_id": "2", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载CLIP", + "actual": "CLIPLoader" + } + ] + }, + { + "node_id": "4", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "21", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "LoRA加载器(仅模型)", + "actual": "LoraLoaderModelOnly" + } + ] + }, + { + "node_id": "22", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "Model Preview Override", + "actual": "ModelPreviewOverrideKJ" + } + ] + }, + { + "node_id": "8", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 有限分段采样", + "actual": "MiniMaxH3FiniteSegmentSampler" + } + ] + }, + { + "node_id": "9", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "创建视频", + "actual": "CreateVideo" + } + ] + }, + { + "node_id": "24", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "分辨率选择器", + "actual": "ResolutionSelector" + } + ] + }, + { + "node_id": "7", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "MiniMax H3 素材规划台", + "actual": "MiniMaxH3TimelinePlanner" + } + ] + }, + { + "node_id": "3", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "加载VAE", + "actual": "VAELoader" + } + ] + }, + { + "node_id": "1", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "UNet加载器", + "actual": "UNETLoader" + } + ] + }, + { + "node_id": "5", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "基本调度器", + "actual": "BasicScheduler" + } + ] + }, + { + "node_id": "6", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "K采样器选择", + "actual": "KSamplerSelect" + } + ] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + }, + { + "id": "07", + "selected_profile": "comfy-frontend-1.48.6-structure-reference", + "source_path": "example_ComfyUI_workflows/6-动作迁移/Wan_Animate2_动作迁移_for循环长视频.json", + "source_sha256": "22b7853e22629822dd354b0b768e2961a53b4c2f480cfaceeaea9dc51c0f0d0b", + "api_sha256": "b1b4f6a6c02d8d21701943c67b62805b1210fed17e7e26b618c58e112ea1d70d", + "source_frontend_version": "1.48.6", + "export_frontend_version": null, + "whole_prompt_available": false, + "whole_prompt_differences": null, + "whole_prompt_issues": [ + { + "code": "reference_structure_invalid", + "message": "局部网络包含连线循环" + } + ], + "production_prompt_available": false, + "serialized_fields": [], + "topology_edges": [ + { + "node_id": "292", + "input": "video", + "status": "unsupported", + "reason": "静音/旁路不在追线参考契约内" + }, + { + "node_id": "291", + "input": "video", + "status": "unsupported", + "reason": "静音/旁路不在追线参考契约内" + }, + { + "node_id": "600", + "input": "AUDIO", + "via_reroute": false, + "source_reference": [ + "585", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "586", + "input": "video_info", + "via_reroute": false, + "source_reference": [ + "585", + 3 + ], + "api": [ + "585", + 3 + ], + "differences": [] + }, + { + "node_id": "604", + "input": "INT", + "via_reroute": false, + "source_reference": [ + "586", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "586", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "597", + "input": "FLOAT", + "via_reroute": false, + "source_reference": [ + "536", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "536", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "538", + "input": "source", + "via_reroute": false, + "source_reference": [ + "536", + 0 + ], + "api": [ + "536", + 0 + ], + "differences": [] + }, + { + "node_id": "536", + "input": "values.a", + "via_reroute": false, + "source_reference": [ + "605", + 0 + ], + "api": [ + "586", + 1 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "586", + "actual": "605" + }, + { + "path": "/1", + "kind": "value", + "expected": 1, + "actual": 0 + } + ] + }, + { + "node_id": "536", + "input": "values.b", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": [ + "580", + 0 + ], + "differences": [] + }, + { + "node_id": "477", + "input": "input", + "via_reroute": true, + "source_reference": [ + "189", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "189", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "continue_motion", + "via_reroute": false, + "source_reference": [ + "606", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "video_frame_offset_1", + "via_reroute": false, + "source_reference": [ + "606", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "text", + "via_reroute": false, + "source_reference": [ + "583", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "583", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "text_4", + "via_reroute": false, + "source_reference": [ + "584", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "584", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "resize_type.width", + "via_reroute": false, + "source_reference": [ + "579", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "resize_type.height_1", + "via_reroute": false, + "source_reference": [ + "579", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "length", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "580", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "477", + "input": "input_1", + "via_reroute": true, + "source_reference": [ + "585", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "input", + "via_reroute": true, + "source_reference": [ + "189", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "189", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "text", + "via_reroute": false, + "source_reference": [ + "583", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "583", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "text_4", + "via_reroute": false, + "source_reference": [ + "584", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "584", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "resize_type.width", + "via_reroute": false, + "source_reference": [ + "579", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "resize_type.height_1", + "via_reroute": false, + "source_reference": [ + "579", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "579", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "length", + "via_reroute": false, + "source_reference": [ + "580", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "580", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "261", + "input": "input_1", + "via_reroute": true, + "source_reference": [ + "585", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "585", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "607", + "input": "source", + "via_reroute": false, + "source_reference": [ + "606", + 3 + ], + "api": [ + "606:596", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "606:596", + "actual": "606" + }, + { + "path": "/1", + "kind": "value", + "expected": 0, + "actual": 3 + } + ] + }, + { + "node_id": "608", + "input": "*", + "via_reroute": false, + "source_reference": [ + "606", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "606", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "245", + "input": "images", + "via_reroute": false, + "source_reference": [ + "609", + 0 + ], + "api": [ + "606:599", + 2 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "606:599", + "actual": "609" + }, + { + "path": "/1", + "kind": "value", + "expected": 2, + "actual": 0 + } + ] + }, + { + "node_id": "245", + "input": "audio", + "via_reroute": false, + "source_reference": [ + "602", + 0 + ], + "api": [ + "585", + 2 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "585", + "actual": "602" + }, + { + "path": "/1", + "kind": "value", + "expected": 2, + "actual": 0 + } + ] + }, + { + "node_id": "245", + "input": "fps", + "via_reroute": false, + "source_reference": [ + "603", + 0 + ], + "api": [ + "586", + 0 + ], + "differences": [ + { + "path": "/0", + "kind": "value", + "expected": "586", + "actual": "603" + } + ] + }, + { + "node_id": "246", + "input": "video", + "via_reroute": false, + "source_reference": [ + "245", + 0 + ], + "api": [ + "245", + 0 + ], + "differences": [] + }, + { + "node_id": "601", + "input": "FLOAT", + "via_reroute": false, + "source_reference": [ + "586", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "586", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value1", + "via_reroute": false, + "source_reference": [ + "261", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value2", + "via_reroute": false, + "source_reference": [ + "261", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value3", + "via_reroute": false, + "source_reference": [ + "261", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "261", + 2 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "a", + "via_reroute": false, + "source_reference": [ + "598", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "598", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value1_1", + "via_reroute": false, + "source_reference": [ + "477", + 0 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 0 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "initial_value2_1", + "via_reroute": false, + "source_reference": [ + "477", + 1 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 1 + ], + "kind": "type" + } + ] + }, + { + "node_id": "606", + "input": "images.image1_1", + "via_reroute": false, + "source_reference": [ + "477", + 2 + ], + "api": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": [ + "477", + 2 + ], + "kind": "type" + } + ] + } + ], + "unsupported_widget_nodes": [ + { + "node_id": "292", + "type": "SaveVideo", + "reason": "未知参考版本" + }, + { + "node_id": "291", + "type": "79280513-53b2-4417-93f8-f3e116bb6736", + "reason": "未知参考版本" + }, + { + "node_id": "583", + "type": "PrimitiveStringMultiline", + "reason": "未知参考版本" + }, + { + "node_id": "580", + "type": "INTConstant", + "reason": "未知参考版本" + }, + { + "node_id": "579", + "type": "TTResolutionSelector", + "reason": "未知参考版本" + }, + { + "node_id": "600", + "type": "SetNode", + "reason": "未知参考版本" + }, + { + "node_id": "603", + "type": "GetNode", + "reason": "未知参考版本" + }, + { + "node_id": "602", + "type": "GetNode", + "reason": "未知参考版本" + }, + { + "node_id": "586", + "type": "VHS_VideoInfoLoaded", + "reason": "未知参考版本" + }, + { + "node_id": "604", + "type": "SetNode", + "reason": "未知参考版本" + }, + { + "node_id": "605", + "type": "GetNode", + "reason": "未知参考版本" + }, + { + "node_id": "584", + "type": "PrimitiveStringMultiline", + "reason": "未知参考版本" + }, + { + "node_id": "597", + "type": "SetNode", + "reason": "未知参考版本" + }, + { + "node_id": "538", + "type": "PreviewAny", + "reason": "未知参考版本" + }, + { + "node_id": "536", + "type": "ComfyMathExpression", + "reason": "未知参考版本" + }, + { + "node_id": "477", + "type": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "reason": "未知参考版本" + }, + { + "node_id": "598", + "type": "GetNode", + "reason": "未知参考版本" + }, + { + "node_id": "261", + "type": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "reason": "未知参考版本" + }, + { + "node_id": "607", + "type": "PreviewAny", + "reason": "未知参考版本" + }, + { + "node_id": "608", + "type": "SetNode", + "reason": "未知参考版本" + }, + { + "node_id": "245", + "type": "CreateVideo", + "reason": "未知参考版本" + }, + { + "node_id": "609", + "type": "GetNode", + "reason": "未知参考版本" + }, + { + "node_id": "246", + "type": "SaveVideo", + "reason": "未知参考版本" + }, + { + "node_id": "601", + "type": "SetNode", + "reason": "未知参考版本" + }, + { + "node_id": "189", + "type": "LoadImage", + "reason": "未知参考版本" + }, + { + "node_id": "610", + "type": "Label (rgthree)", + "reason": "未知参考版本" + }, + { + "node_id": "606", + "type": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "reason": "未知参考版本" + }, + { + "node_id": "585", + "type": "VHS_LoadVideo", + "reason": "未知参考版本" + } + ], + "diagnostic_graph": null, + "unresolved_boundaries": [], + "node_types": [ + { + "node_id": "292", + "source_type": "SaveVideo", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SaveVideo", + "kind": "type" + } + ] + }, + { + "node_id": "291", + "source_type": "79280513-53b2-4417-93f8-f3e116bb6736", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "79280513-53b2-4417-93f8-f3e116bb6736", + "kind": "type" + } + ] + }, + { + "node_id": "583", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + }, + { + "node_id": "580", + "source_type": "INTConstant", + "api_type": "INTConstant", + "differences": [] + }, + { + "node_id": "579", + "source_type": "TTResolutionSelector", + "api_type": "TTResolutionSelector", + "differences": [] + }, + { + "node_id": "600", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "603", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "602", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "586", + "source_type": "VHS_VideoInfoLoaded", + "api_type": "VHS_VideoInfoLoaded", + "differences": [] + }, + { + "node_id": "604", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "605", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "584", + "source_type": "PrimitiveStringMultiline", + "api_type": "PrimitiveStringMultiline", + "differences": [] + }, + { + "node_id": "597", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "538", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "536", + "source_type": "ComfyMathExpression", + "api_type": "ComfyMathExpression", + "differences": [] + }, + { + "node_id": "477", + "source_type": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "b798a87e-23ec-483d-ab9b-6af5b298d0ad", + "kind": "type" + } + ] + }, + { + "node_id": "598", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "261", + "source_type": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "11706f8a-428d-4ef9-b24f-863f651c1b0b", + "kind": "type" + } + ] + }, + { + "node_id": "607", + "source_type": "PreviewAny", + "api_type": "PreviewAny", + "differences": [] + }, + { + "node_id": "608", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "245", + "source_type": "CreateVideo", + "api_type": "CreateVideo", + "differences": [] + }, + { + "node_id": "609", + "source_type": "GetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "GetNode", + "kind": "type" + } + ] + }, + { + "node_id": "246", + "source_type": "SaveVideo", + "api_type": "SaveVideo", + "differences": [] + }, + { + "node_id": "601", + "source_type": "SetNode", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "SetNode", + "kind": "type" + } + ] + }, + { + "node_id": "189", + "source_type": "LoadImage", + "api_type": "LoadImage", + "differences": [] + }, + { + "node_id": "610", + "source_type": "Label (rgthree)", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "Label (rgthree)", + "kind": "type" + } + ] + }, + { + "node_id": "606", + "source_type": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "api_type": null, + "differences": [ + { + "path": "", + "expected": null, + "actual": "bb1c37c2-3479-48a8-88c0-11e7d43715d6", + "kind": "type" + } + ] + }, + { + "node_id": "585", + "source_type": "VHS_LoadVideo", + "api_type": "VHS_LoadVideo", + "differences": [] + } + ], + "metadata": [ + { + "node_id": "292", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "SaveVideo" + }, + "kind": "type" + } + ] + }, + { + "node_id": "291", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "79280513-53b2-4417-93f8-f3e116bb6736" + }, + "kind": "type" + } + ] + }, + { + "node_id": "583", + "differences": [] + }, + { + "node_id": "580", + "differences": [] + }, + { + "node_id": "579", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "TT分辨率选择器", + "actual": "TTResolutionSelector" + } + ] + }, + { + "node_id": "600", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_音频" + }, + "kind": "type" + } + ] + }, + { + "node_id": "603", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_帧率" + }, + "kind": "type" + } + ] + }, + { + "node_id": "602", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_音频" + }, + "kind": "type" + } + ] + }, + { + "node_id": "586", + "differences": [] + }, + { + "node_id": "604", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_动作视频帧数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "605", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_动作视频帧数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "584", + "differences": [] + }, + { + "node_id": "597", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_执行次数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "538", + "differences": [] + }, + { + "node_id": "536", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "数学表达式", + "actual": "ComfyMathExpression" + } + ] + }, + { + "node_id": "477", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "b798a87e-23ec-483d-ab9b-6af5b298d0ad" + }, + "kind": "type" + } + ] + }, + { + "node_id": "598", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_执行次数" + }, + "kind": "type" + } + ] + }, + { + "node_id": "261", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "11706f8a-428d-4ef9-b24f-863f651c1b0b" + }, + "kind": "type" + } + ] + }, + { + "node_id": "607", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "预览任意", + "actual": "PreviewAny" + } + ] + }, + { + "node_id": "608", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_循环结果输出" + }, + "kind": "type" + } + ] + }, + { + "node_id": "245", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "创建视频", + "actual": "CreateVideo" + } + ] + }, + { + "node_id": "609", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Get_循环结果输出" + }, + "kind": "type" + } + ] + }, + { + "node_id": "246", + "differences": [ + { + "path": "/title", + "kind": "value", + "expected": "保存视频", + "actual": "SaveVideo" + } + ] + }, + { + "node_id": "601", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Set_帧率" + }, + "kind": "type" + } + ] + }, + { + "node_id": "189", + "differences": [] + }, + { + "node_id": "610", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "Wan_animate2_动作迁移 For循环长视频 by Bright" + }, + "kind": "type" + } + ] + }, + { + "node_id": "606", + "differences": [ + { + "path": "", + "expected": null, + "actual": { + "title": "bb1c37c2-3479-48a8-88c0-11e7d43715d6" + }, + "kind": "type" + } + ] + }, + { + "node_id": "585", + "differences": [] + } + ], + "api_only_fields_for_supported_nodes": [], + "comparison_is_complete": false, + "executable": false, + "execution_verified": false + } + ] +} diff --git a/docs/hel-892/structure-evidence/source-verification.json b/docs/hel-892/structure-evidence/source-verification.json new file mode 100644 index 00000000..a0a475ee --- /dev/null +++ b/docs/hel-892/structure-evidence/source-verification.json @@ -0,0 +1,203 @@ +{ + "authority": "public_reference_only", + "sources_verified": [ + { + "id": "1.37.11:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "1.37.11:src/extensions/core/widgetInputs.ts", + "sha256": "488d38eb209816778a6da8cb8f734f539e3fbd7f77aae41ec649a52b8764b613" + }, + { + "id": "1.37.11:src/utils/executionUtil.ts", + "sha256": "4e51bc54e35cb7ac9bb7cba418a74ccdd5974f640b9b088aa4ae7668f746ab36" + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "fd2e19a6b8f4369e6e97d79f407cc1bec130feec9d6d3c979cc03b0a556f249f" + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2" + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "d4f1017495158a6133ff770441a4d517dfbf2a328ba42b0405f8729853fe8209" + }, + { + "id": "1.37.11:src/lib/litegraph/src/LLink.ts", + "sha256": "1d58845322b30f122aeafb23ca286ca7349ca23215469f96afb7a98fd6596af4" + }, + { + "id": "1.48.7:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "1.48.7:src/extensions/core/widgetInputs.ts", + "sha256": "fdceceedc727e8a696f273a810fc39a075004a09ea793e0df51418f96ac52a61" + }, + { + "id": "1.48.7:src/utils/executionUtil.ts", + "sha256": "264e11395f28880603e7f9fe36d2e61c74cd59d6d88be990225cce8510e3f816" + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "64baa71b46bd67440b032e18e4d9aebb67a6cc135fe7c4509ae1b5bc25acc2a3" + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2" + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "822b0cdde3fe6a096f82310075a6285ae967dc58d760f19d743442ea20f4f15f" + }, + { + "id": "1.48.7:src/lib/litegraph/src/LLink.ts", + "sha256": "9e9c92acacd5edc58a9c1ad2b3ba66679f27ebda28da74765947d88ce11df656" + }, + { + "id": "1.53.6:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "1.53.6:src/extensions/core/widgetInputs.ts", + "sha256": "f6b3d33b9ffdf4f68136ee0f72d03dabf4affa3292721d1f221b47de792e0daf" + }, + { + "id": "1.53.6:src/utils/executionUtil.ts", + "sha256": "b29fd312e66c7415fa4c720654ac121dc67600b0c1fedf079b6575a174960698" + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "0c0ca487822a9f86324925c2fb4ea59c6c032ad5d042a83ac367cb15196454fe" + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2" + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "29f2da27396bcc426180d819549f654278d65de973ade651d57c4905e319fb9c" + }, + { + "id": "1.53.6:src/lib/litegraph/src/LLink.ts", + "sha256": "562694d5bccb5682222c500a7e7069501eeb94e69eeb1b9a534d1e511902ef57" + }, + { + "id": "1.48.6:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "1.48.6:src/extensions/core/widgetInputs.ts", + "sha256": "fdceceedc727e8a696f273a810fc39a075004a09ea793e0df51418f96ac52a61" + }, + { + "id": "1.48.6:src/utils/executionUtil.ts", + "sha256": "264e11395f28880603e7f9fe36d2e61c74cd59d6d88be990225cce8510e3f816" + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "64baa71b46bd67440b032e18e4d9aebb67a6cc135fe7c4509ae1b5bc25acc2a3" + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2" + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "822b0cdde3fe6a096f82310075a6285ae967dc58d760f19d743442ea20f4f15f" + }, + { + "id": "1.48.6:src/lib/litegraph/src/LLink.ts", + "sha256": "9e9c92acacd5edc58a9c1ad2b3ba66679f27ebda28da74765947d88ce11df656" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/extensions/core/previewAny.ts", + "sha256": "2b19989ac8a3c26e198c7db7f7e2210936b0a4f4d3b26183917baafb841c1874" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/extensions/core/uploadAudio.ts", + "sha256": "0a11f1ad5651d238130bc06aca2a4b31a41f8bec98d0f8512e02ffb42b262e66" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/widgets.ts", + "sha256": "e8bb428cbf69635015de43a4ebc89817b3443f876cbed52eeafe67d26f2398d8" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/app.ts", + "sha256": "e57985f7d365abb035bc2fc755a8f5b10efbca97a7dcb5b2a4a05bcbc78b9d5c" + }, + { + "id": "1038lab/ComfyUI-QwenASR:AILab_QwenASR.py", + "sha256": "f8cda2d0d39517f93ace1a73263146a4bea59a02604e58919a05393c45ade6b7" + }, + { + "id": "1038lab/ComfyUI-QwenASR:__init__.py", + "sha256": "0919008142c12f8fe9a12671a1ca1de548ded128dd7287a13f6230d9729b47c2" + }, + { + "id": "Comfy-Org/ComfyUI:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "Comfy-Org/ComfyUI:comfy_extras/nodes_audio.py", + "sha256": "d47eefe226c273f20561545f6a664bfdfa5c193cec7178c925b5dc5ccb642a9c" + }, + { + "id": "Comfy-Org/ComfyUI:comfy_extras/nodes_preview_any.py", + "sha256": "f8c526dbc4ec512f88a067524865f59eb24db636858f37d601e848885b2d0751" + }, + { + "id": "qwen-history:aaf40688c93c8e083f8a47d9107e6f95405ea7c9", + "sha256": "f8cda2d0d39517f93ace1a73263146a4bea59a02604e58919a05393c45ade6b7" + }, + { + "id": "qwen-history:b037d7be121111a1ba6f40a4d99f6b43ac6411b6", + "sha256": "af7721c1015fef8cb40a724226fb0f720397d70fb1ce367f9145a3b653dd0cd9" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/utils/nodeDefUtil.ts", + "sha256": "9c62901804e584a2e9d7e17e7914475113e41993c44df3d063f0027e95735dc1" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/renderer/extensions/vueNodes/widgets/composables/useStringWidget.ts", + "sha256": "b734a2584d558de501150e8011e1c16031f33778c2cd3b4c712f296ce4f05396" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:packages/shared-frontend-utils/src/formatUtil.ts", + "sha256": "7313418fe3a92aae99f2ef91f081257c2b2162b1578155d7346f2f03ab440039" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/domWidget.ts", + "sha256": "34ec3c58d6b236f4e99bfa0c82dcab8e15c6a6b51c6dcb9ace30e37d1a395800" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/lib/litegraph/src/LGraphNode.ts", + "sha256": "706225a8a06cd7929f9e04fe2388bcdb8f158cdac756c65c45657c020ab7b319" + }, + { + "id": "1038lab/ComfyUI-QwenASR:LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" + }, + { + "id": "1038lab/ComfyUI-QwenASR:__init__.py", + "sha256": "e35f18c3986ee7b00a918ed644e375bc7cee1b88f740cc52fd93b45ace621a41" + }, + { + "id": "ComfyUI_frontend:src/lib/litegraph/src/widgets/BaseWidget.ts", + "sha256": "6a77b402bbf8c67b9ea2ce58de28c61a1b17da82bb437c29565fb260b721b8c7" + }, + { + "id": "ComfyUI_frontend:src/lib/litegraph/src/widgets/LegacyWidget.ts", + "sha256": "05d098254988191736f1c72f7efc57e3f350d97c82267a97f0b8c193d65daa96" + }, + { + "id": "ComfyUI_frontend:src/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget.ts", + "sha256": "36f477f75561e0c7bfc2c6757906724f8ff2c8660ace26759f3f07493877fece" + } + ], + "upstream_code_executed": false, + "target_version_match": "unknown" +} diff --git a/docs/hel-892/structure-evidence/summary.json b/docs/hel-892/structure-evidence/summary.json new file mode 100644 index 00000000..962fdf77 --- /dev/null +++ b/docs/hel-892/structure-evidence/summary.json @@ -0,0 +1,103 @@ +{ + "tested_code_commit": "1f779d53c4312068513c2bd6d513f01a3c9f3caf", + "increment_base": "97f3a76f0ab5da110f4c3a7e79576627d7dedaf9", + "final_delivery_commit": "see subsequent evidence-only commit containing this file; code hashes below are unchanged", + "code_sha256": { + "calliope-backend/scripts/audit_reference_conversion.py": "af3bc0b790f459a72b32517580db7fb7183a5c9d17d563a527ec8c58ff0576f0", + "calliope-backend/src/calliope/comfyui/serialization_reference.py": "1d36316c5619471a13964f13a883a87dc01e445e028d1f653db6b5cd9086a509", + "calliope-backend/src/calliope/comfyui/structure_reference.py": "5bf992902afedd52c91fca31d6d29e29c112e973b112f6754ddb39da9684c7fd", + "calliope-backend/src/calliope/comfyui/ui2api.py": "793a74cff1923e80883d7b1e45ce3e0d08c88a9b194f0702f1cdf0d28e8c2589", + "calliope-backend/tests/test_structure_reference.py": "ab532c7aeb592cff1935dbd4a8657e1c318b3d5a7d8f2da1b5886c20775fcdc5" + }, + "tests": { + "passed": 178, + "failed": 0, + "warning": 1, + "new_specialized": 32, + "existing_affected": 146 + }, + "sources_refetched_and_verified": 49, + "full_backend_rerun": false, + "historical_only": "142 and 865/5/6", + "production_eligibility_changed": false, + "cases": [ + { + "id": "01", + "profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "candidate": true, + "class_types_compared": 22, + "field_items": 34, + "field_differences": 0, + "edges_compared": 23, + "edges_equal": 23, + "unresolved_boundaries": 0, + "metadata_differences": 13, + "whole_prompt_issue_count": 0 + }, + { + "id": "02", + "profile": "comfy-frontend-1.37.11-qwen-b037d7be-reference", + "candidate": false, + "class_types_compared": 6, + "field_items": 16, + "field_differences": 1, + "edges_compared": 5, + "edges_equal": 5, + "unresolved_boundaries": 0, + "metadata_differences": 6, + "whole_prompt_issue_count": 4 + }, + { + "id": "03", + "profile": "comfy-frontend-1.48.7-structure-reference", + "candidate": false, + "class_types_compared": 12, + "field_items": 0, + "field_differences": 0, + "edges_compared": 16, + "edges_equal": 16, + "unresolved_boundaries": 8, + "metadata_differences": 12, + "whole_prompt_issue_count": 21 + }, + { + "id": "04", + "profile": "comfy-frontend-1.53.6-structure-reference", + "candidate": false, + "class_types_compared": 16, + "field_items": 0, + "field_differences": 0, + "edges_compared": 18, + "edges_equal": 18, + "unresolved_boundaries": 15, + "metadata_differences": 14, + "whole_prompt_issue_count": 32 + }, + { + "id": "05", + "profile": "comfy-frontend-1.37.11-controlnet-aux-e8b689a-reference", + "candidate": false, + "class_types_compared": 16, + "field_items": 0, + "field_differences": 0, + "edges_compared": 18, + "edges_equal": 18, + "unresolved_boundaries": 0, + "metadata_differences": 16, + "whole_prompt_issue_count": 18 + }, + { + "id": "07", + "profile": "comfy-frontend-1.48.6-structure-reference", + "candidate": false, + "class_types_compared": 28, + "field_items": 0, + "field_differences": 0, + "edges_compared": 39, + "edges_equal": 4, + "unresolved_boundaries": 0, + "metadata_differences": 21, + "whole_prompt_issue_count": 1 + } + ] +} diff --git a/docs/hel-892/structure-evidence/tests.txt b/docs/hel-892/structure-evidence/tests.txt new file mode 100644 index 00000000..0fcc430c --- /dev/null +++ b/docs/hel-892/structure-evidence/tests.txt @@ -0,0 +1,10 @@ +........................................................................ [ 40%] +........................................................................ [ 80%] +.................................. [100%] +=============================== warnings summary =============================== +../../../hel-892-a64a969a6a44/workdir/aigc-home/calliope-backend/.venv/lib/python3.11/site-packages/starlette/testclient.py:53 + /home/xiaomo/multica_workspaces/hello-af23464d222e/hel-892-a64a969a6a44/workdir/aigc-home/calliope-backend/.venv/lib/python3.11/site-packages/starlette/testclient.py:53: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead. + _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]] + +-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html +178 passed, 1 warning in 8.66s diff --git a/docs/hel-892/structure-reference/1.37.11__LICENSE b/docs/hel-892/structure-reference/1.37.11__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/1.37.11__src__extensions__core__widgetInputs.ts b/docs/hel-892/structure-reference/1.37.11__src__extensions__core__widgetInputs.ts new file mode 100644 index 00000000..c7f9f6eb --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__extensions__core__widgetInputs.ts @@ -0,0 +1,614 @@ +import { + type CallbackParams, + useChainCallback +} from '@/composables/functional/useChainCallback' +import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LLink +} from '@/lib/litegraph/src/litegraph' +import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' +import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' +import type { InputSpec } from '@/schemas/nodeDefSchema' +import { app } from '@/scripts/app' +import { + ComfyWidgets, + addValueControlWidgets, + isValidWidgetType +} from '@/scripts/widgets' +import { CONFIG, GET_CONFIG } from '@/services/litegraphService' +import { mergeInputSpec } from '@/utils/nodeDefUtil' +import { applyTextReplacements } from '@/utils/searchAndReplace' +import { isPrimitiveNode } from '@/renderer/utils/nodeTypeGuards' + +const replacePropertyName = 'Run widget replace on values' +export class PrimitiveNode extends LGraphNode { + controlValues?: any[] + lastType?: string + static override category: string + constructor(title: string) { + super(title) + this.addOutput('connect to widget input', '*') + this.serialize_widgets = true + this.isVirtualNode = true + + if (!this.properties || !(replacePropertyName in this.properties)) { + this.addProperty(replacePropertyName, false, 'boolean') + } + } + + override applyToGraph(extraLinks: LLink[] = []) { + if (!this.outputs[0].links?.length || !this.graph) return + + const links = [ + ...this.outputs[0].links.map((l) => this.graph!.links[l]), + ...extraLinks + ] + let v = this.widgets?.[0].value + if (v && this.properties[replacePropertyName]) { + v = applyTextReplacements(this.graph, v as string) + } + + // For each output link copy our value over the original widget value + for (const linkInfo of links) { + const node = this.graph?.getNodeById(linkInfo.target_id) + const input = node?.inputs[linkInfo.target_slot] + if (!input) { + console.warn('Unable to resolve node or input for link', linkInfo) + continue + } + + const widgetName = input.widget?.name + if (!widgetName) { + console.warn('Invalid widget or widget name', input.widget) + continue + } + + const widget = node.widgets?.find((w) => w.name === widgetName) + if (!widget) { + console.warn( + `Unable to find widget "${widgetName}" on node [${node.id}]` + ) + continue + } + + widget.value = v + widget.callback?.( + widget.value, + app.canvas, + node, + app.canvas.graph_mouse, + {} as CanvasPointerEvent + ) + } + } + + override refreshComboInNode() { + const widget = this.widgets?.[0] + if (widget?.type === 'combo') { + // @ts-expect-error fixme ts strict error + widget.options.values = this.outputs[0].widget[GET_CONFIG]()[0] + + // @ts-expect-error fixme ts strict error + if (!widget.options.values.includes(widget.value as string)) { + // @ts-expect-error fixme ts strict error + widget.value = widget.options.values[0] + ;(widget.callback as Function)(widget.value) + } + } + } + + override onAfterGraphConfigured() { + if (this.outputs[0].links?.length && !this.widgets?.length) { + this.#onFirstConnection() + + // Populate widget values from config data + if (this.widgets && this.widgets_values) { + for (let i = 0; i < this.widgets_values.length; i++) { + const w = this.widgets[i] + if (w) { + w.value = this.widgets_values[i] as any + } + } + } + + // Merge values if required + this.#mergeWidgetConfig() + } + } + + override onConnectionsChange( + _type: ISlotType, + _index: number, + connected: boolean + ) { + if (app.configuringGraph) { + // Dont run while the graph is still setting up + return + } + + const links = this.outputs[0].links + if (connected) { + if (links?.length && !this.widgets?.length) { + this.#onFirstConnection() + } + } else { + // We may have removed a link that caused the constraints to change + this.#mergeWidgetConfig() + + if (!links?.length) { + this.onLastDisconnect() + } + } + } + + override onConnectOutput( + slot: number, + _type: string, + input: INodeInputSlot, + target_node: LGraphNode, + target_slot: number + ) { + // Fires before the link is made allowing us to reject it if it isn't valid + // No widget, we can't connect + if (!input.widget && !(input.type in ComfyWidgets)) { + return false + } + + if (this.outputs[slot].links?.length) { + const valid = this.#isValidConnection(input) + if (valid) { + // On connect of additional outputs, copy our value to their widget + this.applyToGraph([{ target_id: target_node.id, target_slot } as LLink]) + } + return valid + } + + return true + } + + #onFirstConnection(recreating?: boolean) { + // First connection can fire before the graph is ready on initial load so random things can be missing + if (!this.outputs[0].links || !this.graph) { + this.onLastDisconnect() + return + } + const linkId = this.outputs[0].links[0] + const link = this.graph.links[linkId] + if (!link) return + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode || !theirNode.inputs) return + + const input = theirNode.inputs[link.target_slot] + if (!input) return + + let widget + if (!input.widget) { + if (!(input.type in ComfyWidgets)) return + widget = { name: input.name, [GET_CONFIG]: () => [input.type, {}] } //fake widget + } else { + widget = input.widget + } + + // @ts-expect-error fixme ts strict error + const config = widget[GET_CONFIG]?.() + if (!config) return + + const { type } = getWidgetType(config) + // Update our output to restrict to the widget type + this.outputs[0].type = type + this.outputs[0].name = type + this.outputs[0].widget = widget + + this.#createWidget( + widget[CONFIG] ?? config, + theirNode, + widget.name, + // @ts-expect-error fixme ts strict error + recreating + ) + } + + #createWidget( + inputData: InputSpec, + node: LGraphNode, + widgetName: string, + recreating: boolean + ) { + let type = inputData[0] + + if (type instanceof Array) { + type = 'COMBO' + } + + // Store current size as addWidget resizes the node + const [oldWidth, oldHeight] = this.size + let widget: IBaseWidget + if (isValidWidgetType(type)) { + widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}).widget + } else { + // @ts-expect-error InputSpec is not typed correctly + widget = this.addWidget(type, 'value', null, () => {}, {}) + } + + if (node?.widgets && widget) { + const theirWidget = node.widgets.find((w) => w.name === widgetName) + if (theirWidget) { + widget.value = theirWidget.value + } + } + + if ( + !inputData?.[1]?.control_after_generate && + (widget.type === 'number' || widget.type === 'combo') + ) { + let control_value = this.widgets_values?.[1] + if (!control_value) { + control_value = 'fixed' + } + addValueControlWidgets( + this, + widget, + control_value as string, + undefined, + inputData + ) + if (this.widgets?.[1]) widget.linkedWidgets = [this.widgets[1]] + + let filter = this.widgets_values?.[2] + if (filter && this.widgets && this.widgets.length === 3) { + this.widgets[2].value = filter + } + } + + // Restore any saved control values + const controlValues = this.controlValues + if ( + this.widgets && + this.lastType === this.widgets[0]?.type && + controlValues?.length === this.widgets.length - 1 + ) { + for (let i = 0; i < controlValues.length; i++) { + this.widgets[i + 1].value = controlValues[i] + } + } + + // When our value changes, update other widgets to reflect our changes + // e.g. so LoadImage shows correct image + widget.callback = useChainCallback(widget.callback, () => { + this.applyToGraph() + }) + + // Use the biggest dimensions in case the widgets caused the node to grow + this.setSize([ + Math.max(this.size[0], oldWidth), + Math.max(this.size[1], oldHeight) + ]) + + if (!recreating) { + // Grow our node more if required + const sz = this.computeSize() + if (this.size[0] < sz[0]) { + this.size[0] = sz[0] + } + if (this.size[1] < sz[1]) { + this.size[1] = sz[1] + } + + requestAnimationFrame(() => { + this.onResize?.(this.size) + }) + } + } + + recreateWidget() { + const values = this.widgets?.map((w) => w.value) + this.#removeWidgets() + this.#onFirstConnection(true) + if (values?.length && this.widgets) { + for (let i = 0; i < this.widgets.length; i++) + this.widgets[i].value = values[i] + } + return this.widgets?.[0] + } + + #mergeWidgetConfig() { + // Merge widget configs if the node has multiple outputs + const output = this.outputs[0] + const links = output.links ?? [] + + const hasConfig = !!output.widget?.[CONFIG] + if (hasConfig) { + delete output.widget?.[CONFIG] + } + + if (links?.length < 2 && hasConfig) { + // Copy the widget options from the source + if (links.length) { + this.recreateWidget() + } + + return + } + const config1 = (output.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config1) return + const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT' + if (!isNumber || !this.graph) return + + for (const linkId of links) { + const link = this.graph.links[linkId] + if (!link) continue // Can be null when removing a node + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode) continue + const theirInput = theirNode.inputs[link.target_slot] + + // Call is valid connection so it can merge the configs when validating + this.#isValidConnection(theirInput, hasConfig) + } + } + + #isValidConnection(input: INodeInputSlot, forceUpdate?: boolean) { + // Only allow connections where the configs match + const output = this.outputs?.[0] + const config2 = (input.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config2) return false + + return !!mergeIfValid.call( + this, + output, + config2, + forceUpdate, + this.recreateWidget + ) + } + + #removeWidgets() { + if (this.widgets) { + // Allow widgets to cleanup + for (const w of this.widgets) { + if (w.onRemove) { + w.onRemove() + } + } + + // Temporarily store the current values in case the node is being recreated + // e.g. by group node conversion + this.controlValues = [] + this.lastType = this.widgets[0]?.type + for (let i = 1; i < this.widgets.length; i++) { + this.controlValues.push(this.widgets[i].value) + } + setTimeout(() => { + delete this.lastType + delete this.controlValues + }, 15) + this.widgets.length = 0 + } + } + + onLastDisconnect() { + // We can't remove + re-add the output here as if you drag a link over the same link + // it removes, then re-adds, causing it to break + this.outputs[0].type = '*' + this.outputs[0].name = 'connect to widget input' + delete this.outputs[0].widget + + this.#removeWidgets() + } +} + +export function getWidgetConfig( + slot: INodeInputSlot | INodeOutputSlot +): InputSpec { + return (slot.widget?.[CONFIG] ?? + (slot.widget?.[GET_CONFIG] as () => InputSpec)?.() ?? [ + '*', + {} + ]) as InputSpec +} + +function getConfig(this: LGraphNode, widgetName: string) { + const { nodeData } = this.constructor + return ( + nodeData?.input?.required?.[widgetName] ?? + nodeData?.input?.optional?.[widgetName] + ) +} + +/** + * Convert a widget to an input slot. + * @deprecated Widget to socket conversion is no longer necessary, as they co-exist now. + * @param node The node to convert the widget to an input slot for. + * @param widget The widget to convert to an input slot. + * @returns The input slot that was converted from the widget or undefined if the widget is not found. + * @knipIgnoreUnusedButUsedByCustomNodes + */ +export function convertToInput( + node: LGraphNode, + widget: IBaseWidget +): INodeInputSlot | undefined { + console.warn( + 'Please remove call to convertToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return node.inputs.find((slot) => slot.widget?.name === widget.name) +} + +function getWidgetType(config: InputSpec) { + // Special handling for COMBO so we restrict links based on the entries + let type = config[0] + if (type instanceof Array) { + type = 'COMBO' + } + return { type } +} + +export function setWidgetConfig(slot: INodeInputSlot, config?: InputSpec) { + if (!slot.widget) return + if (config) { + slot.widget[GET_CONFIG] = () => config + } else { + delete slot.widget + } + + if (!(slot instanceof NodeSlot)) return + const graph = slot.node.graph + if (!graph) return + const link = graph.links[slot.link ?? -1] + if (!link) return + const originNode = graph.getNodeById(link.origin_id) + if (!originNode || !isPrimitiveNode(originNode)) return + if (config) { + originNode.recreateWidget() + } else if (!app.configuringGraph) { + originNode.disconnectOutput(0) + originNode.onLastDisconnect() + } +} + +export function mergeIfValid( + output: INodeOutputSlot | INodeInputSlot, + config2: InputSpec, + forceUpdate?: boolean, + recreateWidget?: () => void, + config1?: InputSpec +): { customConfig: InputSpec[1] } { + if (!config1) { + config1 = getWidgetConfig(output) + } + + const customSpec = mergeInputSpec(config1, config2) + + if (customSpec || forceUpdate) { + if (customSpec) { + // @ts-expect-error fixme ts strict error + output.widget[CONFIG] = customSpec + } + + // @ts-expect-error fixme ts strict error + const widget = recreateWidget?.call(this) + // When deleting a node this can be null + if (widget) { + // @ts-expect-error fixme ts strict error + const min = widget.options.min + // @ts-expect-error fixme ts strict error + const max = widget.options.max + // @ts-expect-error fixme ts strict error + if (min != null && widget.value < min) widget.value = min + // @ts-expect-error fixme ts strict error + if (max != null && widget.value > max) widget.value = max + // @ts-expect-error fixme ts strict error + widget.callback(widget.value) + } + } + + return { customConfig: customSpec?.[1] ?? {} } +} + +app.registerExtension({ + name: 'Comfy.WidgetInputs', + async beforeRegisterNodeDef(nodeType, _nodeData, app) { + // @ts-expect-error adding extra property + nodeType.prototype.convertWidgetToInput = function (this: LGraphNode) { + console.warn( + 'Please remove call to convertWidgetToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return false + } + + nodeType.prototype.onGraphConfigured = useChainCallback( + nodeType.prototype.onGraphConfigured, + function (this: LGraphNode) { + if (!this.inputs) return + this.widgets ??= [] + + for (const input of this.inputs) { + if (input.widget) { + const name = input.widget.name + if (!input.widget[GET_CONFIG]) { + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + + const w = this.widgets?.find((w) => w.name === name) + if (!w) { + this.removeInput(this.inputs.findIndex((i) => i === input)) + } + } + } + } + ) + + nodeType.prototype.onConfigure = useChainCallback( + nodeType.prototype.onConfigure, + function (this: LGraphNode) { + if (!app.configuringGraph && this.inputs) { + // On copy + paste of nodes, ensure that widget configs are set up + for (const input of this.inputs) { + if (input.widget && !input.widget[GET_CONFIG]) { + const name = input.widget.name + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + } + } + } + ) + + // Double click a widget input to automatically attach a primitive + const origOnInputDblClick = nodeType.prototype.onInputDblClick + nodeType.prototype.onInputDblClick = function ( + this: LGraphNode, + ...[slot, ...args]: CallbackParams + ) { + const r = origOnInputDblClick?.apply(this, [slot, ...args]) + + const input = this.inputs[slot] + if (!input.widget) { + // Not a widget input or already handled input + if ( + !(input.type in ComfyWidgets) && + !( + ( + input.widget?.[GET_CONFIG] as (() => InputSpec) | undefined + )?.()?.[0] instanceof Array + ) + ) { + return r //also Not a ComfyWidgets input or combo (do nothing) + } + } + + // Create a primitive node + const node = LiteGraph.createNode('PrimitiveNode') + const graph = app.canvas.graph + if (!node || !graph) return r + + graph?.add(node) + + // Calculate a position that won't directly overlap another node + const pos: [number, number] = [ + this.pos[0] - node.size[0] - 30, + this.pos[1] + ] + while (graph.getNodeOnPos(pos[0], pos[1], graph.nodes)) + pos[1] += LiteGraph.NODE_TITLE_HEIGHT + + node.pos = pos + node.connect(0, this, slot) + node.title = input.name + + return r + } + }, + registerCustomNodes() { + LiteGraph.registerNodeType( + 'PrimitiveNode', + Object.assign(PrimitiveNode, { + title: 'Primitive' + }) + ) + PrimitiveNode.category = 'utils' + } +}) diff --git a/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__LLink.ts b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__LLink.ts new file mode 100644 index 00000000..6ca8832a --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__LLink.ts @@ -0,0 +1,491 @@ +import { + SUBGRAPH_INPUT_ID, + SUBGRAPH_OUTPUT_ID +} from '@/lib/litegraph/src/constants' +import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations' +import { LayoutSource } from '@/renderer/core/layout/types' + +import type { LGraphNode, NodeId } from './LGraphNode' +import type { Reroute, RerouteId } from './Reroute' +import type { + CanvasColour, + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LinkNetwork, + LinkSegment, + Point, + ReadonlyLinkNetwork +} from './interfaces' +import type { Serialisable, SerialisableLLink } from './types/serialisation' + +const layoutMutations = useLayoutMutations() + +export type LinkId = number + +export type SerialisedLLinkArray = [ + id: LinkId, + origin_id: NodeId, + origin_slot: number, + target_id: NodeId, + target_slot: number, + type: ISlotType +] + +// Resolved connection union; eliminates subgraph in/out as a possibility +export type ResolvedConnection = BaseResolvedConnection & + ( + | (ResolvedSubgraphInput & ResolvedNormalOutput) + | (ResolvedNormalInput & ResolvedSubgraphOutput) + | (ResolvedNormalInput & ResolvedNormalOutput) + ) + +interface BaseResolvedConnection { + link: LLink + /** The node on the input side of the link (owns {@link input}) */ + inputNode?: LGraphNode + /** The input the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: INodeInputSlot + /** The node on the output side of the link (owns {@link output}) */ + outputNode?: LGraphNode + /** The output the link is connected to (mutually exclusive with {@link subgraphInput}) */ + output?: INodeOutputSlot + /** The subgraph output the link is connected to (mutually exclusive with {@link input}) */ + subgraphOutput?: SubgraphOutput + /** The subgraph input the link is connected to (mutually exclusive with {@link output}) */ + subgraphInput?: SubgraphInput +} + +interface ResolvedNormalInput { + inputNode: LGraphNode | undefined + input: INodeInputSlot | undefined + subgraphOutput?: undefined +} + +interface ResolvedNormalOutput { + outputNode: LGraphNode | undefined + output: INodeOutputSlot | undefined + subgraphInput?: undefined +} + +interface ResolvedSubgraphInput { + inputNode?: undefined + /** The actual input slot the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: undefined + subgraphOutput: SubgraphOutput +} + +interface ResolvedSubgraphOutput { + outputNode?: undefined + output?: undefined + subgraphInput: SubgraphInput +} + +type BasicReadonlyNetwork = Pick< + ReadonlyLinkNetwork, + 'getNodeById' | 'links' | 'getLink' | 'inputNode' | 'outputNode' +> + +// this is the class in charge of storing link information +export class LLink implements LinkSegment, Serialisable { + static _drawDebug = false + + /** Link ID */ + id: LinkId + parentId?: RerouteId + type: ISlotType + /** Output node ID */ + origin_id: NodeId + /** Output slot index */ + origin_slot: number + /** Input node ID */ + target_id: NodeId + /** Input slot index */ + target_slot: number + + data?: number | string | boolean | { toToolTip?(): string } + _data?: unknown + /** Centre point of the link, calculated during render only - can be inaccurate */ + _pos: Point + /** @todo Clean up - never implemented in comfy. */ + _last_time?: number + /** The last canvas 2D path that was used to render this link */ + path?: Path2D + /** @inheritdoc */ + _centreAngle?: number + + /** @inheritdoc */ + _dragging?: boolean + + #color?: CanvasColour | null + /** Custom colour for this link only */ + public get color(): CanvasColour | null | undefined { + return this.#color + } + + public set color(value: CanvasColour) { + this.#color = value === '' ? null : value + } + + public get isFloatingOutput(): boolean { + return this.origin_id === -1 && this.origin_slot === -1 + } + + public get isFloatingInput(): boolean { + return this.target_id === -1 && this.target_slot === -1 + } + + public get isFloating(): boolean { + return this.isFloatingOutput || this.isFloatingInput + } + + /** `true` if this link is connected to a subgraph input node (the actual origin is in a different graph). */ + get originIsIoNode(): boolean { + return this.origin_id === SUBGRAPH_INPUT_ID + } + + /** `true` if this link is connected to a subgraph output node (the actual target is in a different graph). */ + get targetIsIoNode(): boolean { + return this.target_id === SUBGRAPH_OUTPUT_ID + } + + constructor( + id: LinkId, + type: ISlotType, + origin_id: NodeId, + origin_slot: number, + target_id: NodeId, + target_slot: number, + parentId?: RerouteId + ) { + this.id = id + this.type = type + this.origin_id = origin_id + this.origin_slot = origin_slot + this.target_id = target_id + this.target_slot = target_slot + this.parentId = parentId + + this._data = null + // center + this._pos = [0, 0] + } + + /** @deprecated Use {@link LLink.create} */ + static createFromArray(data: SerialisedLLinkArray): LLink { + return new LLink(data[0], data[5], data[1], data[2], data[3], data[4]) + } + + /** + * LLink static factory: creates a new LLink from the provided data. + * @param data Serialised LLink data to create the link from + * @returns A new LLink + */ + static create(data: SerialisableLLink): LLink { + return new LLink( + data.id, + data.type, + data.origin_id, + data.origin_slot, + data.target_id, + data.target_slot, + data.parentId + ) + } + + /** + * Gets all reroutes from the output slot to this segment. If this segment is a reroute, it will not be included. + * @returns An ordered array of all reroutes from the node output to + * this reroute or the reroute before it. Otherwise, an empty array. + */ + static getReroutes( + network: Pick, + linkSegment: LinkSegment + ): Reroute[] { + if (linkSegment.parentId === undefined) return [] + return network.reroutes.get(linkSegment.parentId)?.getReroutes() ?? [] + } + + static getFirstReroute( + network: Pick, + linkSegment: LinkSegment + ): Reroute | undefined { + return LLink.getReroutes(network, linkSegment).at(0) + } + + /** + * Finds the reroute in the chain after the provided reroute ID. + * @param network The network this link belongs to + * @param linkSegment The starting point of the search (input side). + * Typically the LLink object itself, but can be any link segment. + * @param rerouteId The matching reroute will have this set as its {@link parentId}. + * @returns The reroute that was found, `undefined` if no reroute was found, or `null` if an infinite loop was detected. + */ + static findNextReroute( + network: Pick, + linkSegment: LinkSegment, + rerouteId: RerouteId + ): Reroute | null | undefined { + if (linkSegment.parentId === undefined) return + return network.reroutes + .get(linkSegment.parentId) + ?.findNextReroute(rerouteId) + } + + /** + * Gets the origin node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the origin node of + * @returns The origin node of the link, or `undefined` if the link is not found or the origin node is not found + */ + static getOriginNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.origin_id + return network.getNodeById(id) ?? undefined + } + + /** + * Gets the target node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the target node of + * @returns The target node of the link, or `undefined` if the link is not found or the target node is not found + */ + static getTargetNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.target_id + return network.getNodeById(id) ?? undefined + } + + /** + * Resolves a link ID to the link, node, and slot objects. + * @param linkId The {@link id} of the link to resolve + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + static resolve( + linkId: LinkId | null | undefined, + network: BasicReadonlyNetwork + ): ResolvedConnection | undefined { + return network.getLink(linkId)?.resolve(network) + } + + /** + * Resolves a list of link IDs to the link, node, and slot objects. + * Discards invalid link IDs. + * @param linkIds An iterable of link {@link id}s to resolve + * @param network The link network to search + * @returns An array of resolved connections. If a link is not found, it is not included in the array. + * @see {@link LLink.resolve} + */ + static resolveMany( + linkIds: Iterable, + network: BasicReadonlyNetwork + ): ResolvedConnection[] { + const resolved: ResolvedConnection[] = [] + for (const id of linkIds) { + const r = network.getLink(id)?.resolve(network) + if (r) resolved.push(r) + } + return resolved + } + + /** + * Resolves the primitive ID values stored in the link to the referenced objects. + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + resolve(network: BasicReadonlyNetwork): ResolvedConnection { + const inputNode = + this.target_id === -1 + ? undefined + : (network.getNodeById(this.target_id) ?? undefined) + const input = inputNode?.inputs[this.target_slot] + const subgraphInput = this.originIsIoNode + ? network.inputNode?.slots[this.origin_slot] + : undefined + if (subgraphInput) { + return { inputNode, input, subgraphInput, link: this } + } + + const outputNode = + this.origin_id === -1 + ? undefined + : (network.getNodeById(this.origin_id) ?? undefined) + const output = outputNode?.outputs[this.origin_slot] + const subgraphOutput = this.targetIsIoNode + ? network.outputNode?.slots[this.target_slot] + : undefined + if (subgraphOutput) { + return { + outputNode, + output, + subgraphInput: undefined, + subgraphOutput, + link: this + } + } + + return { + inputNode, + outputNode, + input, + output, + subgraphInput, + subgraphOutput, + link: this + } + } + + configure(o: LLink | SerialisedLLinkArray) { + if (Array.isArray(o)) { + this.id = o[0] + this.origin_id = o[1] + this.origin_slot = o[2] + this.target_id = o[3] + this.target_slot = o[4] + this.type = o[5] + } else { + this.id = o.id + this.type = o.type + this.origin_id = o.origin_id + this.origin_slot = o.origin_slot + this.target_id = o.target_id + this.target_slot = o.target_slot + this.parentId = o.parentId + } + } + + /** + * Checks if the specified node id and output index are this link's origin (output side). + * @param nodeId ID of the node to check + * @param outputIndex The array index of the node output + * @returns `true` if the origin matches, otherwise `false`. + */ + hasOrigin(nodeId: NodeId, outputIndex: number): boolean { + return this.origin_id === nodeId && this.origin_slot === outputIndex + } + + /** + * Checks if the specified node id and input index are this link's target (input side). + * @param nodeId ID of the node to check + * @param inputIndex The array index of the node input + * @returns `true` if the target matches, otherwise `false`. + */ + hasTarget(nodeId: NodeId, inputIndex: number): boolean { + return this.target_id === nodeId && this.target_slot === inputIndex + } + + /** + * Creates a floating link from this link. + * @param slotType The side of the link that is still connected + * @param parentId The parent reroute ID of the link + * @returns A new LLink that is floating + */ + toFloating(slotType: 'input' | 'output', parentId: RerouteId): LLink { + const exported = this.asSerialisable() + exported.id = -1 + exported.parentId = parentId + + if (slotType === 'input') { + exported.origin_id = -1 + exported.origin_slot = -1 + } else { + exported.target_id = -1 + exported.target_slot = -1 + } + + return LLink.create(exported) + } + + /** + * Disconnects a link and removes it from the graph, cleaning up any reroutes that are no longer used + * @param network The container (LGraph) where reroutes should be updated + * @param keepReroutes If `undefined`, reroutes will be automatically removed if no links remain. + * If `input` or `output`, reroutes will not be automatically removed, and retain a connection to the input or output, respectively. + */ + disconnect(network: LinkNetwork, keepReroutes?: 'input' | 'output'): void { + const reroutes = LLink.getReroutes(network, this) + + const lastReroute = reroutes.at(-1) + + // When floating from output, 1-to-1 ratio of floating link to final reroute (tree-like) + const outputFloating = + keepReroutes === 'output' && + lastReroute?.linkIds.size === 1 && + lastReroute.floatingLinkIds.size === 0 + + // When floating from inputs, the final (input side) reroute may have many floating links + if (outputFloating || (keepReroutes === 'input' && lastReroute)) { + const newLink = LLink.create(this) + newLink.id = -1 + + if (keepReroutes === 'input') { + newLink.origin_id = -1 + newLink.origin_slot = -1 + + lastReroute.floating = { slotType: 'input' } + } else { + newLink.target_id = -1 + newLink.target_slot = -1 + + lastReroute.floating = { slotType: 'output' } + } + + network.addFloatingLink(newLink) + } + + for (const reroute of reroutes) { + reroute.linkIds.delete(this.id) + if (!keepReroutes && !reroute.totalLinks) { + network.reroutes.delete(reroute.id) + // Delete reroute from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteReroute(reroute.id) + } + } + network.links.delete(this.id) + // Delete link from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteLink(this.id) + } + + /** + * @deprecated Prefer {@link LLink.asSerialisable} (returns an object, not an array) + * @returns An array representing this LLink + */ + serialize(): SerialisedLLinkArray { + return [ + this.id, + this.origin_id, + this.origin_slot, + this.target_id, + this.target_slot, + this.type + ] + } + + asSerialisable(): SerialisableLLink { + const copy: SerialisableLLink = { + id: this.id, + origin_id: this.origin_id, + origin_slot: this.origin_slot, + target_id: this.target_id, + target_slot: this.target_slot, + type: this.type + } + if (this.parentId !== undefined) copy.parentId = this.parentId + return copy + } +} diff --git a/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts new file mode 100644 index 00000000..9e9454a8 --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts @@ -0,0 +1,408 @@ +import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { LGraphNode, NodeId } from '@/lib/litegraph/src/LGraphNode' +import { InvalidLinkError } from '@/lib/litegraph/src/infrastructure/InvalidLinkError' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import { SlotIndexError } from '@/lib/litegraph/src/infrastructure/SlotIndexError' +import type { + CallbackParams, + CallbackReturn, + ISlotType +} from '@/lib/litegraph/src/interfaces' +import { LGraphEventMode, LiteGraph } from '@/lib/litegraph/src/litegraph' + +import type { Subgraph } from './Subgraph' +import type { SubgraphNode } from './SubgraphNode' + +export type ExecutionId = string + +/** + * Interface describing the data transfer objects used when compiling a graph for execution. + */ +export type ExecutableLGraphNode = Omit< + ExecutableNodeDTO, + 'graph' | 'node' | 'subgraphNode' +> + +/** + * The end result of resolving a DTO input. + * When a widget value is returned, {@link widgetInfo} is present and {@link origin_slot} is `-1`. + */ +type ResolvedInput = { + /** DTO for the node that the link originates from. */ + node: ExecutableLGraphNode + /** Full unique execution ID of the node that the link originates from. In the case of a widget value, this is the ID of the subgraph node. */ + origin_id: ExecutionId + /** The slot index of the output on the node that the link originates from. `-1` when widget value is set. */ + origin_slot: number + /** Boxed widget value (e.g. for widgets). If this box is `undefined`, then an input link is connected, and widget values from the subgraph node are ignored. */ + widgetInfo?: { value: unknown } +} + +/** + * Concrete implementation of {@link ExecutableLGraphNode}. + * @remarks This is the class that is used to create the data transfer objects for executable nodes. + */ +export class ExecutableNodeDTO implements ExecutableLGraphNode { + applyToGraph?( + ...args: CallbackParams + ): CallbackReturn + + /** The graph that this node is a part of. */ + readonly graph: LGraph | Subgraph + + inputs: { linkId: number | null; name: string; type: ISlotType }[] + + /** Backing field for {@link id}. */ + #id: ExecutionId + + /** + * The path to the actual node through subgraph instances, represented as a list of all subgraph node IDs (instances), + * followed by the actual original node ID within the subgraph. Each segment is separated by `:`. + * + * e.g. `1:2:3`: + * - `1` is the node ID of the first subgraph node in the parent workflow + * - `2` is the node ID of the second subgraph node in the first subgraph + * - `3` is the node ID of the actual node in the subgraph definition + */ + get id() { + return this.#id + } + + get type() { + return this.node.type + } + + get title() { + return this.node.title + } + + get mode() { + return this.node.mode + } + + get comfyClass() { + return this.node.comfyClass + } + + get isVirtualNode() { + return this.node.isVirtualNode + } + + get widgets() { + return this.node.widgets + } + + get subgraphId() { + return this.subgraphNode?.subgraph.id + } + + constructor( + /** The actual node that this DTO wraps. */ + readonly node: LGraphNode | SubgraphNode, + /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */ + readonly subgraphNodePath: readonly NodeId[], + /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */ + readonly nodesByExecutionId: Map, + /** The actual subgraph instance that contains this node, otherwise undefined. */ + readonly subgraphNode?: SubgraphNode + ) { + if (!node.graph) throw new NullGraphError() + + // Set the internal ID of the DTO + this.#id = [...this.subgraphNodePath, this.node.id].join(':') + this.graph = node.graph + this.inputs = this.node.inputs.map((x) => ({ + linkId: x.link, + name: x.name, + type: x.type + })) + + // Only create a wrapper if the node has an applyToGraph method + if (this.node.applyToGraph) { + this.applyToGraph = (...args) => this.node.applyToGraph?.(...args) + } + } + + /** Returns either the DTO itself, or the DTOs of the inner nodes of the subgraph. */ + getInnerNodes(): ExecutableLGraphNode[] { + return this.node.isSubgraphNode() + ? this.node.getInnerNodes(this.nodesByExecutionId, this.subgraphNodePath) + : [this] + } + + /** + * Resolves the executable node & link IDs for a given input slot. + * @param slot The slot index of the input. + * @param visited Leave empty unless overriding this method. + * A set of unique IDs, used to guard against infinite recursion. + * If overriding, ensure that the set is passed on all recursive calls. + * @returns The node and the origin ID / slot index of the output. + */ + resolveInput( + slot: number, + visited = new Set(), + type?: ISlotType + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[I]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving input ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + const input = this.inputs.at(slot) + if (!input) + throw new SlotIndexError( + `No input found for flattened id [${this.id}] slot [${slot}]` + ) + + // Nothing connected + if (input.linkId == null) return + + const link = this.graph.getLink(input.linkId) + if (!link) + throw new InvalidLinkError( + `No link found in parent graph for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const { subgraphNode } = this + + // Link goes up and out of this subgraph + if (subgraphNode && link.originIsIoNode) { + const subgraphNodeInput = subgraphNode.inputs.at(link.origin_slot) + if (!subgraphNodeInput) + throw new SlotIndexError( + `No input found for slot [${link.origin_slot}] ${input.name}` + ) + + // Nothing connected + const linkId = subgraphNodeInput.link + if (linkId == null) { + const widget = subgraphNode.getWidgetFromSlot(subgraphNodeInput) + if (!widget) return + + // Special case: SubgraphNode widget. + return { + node: this, + origin_id: this.id, + origin_slot: -1, + widgetInfo: { value: widget.value } + } + } + + const outerLink = subgraphNode.graph.getLink(linkId) + if (!outerLink) + throw new InvalidLinkError( + `No outer link found for slot [${link.origin_slot}] ${input.name}` + ) + + const subgraphNodeExecutionId = this.subgraphNodePath.join(':') + const subgraphNodeDto = this.nodesByExecutionId.get( + subgraphNodeExecutionId + ) + if (!subgraphNodeDto) + throw new Error( + `No subgraph node DTO found for id [${subgraphNodeExecutionId}]` + ) + + return subgraphNodeDto.resolveInput(outerLink.target_slot, visited) + } + + // Not part of a subgraph; use the original link + const outputNode = this.graph.getNodeById(link.origin_id) + if (!outputNode) + throw new InvalidLinkError( + `No input node found for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const outputNodeExecutionId = [ + ...this.subgraphNodePath, + outputNode.id + ].join(':') + const outputNodeDto = this.nodesByExecutionId.get(outputNodeExecutionId) + if (!outputNodeDto) + throw new Error( + `No output node DTO found for id [${outputNodeExecutionId}]` + ) + + return outputNodeDto.resolveOutput( + link.origin_slot, + type ?? input.type, + visited + ) + } + + /** + * Determines whether this output is a valid endpoint for a link (non-virtual, non-bypass). + * @param slot The slot index of the output. + * @param type The type of the input + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns The node and the origin ID / slot index of the output. + */ + resolveOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[O]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving output ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + // Upstreamed: Bypass nodes are bypassed using the first input with matching type + if (this.mode === LGraphEventMode.BYPASS) { + // Bypass nodes by finding first input with matching type + const matchingIndex = this.#getBypassSlotIndex(slot, type) + + // No input types match - bypass not possible + if (matchingIndex === -1) { + console.warn( + `[ExecutableNodeDTO.resolveOutput] No input types match type [${type}] for id [${this.id}] slot [${slot}]`, + this + ) + return + } + + return this.resolveInput(matchingIndex, visited) + } + + const { node } = this + if (node.isSubgraphNode()) + return this.#resolveSubgraphOutput(slot, type, visited) + + if (node.isVirtualNode) { + const virtualLink = this.node.getInputLink(slot) + if (virtualLink) { + const { inputNode } = virtualLink.resolve(this.graph) + if (!inputNode) + throw new InvalidLinkError( + `Virtual node failed to resolve parent [${this.id}] slot [${slot}]` + ) + + const inputNodeExecutionId = [ + ...this.subgraphNodePath, + inputNode.id + ].join(':') + const inputNodeDto = this.nodesByExecutionId.get(inputNodeExecutionId) + if (!inputNodeDto) + throw new Error(`No input node DTO found for id [${inputNode.id}]`) + + return inputNodeDto.resolveInput(virtualLink.target_slot, visited, type) + } + + // Virtual nodes without a matching input should be discarded. + return + } + + return { + node: this, + origin_id: this.id, + origin_slot: slot + } + } + + /** + * Finds the index of the input slot on this node that matches the given output {@link slot} index. + * Used when bypassing nodes. + * @param slot The output slot index on this node + * @param type The type of the final target input (so type list matches are accurate) + * @returns The index of the input slot on this node, otherwise `-1`. + */ + #getBypassSlotIndex(slot: number, type: ISlotType) { + const { inputs } = this + const oppositeInput = inputs[slot] + const outputType = this.node.outputs[slot].type + + // Any type short circuit - match slot ID, fallback to first slot + if (type === '*' || type === '') { + return inputs.length > slot ? slot : 0 + } + + // Prefer input with the same slot ID + if ( + oppositeInput && + LiteGraph.isValidConnection(oppositeInput.type, outputType) && + LiteGraph.isValidConnection(oppositeInput.type, type) + ) { + return slot + } + + // Preserve legacy behaviour; use exact match first. + const exactMatch = inputs.findIndex((input) => input.type === type) + if (exactMatch !== -1) return exactMatch + + // Find first matching slot - prefer exact type + return inputs.findIndex( + (input) => + LiteGraph.isValidConnection(input.type, outputType) && + LiteGraph.isValidConnection(input.type, type) + ) + } + + /** + * Resolves the link inside a subgraph node, from the subgraph IO node to the node inside the subgraph. + * @param slot The slot index of the output on the subgraph node. + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns A DTO for the node, and the origin ID / slot index of the output. + */ + #resolveSubgraphOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const { node } = this + const output = node.outputs.at(slot) + + if (!output) + throw new SlotIndexError( + `No output found for flattened id [${this.id}] slot [${slot}]` + ) + if (!node.isSubgraphNode()) + throw new TypeError(`Node is not a subgraph node: ${node.id}`) + + // Link inside the subgraph + const innerResolved = node.resolveSubgraphOutputLink(slot) + if (!innerResolved) return + + const innerNode = innerResolved.outputNode + if (!innerNode) + throw new Error( + `No output node found for id [${this.id}] slot [${slot}] ${output.name}` + ) + + // Recurse into the subgraph + const innerNodeExecutionId = [ + ...this.subgraphNodePath, + node.id, + innerNode.id + ].join(':') + const innerNodeDto = this.nodesByExecutionId.get(innerNodeExecutionId) + if (!innerNodeDto) + throw new Error( + `No inner node DTO found for id [${innerNodeExecutionId}]` + ) + + return innerNodeDto.resolveOutput( + innerResolved.link.origin_slot, + type, + visited + ) + } +} diff --git a/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__Subgraph.ts b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__Subgraph.ts new file mode 100644 index 00000000..e1f2f0b2 --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__Subgraph.ts @@ -0,0 +1,3 @@ +// Re-export Subgraph and GraphOrSubgraph from LGraph.ts to maintain compatibility +// This is a temporary fix to resolve circular dependency issues +export { Subgraph, type GraphOrSubgraph } from '@/lib/litegraph/src/LGraph' diff --git a/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__SubgraphNode.ts b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__SubgraphNode.ts new file mode 100644 index 00000000..e26e1cd4 --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__lib__litegraph__src__subgraph__SubgraphNode.ts @@ -0,0 +1,645 @@ +import type { BaseLGraph, LGraph } from '@/lib/litegraph/src/LGraph' +import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' +import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode' +import { LLink } from '@/lib/litegraph/src/LLink' +import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import type { + ISubgraphInput, + IWidgetLocator +} from '@/lib/litegraph/src/interfaces' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { + INodeInputSlot, + ISlotType, + NodeId +} from '@/lib/litegraph/src/litegraph' +import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' +import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' +import type { + GraphOrSubgraph, + Subgraph +} from '@/lib/litegraph/src/subgraph/Subgraph' +import type { + ExportedSubgraphInstance, + ISerialisedNode +} from '@/lib/litegraph/src/types/serialisation' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' +import type { UUID } from '@/lib/litegraph/src/utils/uuid' +import { AssetWidget } from '@/lib/litegraph/src/widgets/AssetWidget' +import { toConcreteWidget } from '@/lib/litegraph/src/widgets/widgetMap' + +import { ExecutableNodeDTO } from './ExecutableNodeDTO' +import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO' +import type { SubgraphInput } from './SubgraphInput' + +const workflowSvg = new Image() +workflowSvg.src = + "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='16' height='16'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-linecap='round' stroke-width='1.3' d='M9.18613 3.09999H6.81377M9.18613 12.9H7.55288c-3.08678 0-5.35171-2.99581-4.60305-6.08843l.3054-1.26158M14.7486 2.1721l-.5931 2.45c-.132.54533-.6065.92789-1.1508.92789h-2.2993c-.77173 0-1.33797-.74895-1.1508-1.5221l.5931-2.45c.132-.54533.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.74896 1.1508 1.52211Zm-8.3033 0-.59309 2.45c-.13201.54533-.60646.92789-1.15076.92789H2.4021c-.7717 0-1.33793-.74895-1.15077-1.5221l.59309-2.45c.13201-.54533.60647-.9279 1.15077-.9279h2.29935c.77169 0 1.33792.74896 1.15076 1.52211Zm8.3033 9.8-.5931 2.45c-.132.5453-.6065.9279-1.1508.9279h-2.2993c-.77173 0-1.33797-.749-1.1508-1.5221l.5931-2.45c.132-.5453.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.7489 1.1508 1.5221Z'/%3E%3C/svg%3E %3C/svg%3E" + +/** + * An instance of a {@link Subgraph}, displayed as a node on the containing (parent) graph. + */ +export class SubgraphNode extends LGraphNode implements BaseLGraph { + declare inputs: (INodeInputSlot & Partial)[] + + override readonly type: UUID + override readonly isVirtualNode = true as const + + get rootGraph(): LGraph { + return this.graph.rootGraph + } + + override get displayType(): string { + return 'Subgraph node' + } + + override isSubgraphNode(): this is SubgraphNode { + return true + } + + override widgets: IBaseWidget[] = [] + + /** Manages lifecycle of all subgraph event listeners */ + #eventAbortController = new AbortController() + + constructor( + /** The (sub)graph that contains this subgraph instance. */ + override readonly graph: GraphOrSubgraph, + /** The definition of this subgraph; how its nodes are configured, etc. */ + readonly subgraph: Subgraph, + instanceData: ExportedSubgraphInstance + ) { + super(subgraph.name, subgraph.id) + + // Update this node when the subgraph input / output slots are changed + const subgraphEvents = this.subgraph.events + const { signal } = this.#eventAbortController + + subgraphEvents.addEventListener( + 'input-added', + (e) => { + const subgraphInput = e.detail.input + const { name, type } = subgraphInput + const existingInput = this.inputs.find((i) => i.name == name) + if (existingInput) { + const linkId = subgraphInput.linkIds[0] + const { inputNode, input } = subgraph.links[linkId].resolve(subgraph) + const widget = inputNode?.widgets?.find?.((w) => w.name == name) + if (widget) + this.#setWidget(subgraphInput, existingInput, widget, input?.widget) + return + } + const input = this.addInput(name, type) + + this.#addSubgraphInputListeners(subgraphInput, input) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-input', + (e) => { + const widget = e.detail.input._widget + if (widget) this.ensureWidgetRemoved(widget) + + this.removeInput(e.detail.index) + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'output-added', + (e) => { + const { name, type } = e.detail.output + this.addOutput(name, type) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-output', + (e) => { + this.removeOutput(e.detail.index) + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-input', + (e) => { + const { index, newName } = e.detail + const input = this.inputs.at(index) + if (!input) throw new Error('Subgraph input not found') + + input.label = newName + if (input._widget) { + input._widget.label = newName + } + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-output', + (e) => { + const { index, newName } = e.detail + const output = this.outputs.at(index) + if (!output) throw new Error('Subgraph output not found') + + output.label = newName + }, + { signal } + ) + + this.type = subgraph.id + this.configure(instanceData) + + this.addTitleButton({ + name: 'enter_subgraph', + text: '\uE93B', // Unicode for pi-window-maximize + yOffset: 0, // No vertical offset needed, button is centered + xOffset: -10, + fontSize: 16 + }) + } + + override onTitleButtonClick( + button: LGraphButton, + canvas: LGraphCanvas + ): void { + if (button.name === 'enter_subgraph') { + canvas.openSubgraph(this.subgraph, this) + } else { + super.onTitleButtonClick(button, canvas) + } + } + + #addSubgraphInputListeners( + subgraphInput: SubgraphInput, + input: INodeInputSlot & Partial + ) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + input._listenerController = new AbortController() + const { signal } = input._listenerController + + subgraphInput.events.addEventListener( + 'input-connected', + (e) => { + if (input._widget) return + + const widget = subgraphInput._widget + if (!widget) return + + const widgetLocator = e.detail.input.widget + this.#setWidget(subgraphInput, input, widget, widgetLocator) + }, + { signal } + ) + + subgraphInput.events.addEventListener( + 'input-disconnected', + () => { + // If the input is connected to more than one widget, don't remove the widget + const connectedWidgets = subgraphInput.getConnectedWidgets() + if (connectedWidgets.length > 0) return + + this.removeWidgetByName(input.name) + + delete input.pos + delete input.widget + input._widget = undefined + }, + { signal } + ) + } + + override configure(info: ExportedSubgraphInstance): void { + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + } + + this.inputs.length = 0 + this.inputs.push( + ...this.subgraph.inputNode.slots.map( + (slot) => + new NodeInputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + type: slot.type, + link: null + }, + this + ) + ) + ) + + this.outputs.length = 0 + this.outputs.push( + ...this.subgraph.outputNode.slots.map( + (slot) => + new NodeOutputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + type: slot.type, + links: null + }, + this + ) + ) + ) + + super.configure(info) + } + + override _internalConfigureAfterSlots() { + // Reset widgets + this.widgets.length = 0 + + // Check all inputs for connected widgets + for (const input of this.inputs) { + const subgraphInput = this.subgraph.inputNode.slots.find( + (slot) => slot.name === input.name + ) + if (!subgraphInput) { + // Skip inputs that don't exist in the subgraph definition + // This can happen when loading workflows with dynamically added inputs + console.warn( + `[SubgraphNode.configure] No subgraph input found for input ${input.name}, skipping` + ) + continue + } + + this.#addSubgraphInputListeners(subgraphInput, input) + + // Find the first widget that this slot is connected to + for (const linkId of subgraphInput.linkIds) { + const link = this.subgraph.getLink(linkId) + if (!link) { + console.warn( + `[SubgraphNode.configure] No link found for link ID ${linkId}`, + this + ) + continue + } + + const { inputNode } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + //Manually find input since target_slot can't be trusted + const targetInput = inputNode.inputs.find((inp) => inp.link === linkId) + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) + continue + } + + // No widget - ignore this link + const widget = inputNode.getWidgetFromSlot(targetInput) + if (!widget) continue + + this.#setWidget(subgraphInput, input, widget, targetInput.widget) + break + } + } + } + + #setWidget( + subgraphInput: Readonly, + input: INodeInputSlot, + widget: Readonly, + inputWidget: IWidgetLocator | undefined + ) { + // Use the first matching widget + const promotedWidget = toConcreteWidget(widget, this).createCopyForNode( + this + ) + if (widget instanceof AssetWidget) + promotedWidget.options.nodeType ??= widget.node.type + + Object.assign(promotedWidget, { + get name() { + return subgraphInput.name + }, + set name(value) { + console.warn( + 'Promoted widget: setting name is not allowed', + this, + value + ) + }, + get localized_name() { + return subgraphInput.localized_name + }, + set localized_name(value) { + console.warn( + 'Promoted widget: setting localized_name is not allowed', + this, + value + ) + }, + get label() { + return subgraphInput.label + }, + set label(value) { + console.warn( + 'Promoted widget: setting label is not allowed', + this, + value + ) + }, + get tooltip() { + // Preserve the original widget's tooltip for promoted widgets + return widget.tooltip + }, + set tooltip(value) { + console.warn( + 'Promoted widget: setting tooltip is not allowed', + this, + value + ) + } + }) + + const widgetCount = this.inputs.filter((i) => i.widget).length + this.widgets.splice(widgetCount, 0, promotedWidget) + + // Dispatch widget-promoted event + this.subgraph.events.dispatch('widget-promoted', { + widget: promotedWidget, + subgraphNode: this + }) + + // NOTE: This code creates linked chains of prototypes for passing across + // multiple levels of subgraphs. As part of this, it intentionally avoids + // creating new objects. Have care when making changes. + input.widget ??= { name: subgraphInput.name } + input.widget.name = subgraphInput.name + if (inputWidget) Object.setPrototypeOf(input.widget, inputWidget) + + input._widget = promotedWidget + } + + /** + * Ensures the subgraph slot is in the params before adding the input as normal. + * @param name The name of the input slot. + * @param type The type of the input slot. + * @param inputProperties Properties that are directly assigned to the created input. Default: a new, empty object. + * @returns The new input slot. + * @remarks Assertion is required to instantiate empty generic POJO. + */ + override addInput>( + name: string, + type: ISlotType, + inputProperties: TInput = {} as TInput + ): INodeInputSlot & TInput { + // Bypasses type narrowing on this.inputs + return super.addInput(name, type, inputProperties) + } + + override getInputLink(slot: number): LLink | null { + // Output side: the link from inside the subgraph + const innerLink = this.subgraph.outputNode.slots[slot].getLinks().at(0) + if (!innerLink) { + console.warn( + `SubgraphNode.getInputLink: no inner link found for slot ${slot}` + ) + return null + } + + const newLink = LLink.create(innerLink) + newLink.origin_id = `${this.id}:${innerLink.origin_id}` + newLink.origin_slot = innerLink.origin_slot + + return newLink + } + + /** + * Finds the internal links connected to the given input slot inside the subgraph, and resolves the nodes / slots. + * @param slot The slot index + * @returns The resolved connections, or undefined if no input node is found. + * @remarks This is used to resolve the input links when dragging a link from a subgraph input slot. + */ + resolveSubgraphInputLinks(slot: number): ResolvedConnection[] { + const inputSlot = this.subgraph.inputNode.slots[slot] + const innerLinks = inputSlot.getLinks() + if (innerLinks.length === 0) { + console.warn( + `[SubgraphNode.resolveSubgraphInputLinks] No inner links found for input slot [${slot}] ${inputSlot.name}`, + this + ) + return [] + } + return innerLinks.map((link) => link.resolve(this.subgraph)) + } + + /** + * Finds the internal link connected to the given output slot inside the subgraph, and resolves the nodes / slots. + * @param slot The slot index + * @returns The output node if found, otherwise undefined. + */ + resolveSubgraphOutputLink(slot: number): ResolvedConnection | undefined { + const outputSlot = this.subgraph.outputNode.slots[slot] + const innerLink = outputSlot.getLinks().at(0) + if (innerLink) { + return innerLink.resolve(this.subgraph) + } + console.warn( + `[SubgraphNode.resolveSubgraphOutputLink] No inner link found for output slot [${slot}] ${outputSlot.name}`, + this + ) + } + + /** @internal Used to flatten the subgraph before execution. */ + override getInnerNodes( + /** The set of computed node DTOs for this execution. */ + executableNodes: Map, + /** The path of subgraph node IDs. */ + subgraphNodePath: readonly NodeId[] = [], + /** Internal recursion param. The list of nodes to add to. */ + nodes: ExecutableLGraphNode[] = [], + /** Internal recursion param. The set of visited nodes. */ + visited = new Set() + ): ExecutableLGraphNode[] { + if (visited.has(this)) { + const nodeInfo = `${this.id}${this.title ? ` (${this.title})` : ''}` + const subgraphInfo = `'${this.subgraph.name || 'Unnamed Subgraph'}'` + const depth = subgraphNodePath.length + throw new RecursionError( + `Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph ${subgraphInfo}. ` + + `This creates an infinite loop in the subgraph hierarchy.` + ) + } + visited.add(this) + + const subgraphInstanceIdPath = [...subgraphNodePath, this.id] + + // Store the subgraph node DTO + const parentSubgraphNode = this.graph.rootGraph + .resolveSubgraphIdPath(subgraphNodePath) + .at(-1) + const subgraphNodeDto = new ExecutableNodeDTO( + this, + subgraphNodePath, + executableNodes, + parentSubgraphNode + ) + executableNodes.set(subgraphNodeDto.id, subgraphNodeDto) + + for (const node of this.subgraph.nodes) { + if ('getInnerNodes' in node && node.getInnerNodes) { + node.getInnerNodes( + executableNodes, + subgraphInstanceIdPath, + nodes, + new Set(visited) + ) + } else { + // Create minimal DTOs rather than cloning the node + const aVeryRealNode = new ExecutableNodeDTO( + node, + subgraphInstanceIdPath, + executableNodes, + this + ) + executableNodes.set(aVeryRealNode.id, aVeryRealNode) + nodes.push(aVeryRealNode) + } + } + return nodes + } + + override removeWidgetByName(name: string): void { + const widget = this.widgets.find((w) => w.name === name) + if (widget) { + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + super.removeWidgetByName(name) + } + + override ensureWidgetRemoved(widget: IBaseWidget): void { + if (this.widgets.includes(widget)) { + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + super.ensureWidgetRemoved(widget) + } + + override onRemoved(): void { + // Clean up all subgraph event listeners + this.#eventAbortController.abort() + + // Clean up all promoted widgets + for (const widget of this.widgets) { + if ('isProxyWidget' in widget && widget.isProxyWidget) continue + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + } + } + override drawTitleBox( + ctx: CanvasRenderingContext2D, + { + scale, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + box_size = 10 + }: DrawTitleBoxOptions + ): void { + if (this.onDrawTitleBox) { + this.onDrawTitleBox(ctx, title_height, this.renderingSize, scale) + return + } + ctx.save() + ctx.fillStyle = '#3b82f6' + ctx.beginPath() + ctx.roundRect(6, -24.5, 22, 20, 5) + ctx.fill() + if (!low_quality) { + ctx.translate(25, 23) + ctx.scale(-1.5, 1.5) + ctx.drawImage(workflowSvg, 0, -title_height, box_size, box_size) + } + ctx.restore() + } + + /** + * Synchronizes widget values from this SubgraphNode instance to the + * corresponding widgets in the subgraph definition before serialization. + * This ensures nested subgraph widget values are preserved when saving. + */ + override serialize(): ISerialisedNode { + // Sync widget values to subgraph definition before serialization + for (let i = 0; i < this.widgets.length; i++) { + const widget = this.widgets[i] + const input = this.inputs.find((inp) => inp.name === widget.name) + + if (input) { + const subgraphInput = this.subgraph.inputNode.slots.find( + (slot) => slot.name === input.name + ) + + if (subgraphInput) { + // Find all widgets connected to this subgraph input + const connectedWidgets = subgraphInput.getConnectedWidgets() + + // Update the value of all connected widgets + for (const connectedWidget of connectedWidgets) { + connectedWidget.value = widget.value + } + } + } + } + + // Call parent serialize method + return super.serialize() + } + override clone() { + const clone = super.clone() + // force reasign so domWidgets reset ownership + + this.properties.proxyWidgets = this.properties.proxyWidgets + + //TODO: Consider deep cloning subgraphs here. + //It's the safest place to prevent creation of linked subgraphs + //But the frequency of clone().serialize() calls is likely to result in + //pollution of rootGraph.subgraphs + + return clone + } +} diff --git a/docs/hel-892/structure-reference/1.37.11__src__utils__executionUtil.ts b/docs/hel-892/structure-reference/1.37.11__src__utils__executionUtil.ts new file mode 100644 index 00000000..3f7f982c --- /dev/null +++ b/docs/hel-892/structure-reference/1.37.11__src__utils__executionUtil.ts @@ -0,0 +1,150 @@ +import type { + ExecutableLGraphNode, + ExecutionId, + LGraph +} from '@/lib/litegraph/src/litegraph' +import { + ExecutableNodeDTO, + LGraphEventMode +} from '@/lib/litegraph/src/litegraph' +import type { + ComfyApiWorkflow, + ComfyWorkflowJSON +} from '@/platform/workflow/validation/schemas/workflowSchema' + +import { ExecutableGroupNodeDTO, isGroupNode } from './executableGroupNodeDto' +import { compressWidgetInputSlots } from './litegraphUtil' + +/** + * Converts the current graph workflow for sending to the API. + * @note Node widgets are updated before serialization to prepare queueing. + * + * @param graph The graph to convert. + * @param options The options for the conversion. + * - `sortNodes`: Whether to sort the nodes by execution order. + * @returns The workflow and node links + */ +export const graphToPrompt = async ( + graph: LGraph, + options: { sortNodes?: boolean } = {} +): Promise<{ workflow: ComfyWorkflowJSON; output: ComfyApiWorkflow }> => { + const { sortNodes = false } = options + + for (const node of graph.computeExecutionOrder(false)) { + const innerNodes = node.getInnerNodes + ? node.getInnerNodes(new Map()) + : [node] + for (const innerNode of innerNodes) { + if (innerNode.isVirtualNode) { + innerNode.applyToGraph?.() + } + } + } + + const workflow = graph.serialize({ sortNodes }) + + // Remove localized_name from the workflow + for (const node of workflow.nodes) { + for (const slot of node.inputs ?? []) { + delete slot.localized_name + } + for (const slot of node.outputs ?? []) { + delete slot.localized_name + } + } + + compressWidgetInputSlots(workflow) + workflow.extra ??= {} + workflow.extra.frontendVersion = __COMFYUI_FRONTEND_VERSION__ + + const nodeDtoMap = new Map() + for (const node of graph.computeExecutionOrder(false)) { + const dto: ExecutableLGraphNode = isGroupNode(node) + ? new ExecutableGroupNodeDTO(node, [], nodeDtoMap) + : new ExecutableNodeDTO(node, [], nodeDtoMap) + + for (const innerNode of dto.getInnerNodes()) { + nodeDtoMap.set(innerNode.id, innerNode) + } + + nodeDtoMap.set(dto.id, dto) + } + + const output: ComfyApiWorkflow = {} + // Process nodes in order of execution + for (const node of nodeDtoMap.values()) { + // Don't serialize muted nodes + if ( + node.isVirtualNode || + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + const inputs: ComfyApiWorkflow[string]['inputs'] = {} + const { widgets } = node + + // Store all widget values + if (widgets) { + for (const [i, widget] of widgets.entries()) { + if (!widget.name || widget.options?.serialize === false) continue + + const widgetValue = widget.serializeValue + ? await widget.serializeValue(node, i) + : widget.value + // By default, Array values are reserved to represent node connections. + // We need to wrap the array as an object to avoid the misinterpretation + // of the array as a node connection. + // The backend automatically unwraps the object to an array during + // execution. + inputs[widget.name] = Array.isArray(widgetValue) + ? { + __value__: widgetValue + } + : widgetValue + } + } + + // Store all node links + for (const [i, input] of node.inputs.entries()) { + const resolvedInput = node.resolveInput(i) + if (!resolvedInput) continue + + // Resolved to an actual widget value rather than a node connection + if (resolvedInput.widgetInfo) { + const { value } = resolvedInput.widgetInfo + inputs[input.name] = Array.isArray(value) ? { __value__: value } : value + continue + } + + inputs[input.name] = [ + String(resolvedInput.origin_id), + // @ts-expect-error link.origin_slot is already number. + parseInt(resolvedInput.origin_slot) + ] + } + + output[String(node.id)] = { + inputs, + // TODO(huchenlei): Filter out all nodes that cannot be mapped to a + // comfyClass. + class_type: node.comfyClass!, + // Ignored by the backend. + _meta: { + title: node.title + } + } + } + + // Remove inputs connected to removed nodes + for (const { inputs } of Object.values(output)) { + for (const [i, input] of Object.entries(inputs)) { + if (Array.isArray(input) && input.length === 2 && !output[input[0]]) { + delete inputs[i] + } + } + } + + return { workflow: workflow as ComfyWorkflowJSON, output } +} diff --git a/docs/hel-892/structure-reference/1.48.6__LICENSE b/docs/hel-892/structure-reference/1.48.6__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/1.48.6__src__extensions__core__widgetInputs.ts b/docs/hel-892/structure-reference/1.48.6__src__extensions__core__widgetInputs.ts new file mode 100644 index 00000000..3c2ac3a6 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__extensions__core__widgetInputs.ts @@ -0,0 +1,617 @@ +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LLink +} from '@/lib/litegraph/src/litegraph' +import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' +import type { + IBaseWidget, + TWidgetValue +} from '@/lib/litegraph/src/types/widgets' +import { assetService } from '@/platform/assets/services/assetService' +import { createAssetWidget } from '@/platform/assets/utils/createAssetWidget' +import type { ComfyNodeDef, InputSpec } from '@/schemas/nodeDefSchema' +import { app } from '@/scripts/app' +import { + ComfyWidgets, + addValueControlWidgets, + isValidWidgetType +} from '@/scripts/widgets' +import { isPrimitiveNode } from '@/renderer/utils/nodeTypeGuards' +import { CONFIG, GET_CONFIG } from '@/services/litegraphService' +import { mergeInputSpec } from '@/utils/nodeDefUtil' +import { applyTextReplacements } from '@/utils/searchAndReplace' + +import { applyFirstWidgetValueToGraph } from './widgetValuePropagation' + +const replacePropertyName = 'Run widget replace on values' +export class PrimitiveNode extends LGraphNode { + controlValues?: TWidgetValue[] + lastType?: string + static override category: string + constructor(title: string) { + super(title) + this.addOutput('connect to widget input', '*') + this.serialize_widgets = true + this.isVirtualNode = true + + if (!this.properties || !(replacePropertyName in this.properties)) { + this.addProperty(replacePropertyName, false, 'boolean') + } + } + + override applyToGraph(extraLinks: LLink[] = []) { + const sourceWidget = this.widgets?.[0] + const graph = this.graph + if (!sourceWidget || !graph) return + + let v = sourceWidget.value + if (v && this.properties[replacePropertyName]) { + v = applyTextReplacements(graph, v as string) + } + applyFirstWidgetValueToGraph(this, extraLinks, () => v) + } + + override refreshComboInNode() { + const widget = this.widgets?.[0] + if (widget?.type === 'combo') { + // @ts-expect-error fixme ts strict error + widget.options.values = this.outputs[0].widget[GET_CONFIG]()[0] + + // @ts-expect-error fixme ts strict error + if (!widget.options.values.includes(widget.value as string)) { + // @ts-expect-error fixme ts strict error + widget.value = widget.options.values[0] + widget.callback?.(widget.value) + } + } + } + + override onAfterGraphConfigured() { + if (this.outputs[0].links?.length && !this.widgets?.length) { + this._onFirstConnection() + + // Populate widget values from config data + if (this.widgets && this.widgets_values) { + for (let i = 0; i < this.widgets_values.length; i++) { + const w = this.widgets[i] + if (w) { + w.value = this.widgets_values[i] + } + } + } + + // Merge values if required + this._mergeWidgetConfig() + } + } + + override onConnectionsChange( + _type: ISlotType, + _index: number, + connected: boolean + ) { + if (app.configuringGraph) { + // Dont run while the graph is still setting up + return + } + + const links = this.outputs[0].links + if (connected) { + if (links?.length && !this.widgets?.length) { + this._onFirstConnection() + } + } else { + // We may have removed a link that caused the constraints to change + this._mergeWidgetConfig() + + if (!links?.length) { + this.onLastDisconnect() + } + } + } + + override onConnectOutput( + slot: number, + _type: string, + input: INodeInputSlot, + target_node: LGraphNode, + target_slot: number + ) { + // Fires before the link is made allowing us to reject it if it isn't valid + // No widget, we can't connect + if (!input.widget && !(input.type in ComfyWidgets)) { + return false + } + + if (this.outputs[slot].links?.length) { + const valid = this._isValidConnection(input) + if (valid) { + // On connect of additional outputs, copy our value to their widget + this.applyToGraph([{ target_id: target_node.id, target_slot } as LLink]) + } + return valid + } + + return true + } + + private _onFirstConnection(recreating?: boolean) { + // First connection can fire before the graph is ready on initial load so random things can be missing + if (!this.outputs[0].links || !this.graph) { + this.onLastDisconnect() + return + } + const linkId = this.outputs[0].links[0] + const link = this.graph.links[linkId] + if (!link) return + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode || !theirNode.inputs) return + + const input = theirNode.inputs[link.target_slot] + if (!input) return + + let widget + if (!input.widget) { + if (!(input.type in ComfyWidgets)) return + widget = { name: input.name, [GET_CONFIG]: () => [input.type, {}] } //fake widget + } else { + widget = input.widget + } + + // @ts-expect-error fixme ts strict error + const config = widget[GET_CONFIG]?.() + if (!config) return + + const { type } = getWidgetType(config) + // Update our output to restrict to the widget type + this.outputs[0].type = type + this.outputs[0].name = type + this.outputs[0].widget = widget + + this._createWidget( + widget[CONFIG] ?? config, + theirNode, + widget.name, + // @ts-expect-error fixme ts strict error + recreating + ) + } + + private _createWidget( + inputData: InputSpec, + node: LGraphNode, + widgetName: string, + recreating: boolean + ) { + let type = inputData[0] + + if (type instanceof Array) { + type = 'COMBO' + } + + // Store current size as addWidget resizes the node + const [oldWidth, oldHeight] = this.size + let widget: IBaseWidget + + if ( + type === 'COMBO' && + assetService.shouldUseAssetBrowser(node.comfyClass, widgetName) + ) { + widget = this._createAssetWidget(node, widgetName, inputData) + const theirWidget = node.widgets?.find((w) => w.name === widgetName) + if (theirWidget) widget.value = theirWidget.value + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + return + } + + if (isValidWidgetType(type)) { + widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}).widget + } else { + // @ts-expect-error InputSpec is not typed correctly + widget = this.addWidget(type, 'value', null, () => {}, {}) + } + + if (node?.widgets && widget) { + const theirWidget = node.widgets.find((w) => w.name === widgetName) + if (theirWidget) { + widget.value = theirWidget.value + } + } + + if ( + !inputData?.[1]?.control_after_generate && + (widget.type === 'number' || widget.type === 'combo') + ) { + let control_value = this.widgets_values?.[1] + if (!control_value) { + control_value = 'fixed' + } + addValueControlWidgets( + this, + widget, + control_value as string, + undefined, + inputData + ) + if (this.widgets?.[1]) widget.linkedWidgets = [this.widgets[1]] + + const filter = this.widgets_values?.[2] + if (filter && this.widgets && this.widgets.length === 3) { + this.widgets[2].value = filter + } + } + + // Restore any saved control values + const controlValues = this.controlValues + if ( + this.widgets && + this.lastType === this.widgets[0]?.type && + controlValues?.length === this.widgets.length - 1 + ) { + for (let i = 0; i < controlValues.length; i++) { + this.widgets[i + 1].value = controlValues[i] + } + } + + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + } + + private _createAssetWidget( + targetNode: LGraphNode, + targetInputName: string, + inputData: InputSpec + ): IBaseWidget { + const defaultValue = inputData[1]?.default as string | undefined + return createAssetWidget({ + node: this, + widgetName: 'value', + nodeTypeForBrowser: targetNode.comfyClass ?? '', + inputNameForBrowser: targetInputName, + defaultValue + }) + } + + private _finalizeWidget( + widget: IBaseWidget, + oldWidth: number, + oldHeight: number, + recreating: boolean + ) { + widget.callback = useChainCallback(widget.callback, () => { + this.applyToGraph() + }) + + this.setSize([ + Math.max(this.size[0], oldWidth), + Math.max(this.size[1], oldHeight) + ]) + + if (!recreating) { + const sz = this.computeSize() + if (this.size[0] < sz[0]) { + this.size[0] = sz[0] + } + if (this.size[1] < sz[1]) { + this.size[1] = sz[1] + } + + requestAnimationFrame(() => { + this.onResize?.(this.size) + }) + } + } + + recreateWidget() { + const values = this.widgets?.map((w) => w.value) + this._removeWidgets() + this._onFirstConnection(true) + if (values?.length && this.widgets) { + for (let i = 0; i < this.widgets.length; i++) + this.widgets[i].value = values[i] + } + return this.widgets?.[0] + } + + private _mergeWidgetConfig() { + // Merge widget configs if the node has multiple outputs + const output = this.outputs[0] + const links = output.links ?? [] + + const hasConfig = !!output.widget?.[CONFIG] + if (hasConfig) { + delete output.widget?.[CONFIG] + } + + if (links?.length < 2 && hasConfig) { + // Copy the widget options from the source + if (links.length) { + this.recreateWidget() + } + + return + } + const config1 = (output.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config1) return + const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT' + if (!isNumber || !this.graph) return + + for (const linkId of links) { + const link = this.graph.links[linkId] + if (!link) continue // Can be null when removing a node + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode) continue + const theirInput = theirNode.inputs[link.target_slot] + + // Call is valid connection so it can merge the configs when validating + this._isValidConnection(theirInput, hasConfig) + } + } + + private _isValidConnection(input: INodeInputSlot, forceUpdate?: boolean) { + // Only allow connections where the configs match + const output = this.outputs?.[0] + const config2 = (input.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config2) return false + + return !!mergeIfValid.call( + this, + output, + config2, + forceUpdate, + this.recreateWidget + ) + } + + private _removeWidgets() { + if (this.widgets) { + // Allow widgets to cleanup + for (const w of this.widgets) { + if (w.onRemove) { + w.onRemove() + } + } + + // Temporarily store the current values in case the node is being recreated + this.controlValues = [] + this.lastType = this.widgets[0]?.type + for (let i = 1; i < this.widgets.length; i++) { + this.controlValues.push(this.widgets[i].value) + } + setTimeout(() => { + delete this.lastType + delete this.controlValues + }, 15) + this.widgets.length = 0 + } + } + + onLastDisconnect() { + // We can't remove + re-add the output here as if you drag a link over the same link + // it removes, then re-adds, causing it to break + this.outputs[0].type = '*' + this.outputs[0].name = 'connect to widget input' + delete this.outputs[0].widget + + this._removeWidgets() + } +} + +export function getWidgetConfig( + slot: INodeInputSlot | INodeOutputSlot +): InputSpec { + return (slot.widget?.[CONFIG] ?? + (slot.widget?.[GET_CONFIG] as () => InputSpec)?.() ?? [ + '*', + {} + ]) as InputSpec +} + +function getConfig(this: LGraphNode, widgetName: string) { + const { nodeData } = this.constructor + return ( + nodeData?.input?.required?.[widgetName] ?? + nodeData?.input?.optional?.[widgetName] + ) +} + +/** + * Convert a widget to an input slot. + * @deprecated Widget to socket conversion is no longer necessary, as they co-exist now. + * @param node The node to convert the widget to an input slot for. + * @param widget The widget to convert to an input slot. + * @returns The input slot that was converted from the widget or undefined if the widget is not found. + * @knipIgnoreUnusedButUsedByCustomNodes + */ +export function convertToInput( + node: LGraphNode, + widget: IBaseWidget +): INodeInputSlot | undefined { + console.warn( + 'Please remove call to convertToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return node.inputs.find((slot) => slot.widget?.name === widget.name) +} + +function getWidgetType(config: InputSpec) { + // Special handling for COMBO so we restrict links based on the entries + let type = config[0] + if (type instanceof Array) { + type = 'COMBO' + } + return { type } +} + +export function setWidgetConfig(slot: INodeInputSlot, config?: InputSpec) { + if (!slot.widget) return + if (config) { + slot.widget[GET_CONFIG] = () => config + } else { + delete slot.widget + } + + if (!(slot instanceof NodeSlot)) return + const graph = slot.node.graph + if (!graph) return + const link = graph.getLink(slot.link) + if (!link) return + const originNode = graph.getNodeById(link.origin_id) + if (!originNode || !isPrimitiveNode(originNode)) return + if (config) { + originNode.recreateWidget() + } else if (!app.configuringGraph) { + originNode.disconnectOutput(0) + originNode.onLastDisconnect() + } +} + +export function mergeIfValid( + output: INodeOutputSlot | INodeInputSlot, + config2: InputSpec, + forceUpdate?: boolean, + recreateWidget?: () => void, + config1?: InputSpec +): { customConfig: InputSpec[1] } { + if (!config1) { + config1 = getWidgetConfig(output) + } + + const customSpec = mergeInputSpec(config1, config2) + + if (customSpec || forceUpdate) { + if (customSpec) { + // @ts-expect-error fixme ts strict error + output.widget[CONFIG] = customSpec + } + + // @ts-expect-error fixme ts strict error + const widget = recreateWidget?.call(this) + // When deleting a node this can be null + if (widget) { + // @ts-expect-error fixme ts strict error + const min = widget.options.min + // @ts-expect-error fixme ts strict error + const max = widget.options.max + // @ts-expect-error fixme ts strict error + if (min != null && widget.value < min) widget.value = min + // @ts-expect-error fixme ts strict error + if (max != null && widget.value > max) widget.value = max + // @ts-expect-error fixme ts strict error + widget.callback(widget.value) + } + } + + return { customConfig: customSpec?.[1] ?? {} } +} + +app.registerExtension({ + name: 'Comfy.WidgetInputs', + async beforeRegisterNodeDef( + nodeType: typeof LGraphNode, + _nodeData: ComfyNodeDef + ) { + // @ts-expect-error adding extra property + nodeType.prototype.convertWidgetToInput = function (this: LGraphNode) { + console.warn( + 'Please remove call to convertWidgetToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return false + } + + nodeType.prototype.onGraphConfigured = useChainCallback( + nodeType.prototype.onGraphConfigured, + function (this: LGraphNode) { + if (!this.inputs) return + this.widgets ??= [] + + for (const input of this.inputs) { + if (input.widget) { + const name = input.widget.name + if (!input.widget[GET_CONFIG]) { + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + + const w = this.widgets?.find((w) => w.name === name) + if (!w) { + this.removeInput(this.inputs.findIndex((i) => i === input)) + } + } + } + } + ) + + nodeType.prototype.onConfigure = useChainCallback( + nodeType.prototype.onConfigure, + function (this: LGraphNode) { + if (!app.configuringGraph && this.inputs) { + // On copy + paste of nodes, ensure that widget configs are set up + for (const input of this.inputs) { + if (input.widget && !input.widget[GET_CONFIG]) { + const name = input.widget.name + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + } + } + } + ) + + // Double click a widget input to automatically attach a primitive + const origOnInputDblClick = nodeType.prototype.onInputDblClick + nodeType.prototype.onInputDblClick = function ( + this: LGraphNode, + ...[slot, ...args]: Parameters> + ) { + const r = origOnInputDblClick?.apply(this, [slot, ...args]) + + const input = this.inputs[slot] + if (!input.widget) { + // Not a widget input or already handled input + if ( + !(input.type in ComfyWidgets) && + !( + ( + input.widget?.[GET_CONFIG] as (() => InputSpec) | undefined + )?.()?.[0] instanceof Array + ) + ) { + return r //also Not a ComfyWidgets input or combo (do nothing) + } + } + + // Create a primitive node + const node = LiteGraph.createNode('PrimitiveNode') + const graph = app.canvas.graph + if (!node || !graph) return r + + graph?.add(node) + + // Calculate a position that won't directly overlap another node + const pos: [number, number] = [ + this.pos[0] - node.size[0] - 30, + this.pos[1] + ] + while (graph.getNodeOnPos(pos[0], pos[1], graph.nodes)) + pos[1] += LiteGraph.NODE_TITLE_HEIGHT + + node.pos = pos + node.connect(0, this, slot) + node.title = input.name + + return r + } + }, + registerCustomNodes() { + LiteGraph.registerNodeType( + 'PrimitiveNode', + Object.assign(PrimitiveNode, { + title: 'Primitive' + }) + ) + PrimitiveNode.category = 'utilities/primitive' + } +}) diff --git a/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__LLink.ts b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__LLink.ts new file mode 100644 index 00000000..78e86137 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__LLink.ts @@ -0,0 +1,507 @@ +import { + SUBGRAPH_INPUT_ID, + SUBGRAPH_OUTPUT_ID +} from '@/lib/litegraph/src/constants' +import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations' +import { LayoutSource } from '@/renderer/core/layout/types' +import { toLinkId } from '@/types/linkId' +import { UNASSIGNED_NODE_ID, toNodeId, serializeNodeId } from '@/types/nodeId' +import { toRerouteId } from '@/types/rerouteId' + +import type { LinkId } from '@/types/linkId' +import type { RerouteId } from '@/types/rerouteId' +import type { LGraphNode } from './LGraphNode' +import type { NodeId, SerializedNodeId } from '@/types/nodeId' +import type { Reroute } from './Reroute' +import type { + CanvasColour, + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LinkNetwork, + LinkSegment, + Point, + ReadonlyLinkNetwork +} from './interfaces' +import type { Serialisable, SerialisableLLink } from './types/serialisation' + +const layoutMutations = useLayoutMutations() + +export type { LinkId } from '@/types/linkId' +export type SerialisedLLinkArray = [ + id: number, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + type: ISlotType +] + +// Resolved connection union; eliminates subgraph in/out as a possibility +export type ResolvedConnection = BaseResolvedConnection & + ( + | (ResolvedSubgraphInput & ResolvedNormalOutput) + | (ResolvedNormalInput & ResolvedSubgraphOutput) + | (ResolvedNormalInput & ResolvedNormalOutput) + ) + +interface BaseResolvedConnection { + link: LLink + /** The node on the input side of the link (owns {@link input}) */ + inputNode?: LGraphNode + /** The input the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: INodeInputSlot + /** The node on the output side of the link (owns {@link output}) */ + outputNode?: LGraphNode + /** The output the link is connected to (mutually exclusive with {@link subgraphInput}) */ + output?: INodeOutputSlot + /** The subgraph output the link is connected to (mutually exclusive with {@link input}) */ + subgraphOutput?: SubgraphOutput + /** The subgraph input the link is connected to (mutually exclusive with {@link output}) */ + subgraphInput?: SubgraphInput +} + +interface ResolvedNormalInput { + inputNode: LGraphNode | undefined + input: INodeInputSlot | undefined + subgraphOutput?: undefined +} + +interface ResolvedNormalOutput { + outputNode: LGraphNode | undefined + output: INodeOutputSlot | undefined + subgraphInput?: undefined +} + +interface ResolvedSubgraphInput { + inputNode?: undefined + /** The actual input slot the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: undefined + subgraphOutput: SubgraphOutput +} + +interface ResolvedSubgraphOutput { + outputNode?: undefined + output?: undefined + subgraphInput: SubgraphInput +} + +type BasicReadonlyNetwork = Pick< + ReadonlyLinkNetwork, + 'getNodeById' | 'links' | 'getLink' | 'inputNode' | 'outputNode' +> + +// this is the class in charge of storing link information +export class LLink implements LinkSegment, Serialisable { + static _drawDebug = false + + /** Link ID */ + id: LinkId + parentId?: RerouteId + type: ISlotType + /** Output node ID */ + origin_id: NodeId + /** Output slot index */ + origin_slot: number + /** Input node ID */ + target_id: NodeId + /** Input slot index */ + target_slot: number + + data?: number | string | boolean | { toToolTip?(): string } + _data?: unknown + /** Centre point of the link, calculated during render only - can be inaccurate */ + _pos: Point + /** @todo Clean up - never implemented in comfy. */ + _last_time?: number + /** The last canvas 2D path that was used to render this link */ + path?: Path2D + /** @inheritdoc */ + _centreAngle?: number + + /** @inheritdoc */ + _dragging?: boolean + + private _color?: CanvasColour | null + /** Custom colour for this link only */ + public get color(): CanvasColour | null | undefined { + return this._color + } + + public set color(value: CanvasColour) { + this._color = value === '' ? null : value + } + + public get isFloatingOutput(): boolean { + return this.origin_id === UNASSIGNED_NODE_ID && this.origin_slot === -1 + } + + public get isFloatingInput(): boolean { + return this.target_id === UNASSIGNED_NODE_ID && this.target_slot === -1 + } + + public get isFloating(): boolean { + return this.isFloatingOutput || this.isFloatingInput + } + + /** `true` if this link is connected to a subgraph input node (the actual origin is in a different graph). */ + get originIsIoNode(): boolean { + return this.origin_id === SUBGRAPH_INPUT_ID + } + + /** `true` if this link is connected to a subgraph output node (the actual target is in a different graph). */ + get targetIsIoNode(): boolean { + return this.target_id === SUBGRAPH_OUTPUT_ID + } + + constructor( + id: LinkId, + type: ISlotType, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + parentId?: RerouteId + ) { + this.id = id + this.type = type + this.origin_id = toNodeId(origin_id) + this.origin_slot = origin_slot + this.target_id = toNodeId(target_id) + this.target_slot = target_slot + this.parentId = parentId + + this._data = null + // center + this._pos = [0, 0] + } + + /** @deprecated Use {@link LLink.create} */ + static createFromArray(data: SerialisedLLinkArray): LLink { + return new LLink( + toLinkId(data[0]), + data[5], + data[1], + data[2], + data[3], + data[4] + ) + } + + /** + * LLink static factory: creates a new LLink from the provided data. + * @param data Serialised LLink data to create the link from + * @returns A new LLink + */ + static create(data: SerialisableLLink): LLink { + return new LLink( + toLinkId(data.id), + data.type, + data.origin_id, + data.origin_slot, + data.target_id, + data.target_slot, + data.parentId === undefined ? undefined : toRerouteId(data.parentId) + ) + } + + /** + * Gets all reroutes from the output slot to this segment. If this segment is a reroute, it will not be included. + * @returns An ordered array of all reroutes from the node output to + * this reroute or the reroute before it. Otherwise, an empty array. + */ + static getReroutes( + network: Pick, + linkSegment: LinkSegment + ): Reroute[] { + if (linkSegment.parentId === undefined) return [] + return network.reroutes.get(linkSegment.parentId)?.getReroutes() ?? [] + } + + static getFirstReroute( + network: Pick, + linkSegment: LinkSegment + ): Reroute | undefined { + return LLink.getReroutes(network, linkSegment).at(0) + } + + /** + * Finds the reroute in the chain after the provided reroute ID. + * @param network The network this link belongs to + * @param linkSegment The starting point of the search (input side). + * Typically the LLink object itself, but can be any link segment. + * @param rerouteId The matching reroute will have this set as its {@link parentId}. + * @returns The reroute that was found, `undefined` if no reroute was found, or `null` if an infinite loop was detected. + */ + static findNextReroute( + network: Pick, + linkSegment: LinkSegment, + rerouteId: RerouteId + ): Reroute | null | undefined { + if (linkSegment.parentId === undefined) return + return network.reroutes + .get(linkSegment.parentId) + ?.findNextReroute(rerouteId) + } + + /** + * Gets the origin node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the origin node of + * @returns The origin node of the link, or `undefined` if the link is not found or the origin node is not found + */ + static getOriginNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.origin_id + return network.getNodeById(id) ?? undefined + } + + /** + * Gets the target node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the target node of + * @returns The target node of the link, or `undefined` if the link is not found or the target node is not found + */ + static getTargetNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.target_id + return network.getNodeById(id) ?? undefined + } + + /** + * Resolves a link ID to the link, node, and slot objects. + * @param linkId The {@link id} of the link to resolve + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + static resolve( + linkId: LinkId | null | undefined, + network: BasicReadonlyNetwork + ): ResolvedConnection | undefined { + return network.getLink(linkId)?.resolve(network) + } + + /** + * Resolves a list of link IDs to the link, node, and slot objects. + * Discards invalid link IDs. + * @param linkIds An iterable of link {@link id}s to resolve + * @param network The link network to search + * @returns An array of resolved connections. If a link is not found, it is not included in the array. + * @see {@link LLink.resolve} + */ + static resolveMany( + linkIds: Iterable, + network: BasicReadonlyNetwork + ): ResolvedConnection[] { + const resolved: ResolvedConnection[] = [] + for (const id of linkIds) { + const r = network.getLink(id)?.resolve(network) + if (r) resolved.push(r) + } + return resolved + } + + /** + * Resolves the primitive ID values stored in the link to the referenced objects. + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + resolve(network: BasicReadonlyNetwork): ResolvedConnection { + const inputNode = + this.target_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.target_id) ?? undefined) + const input = inputNode?.inputs[this.target_slot] + const subgraphInput = this.originIsIoNode + ? network.inputNode?.slots[this.origin_slot] + : undefined + if (subgraphInput) { + return { inputNode, input, subgraphInput, link: this } + } + + const outputNode = + this.origin_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.origin_id) ?? undefined) + const output = outputNode?.outputs[this.origin_slot] + const subgraphOutput = this.targetIsIoNode + ? network.outputNode?.slots[this.target_slot] + : undefined + if (subgraphOutput) { + return { + outputNode, + output, + subgraphInput: undefined, + subgraphOutput, + link: this + } + } + + return { + inputNode, + outputNode, + input, + output, + subgraphInput, + subgraphOutput, + link: this + } + } + + configure(o: LLink | SerialisedLLinkArray) { + if (Array.isArray(o)) { + this.id = toLinkId(o[0]) + this.origin_id = toNodeId(o[1]) + this.origin_slot = o[2] + this.target_id = toNodeId(o[3]) + this.target_slot = o[4] + this.type = o[5] + } else { + this.id = o.id + this.type = o.type + this.origin_id = o.origin_id + this.origin_slot = o.origin_slot + this.target_id = o.target_id + this.target_slot = o.target_slot + this.parentId = o.parentId + } + } + + /** + * Checks if the specified node id and output index are this link's origin (output side). + * @param nodeId ID of the node to check + * @param outputIndex The array index of the node output + * @returns `true` if the origin matches, otherwise `false`. + */ + hasOrigin(nodeId: SerializedNodeId, outputIndex: number): boolean { + return ( + this.origin_id === toNodeId(nodeId) && this.origin_slot === outputIndex + ) + } + + /** + * Checks if the specified node id and input index are this link's target (input side). + * @param nodeId ID of the node to check + * @param inputIndex The array index of the node input + * @returns `true` if the target matches, otherwise `false`. + */ + hasTarget(nodeId: SerializedNodeId, inputIndex: number): boolean { + return ( + this.target_id === toNodeId(nodeId) && this.target_slot === inputIndex + ) + } + + /** + * Creates a floating link from this link. + * @param slotType The side of the link that is still connected + * @param parentId The parent reroute ID of the link + * @returns A new LLink that is floating + */ + toFloating(slotType: 'input' | 'output', parentId: RerouteId): LLink { + const exported = this.asSerialisable() + exported.id = toLinkId(-1) + exported.parentId = parentId + + if (slotType === 'input') { + exported.origin_id = UNASSIGNED_NODE_ID + exported.origin_slot = -1 + } else { + exported.target_id = UNASSIGNED_NODE_ID + exported.target_slot = -1 + } + + return LLink.create(exported) + } + + /** + * Disconnects a link and removes it from the graph, cleaning up any reroutes that are no longer used + * @param network The container (LGraph) where reroutes should be updated + * @param keepReroutes If `undefined`, reroutes will be automatically removed if no links remain. + * If `input` or `output`, reroutes will not be automatically removed, and retain a connection to the input or output, respectively. + */ + disconnect(network: LinkNetwork, keepReroutes?: 'input' | 'output'): void { + const reroutes = LLink.getReroutes(network, this) + + const lastReroute = reroutes.at(-1) + + // When floating from output, 1-to-1 ratio of floating link to final reroute (tree-like) + const outputFloating = + keepReroutes === 'output' && + lastReroute?.linkIds.size === 1 && + lastReroute.floatingLinkIds.size === 0 + + // When floating from inputs, the final (input side) reroute may have many floating links + if (outputFloating || (keepReroutes === 'input' && lastReroute)) { + const newLink = LLink.create(this) + newLink.id = toLinkId(-1) + + if (keepReroutes === 'input') { + newLink.origin_id = UNASSIGNED_NODE_ID + newLink.origin_slot = -1 + + lastReroute.floating = { slotType: 'input' } + } else { + newLink.target_id = UNASSIGNED_NODE_ID + newLink.target_slot = -1 + + lastReroute.floating = { slotType: 'output' } + } + + network.addFloatingLink(newLink) + } + + for (const reroute of reroutes) { + reroute.linkIds.delete(this.id) + if (!keepReroutes && !reroute.totalLinks) { + network.reroutes.delete(reroute.id) + // Delete reroute from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteReroute(reroute.id) + } + } + network.links.delete(this.id) + // Delete link from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteLink(this.id) + } + + /** + * @deprecated Prefer {@link LLink.asSerialisable} (returns an object, not an array) + * @returns An array representing this LLink + */ + serialize(): SerialisedLLinkArray { + return [ + this.id, + serializeNodeId(this.origin_id), + this.origin_slot, + serializeNodeId(this.target_id), + this.target_slot, + this.type + ] + } + + asSerialisable(): SerialisableLLink { + const copy: SerialisableLLink = { + id: this.id, + origin_id: serializeNodeId(this.origin_id), + origin_slot: this.origin_slot, + target_id: serializeNodeId(this.target_id), + target_slot: this.target_slot, + type: this.type + } + if (this.parentId !== undefined) copy.parentId = this.parentId + return copy + } +} diff --git a/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts new file mode 100644 index 00000000..35220e8b --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts @@ -0,0 +1,429 @@ +import { toLinkId } from '@/types/linkId' +import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { SerializedNodeId } from '@/types/nodeId' +import type { LinkId } from '@/lib/litegraph/src/LLink' +import { InvalidLinkError } from '@/lib/litegraph/src/infrastructure/InvalidLinkError' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import { SlotIndexError } from '@/lib/litegraph/src/infrastructure/SlotIndexError' +import type { ISlotType } from '@/lib/litegraph/src/interfaces' +import { LGraphEventMode, LiteGraph } from '@/lib/litegraph/src/litegraph' + +import type { Subgraph } from './Subgraph' +import type { SubgraphNode } from './SubgraphNode' + +export type ExecutionId = string + +/** + * Interface describing the data transfer objects used when compiling a graph for execution. + */ +export type ExecutableLGraphNode = Omit< + ExecutableNodeDTO, + 'graph' | 'node' | 'subgraphNode' +> + +/** + * The end result of resolving a DTO input. + * When a widget value is returned, {@link widgetInfo} is present and {@link origin_slot} is `-1`. + */ +type ResolvedInput = { + /** DTO for the node that the link originates from. */ + node: ExecutableLGraphNode + /** Full unique execution ID of the node that the link originates from. In the case of a widget value, this is the ID of the subgraph node. */ + origin_id: ExecutionId + /** The slot index of the output on the node that the link originates from. `-1` when widget value is set. */ + origin_slot: number + /** Boxed widget value (e.g. for widgets). If this box is `undefined`, then an input link is connected, and widget values from the subgraph node are ignored. */ + widgetInfo?: { value: unknown } +} + +/** + * Concrete implementation of {@link ExecutableLGraphNode}. + * @remarks This is the class that is used to create the data transfer objects for executable nodes. + */ +export class ExecutableNodeDTO implements ExecutableLGraphNode { + applyToGraph?( + ...args: Parameters> + ): ReturnType> + + /** The graph that this node is a part of. */ + readonly graph: LGraph | Subgraph + + inputs: { linkId: LinkId | null; name: string; type: ISlotType }[] + + /** Backing field for {@link id}. */ + private _id: ExecutionId + + /** + * The path to the actual node through subgraph instances, represented as a list of all subgraph node IDs (instances), + * followed by the actual original node ID within the subgraph. Each segment is separated by `:`. + * + * e.g. `1:2:3`: + * - `1` is the node ID of the first subgraph node in the parent workflow + * - `2` is the node ID of the second subgraph node in the first subgraph + * - `3` is the node ID of the actual node in the subgraph definition + */ + get id() { + return this._id + } + + get type() { + return this.node.type + } + + get title() { + return this.node.title + } + + get mode() { + return this.node.mode + } + + get comfyClass() { + return this.node.comfyClass + } + + get isVirtualNode() { + return this.node.isVirtualNode + } + + get widgets() { + return this.node.widgets + } + + get subgraphId() { + return this.subgraphNode?.subgraph.id + } + + constructor( + /** The actual node that this DTO wraps. */ + readonly node: LGraphNode | SubgraphNode, + /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */ + readonly subgraphNodePath: readonly SerializedNodeId[], + /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */ + readonly nodesByExecutionId: Map, + /** The actual subgraph instance that contains this node, otherwise undefined. */ + readonly subgraphNode?: SubgraphNode + ) { + if (!node.graph) throw new NullGraphError() + + // Set the internal ID of the DTO + this._id = [...this.subgraphNodePath, this.node.id].join(':') + this.graph = node.graph + this.inputs = this.node.inputs.map((x) => ({ + linkId: x.link == null ? null : toLinkId(x.link), + name: x.name, + type: x.type + })) + + // Only create a wrapper if the node has an applyToGraph method + if (this.node.applyToGraph) { + this.applyToGraph = (...args) => this.node.applyToGraph?.(...args) + } + } + + /** Returns either the DTO itself, or the DTOs of the inner nodes of the subgraph. */ + getInnerNodes(): ExecutableLGraphNode[] { + return this.node.isSubgraphNode() + ? this.node.getInnerNodes(this.nodesByExecutionId, this.subgraphNodePath) + : [this] + } + + /** + * Resolves the executable node & link IDs for a given input slot. + * @param slot The slot index of the input. + * @param visited Leave empty unless overriding this method. + * A set of unique IDs, used to guard against infinite recursion. + * If overriding, ensure that the set is passed on all recursive calls. + * @returns The node and the origin ID / slot index of the output. + */ + resolveInput( + slot: number, + visited = new Set(), + type?: ISlotType + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[I]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving input ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + const input = this.inputs.at(slot) + if (!input) + throw new SlotIndexError( + `No input found for flattened id [${this.id}] slot [${slot}]` + ) + + // Nothing connected + if (input.linkId == null) return + + const link = this.graph.getLink(input.linkId) + if (!link) + throw new InvalidLinkError( + `No link found in parent graph for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const { subgraphNode } = this + + // Link goes up and out of this subgraph + if (subgraphNode && link.originIsIoNode) { + const subgraphNodeInput = subgraphNode.inputs.at(link.origin_slot) + if (!subgraphNodeInput) + throw new SlotIndexError( + `No input found for slot [${link.origin_slot}] ${input.name}` + ) + + // Nothing connected + const linkId = subgraphNodeInput.link + if (linkId == null) { + const id = subgraphNodeInput.widgetId + if (!id) return + + return { + node: this, + origin_id: this.id, + origin_slot: -1, + widgetInfo: { value: useWidgetValueStore().getWidget(id)?.value } + } + } + + if (!subgraphNode.graph) + throw new NullGraphError( + `SubgraphNode ${subgraphNode.id} has no graph during input resolution` + ) + const outerLink = subgraphNode.graph.getLink(linkId) + if (!outerLink) + throw new InvalidLinkError( + `No outer link found for slot [${link.origin_slot}] ${input.name}` + ) + + const subgraphNodeExecutionId: ExecutionId = + this.subgraphNodePath.join(':') + const subgraphNodeDto = this.nodesByExecutionId.get( + subgraphNodeExecutionId + ) + if (!subgraphNodeDto) + throw new Error( + `No subgraph node DTO found for id [${subgraphNodeExecutionId}]` + ) + + return subgraphNodeDto.resolveInput(outerLink.target_slot, visited) + } + + // Not part of a subgraph; use the original link + const outputNode = this.graph.getNodeById(link.origin_id) + if (!outputNode) + throw new InvalidLinkError( + `No input node found for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const outputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + outputNode.id + ].join(':') + const outputNodeDto = this.nodesByExecutionId.get(outputNodeExecutionId) + if (!outputNodeDto) + throw new Error( + `No output node DTO found for id [${outputNodeExecutionId}]` + ) + + return outputNodeDto.resolveOutput( + link.origin_slot, + type ?? input.type, + visited + ) + } + + /** + * Determines whether this output is a valid endpoint for a link (non-virtual, non-bypass). + * @param slot The slot index of the output. + * @param type The type of the input + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns The node and the origin ID / slot index of the output. + */ + resolveOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[O]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving output ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + // Muted nodes produce no output + if (this.mode === LGraphEventMode.NEVER) return + + // Upstreamed: Bypass nodes are bypassed using the first input with matching type + if (this.mode === LGraphEventMode.BYPASS) { + // Bypass nodes by finding first input with matching type + const matchingIndex = this._getBypassSlotIndex(slot, type) + + // No input types match - bypass not possible + if (matchingIndex === -1) { + console.warn( + `[ExecutableNodeDTO.resolveOutput] No input types match type [${type}] for id [${this.id}] slot [${slot}]`, + this + ) + return + } + + return this.resolveInput(matchingIndex, visited) + } + + const { node } = this + if (node.isSubgraphNode()) + return this._resolveSubgraphOutput(slot, type, visited) + + if (node.isVirtualNode) { + // Cross-graph virtual nodes (e.g. Set/Get) resolve their source directly. + const virtualSource = this.node.resolveVirtualOutput?.(slot) + if (virtualSource) { + const inputNodeDto = [...this.nodesByExecutionId.values()].find( + (dto) => + dto instanceof ExecutableNodeDTO && dto.node === virtualSource.node + ) + if (!inputNodeDto) + throw new Error( + `No DTO found for virtual source node [${virtualSource.node.id}]` + ) + + return inputNodeDto.resolveOutput(virtualSource.slot, type, visited) + } + const virtualLink = this.node.getInputLink(slot) + if (virtualLink) { + const { inputNode } = virtualLink.resolve(this.graph) + if (!inputNode) + throw new InvalidLinkError( + `Virtual node failed to resolve parent [${this.id}] slot [${slot}]` + ) + + const inputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + inputNode.id + ].join(':') + const inputNodeDto = this.nodesByExecutionId.get(inputNodeExecutionId) + if (!inputNodeDto) + throw new Error(`No input node DTO found for id [${inputNode.id}]`) + + return inputNodeDto.resolveInput(virtualLink.target_slot, visited, type) + } + + // Virtual nodes without a matching input should be discarded. + return + } + + return { + node: this, + origin_id: this.id, + origin_slot: slot + } + } + + /** + * Finds the index of the input slot on this node that matches the given output {@link slot} index. + * Used when bypassing nodes. + * @param slot The output slot index on this node + * @param type The type of the final target input (so type list matches are accurate) + * @returns The index of the input slot on this node, otherwise `-1`. + */ + private _getBypassSlotIndex(slot: number, type: ISlotType) { + const { inputs } = this + const oppositeInput = inputs[slot] + const outputType = this.node.outputs[slot].type + + // Any type short circuit - match slot ID, fallback to first slot + if (type === '*' || type === '') { + return inputs.length > slot ? slot : 0 + } + + // Prefer input with the same slot ID + if ( + oppositeInput && + LiteGraph.isValidConnection(oppositeInput.type, outputType) && + LiteGraph.isValidConnection(oppositeInput.type, type) + ) { + return slot + } + + // Preserve legacy behaviour; use exact match first. + const exactMatch = inputs.findIndex((input) => input.type === type) + if (exactMatch !== -1) return exactMatch + + // Find first matching slot - prefer exact type + return inputs.findIndex( + (input) => + LiteGraph.isValidConnection(input.type, outputType) && + LiteGraph.isValidConnection(input.type, type) + ) + } + + /** + * Resolves the link inside a subgraph node, from the subgraph IO node to the node inside the subgraph. + * @param slot The slot index of the output on the subgraph node. + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns A DTO for the node, and the origin ID / slot index of the output. + */ + private _resolveSubgraphOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const { node } = this + const output = node.outputs.at(slot) + + if (!output) + throw new SlotIndexError( + `No output found for flattened id [${this.id}] slot [${slot}]` + ) + if (!node.isSubgraphNode()) + throw new TypeError(`Node is not a subgraph node: ${node.id}`) + + // Link inside the subgraph + const innerResolved = node.resolveSubgraphOutputLink(slot) + if (!innerResolved) return + + const innerNode = innerResolved.outputNode + if (!innerNode) + throw new Error( + `No output node found for id [${this.id}] slot [${slot}] ${output.name}` + ) + + // Recurse into the subgraph + const innerNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + node.id, + innerNode.id + ].join(':') + const innerNodeDto = this.nodesByExecutionId.get(innerNodeExecutionId) + if (!innerNodeDto) + throw new Error( + `No inner node DTO found for id [${innerNodeExecutionId}]` + ) + + return innerNodeDto.resolveOutput( + innerResolved.link.origin_slot, + type, + visited + ) + } +} diff --git a/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__Subgraph.ts b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__Subgraph.ts new file mode 100644 index 00000000..e1f2f0b2 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__Subgraph.ts @@ -0,0 +1,3 @@ +// Re-export Subgraph and GraphOrSubgraph from LGraph.ts to maintain compatibility +// This is a temporary fix to resolve circular dependency issues +export { Subgraph, type GraphOrSubgraph } from '@/lib/litegraph/src/LGraph' diff --git a/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts new file mode 100644 index 00000000..6ea9b179 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts @@ -0,0 +1,948 @@ +import cloneDeep from 'es-toolkit/compat/cloneDeep' +import type { BaseLGraph, LGraph, SubgraphId } from '@/lib/litegraph/src/LGraph' +import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' +import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode' +import { LLink } from '@/lib/litegraph/src/LLink' +import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import type { + ISubgraphInput, + IWidgetLocator +} from '@/lib/litegraph/src/interfaces' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { INodeInputSlot, ISlotType } from '@/lib/litegraph/src/litegraph' +import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' +import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' +import { toNodeId } from '@/types/nodeId' +import type { SerializedNodeId } from '@/types/nodeId' +import type { + GraphOrSubgraph, + Subgraph +} from '@/lib/litegraph/src/subgraph/Subgraph' +import type { + ExportedSubgraphInstance, + ISerialisedNode +} from '@/lib/litegraph/src/types/serialisation' +import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' +import type { + IBaseWidget, + TWidgetValue +} from '@/lib/litegraph/src/types/widgets' +import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' +import { resolveConcretePromotedWidget } from '@/core/graph/subgraph/resolveConcretePromotedWidget' +import { resolveSubgraphInputTarget } from '@/core/graph/subgraph/resolveSubgraphInputTarget' +import { parsePreviewExposures } from '@/core/schemas/previewExposureSchema' +import { parseProxyWidgetErrorQuarantine } from '@/core/schemas/proxyWidgetQuarantineSchema' +import { usePreviewExposureStore } from '@/stores/previewExposureStore' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { createNodeLocatorId } from '@/types/nodeIdentification' +import type { WidgetId } from '@/types/widgetId' +import { widgetId } from '@/types/widgetId' + +import { ExecutableNodeDTO } from './ExecutableNodeDTO' +import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO' +import type { SubgraphInput } from './SubgraphInput' +import { createBitmapCache } from './svgBitmapCache' + +const workflowSvg = new Image() +workflowSvg.src = + "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='16' height='16'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-linecap='round' stroke-width='1.3' d='M9.18613 3.09999H6.81377M9.18613 12.9H7.55288c-3.08678 0-5.35171-2.99581-4.60305-6.08843l.3054-1.26158M14.7486 2.1721l-.5931 2.45c-.132.54533-.6065.92789-1.1508.92789h-2.2993c-.77173 0-1.33797-.74895-1.1508-1.5221l.5931-2.45c.132-.54533.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.74896 1.1508 1.52211Zm-8.3033 0-.59309 2.45c-.13201.54533-.60646.92789-1.15076.92789H2.4021c-.7717 0-1.33793-.74895-1.15077-1.5221l.59309-2.45c.13201-.54533.60647-.9279 1.15077-.9279h2.29935c.77169 0 1.33792.74896 1.15076 1.52211Zm8.3033 9.8-.5931 2.45c-.132.5453-.6065.9279-1.1508.9279h-2.2993c-.77173 0-1.33797-.749-1.1508-1.5221l.5931-2.45c.132-.5453.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.7489 1.1508 1.5221Z'/%3E%3C/svg%3E %3C/svg%3E" + +const workflowBitmapCache = createBitmapCache(workflowSvg, 32) + +export class SubgraphNode extends LGraphNode implements BaseLGraph { + declare inputs: (INodeInputSlot & Partial)[] + + override readonly type: SubgraphId + override readonly isVirtualNode = true as const + override graph: GraphOrSubgraph | null + + get rootGraph(): LGraph { + if (!this.graph) + throw new NullGraphError(`SubgraphNode ${this.id} has no graph`) + return this.graph.rootGraph + } + + get isDetached(): boolean { + return !this.graph + } + + override get displayType(): string { + return 'Subgraph node' + } + + override isSubgraphNode(): this is SubgraphNode { + return true + } + + declare widgets: IBaseWidget[] + + /** + * Retained as a no-op for extension compatibility: promoted host widgets are + * now store-backed and addressed by widgetId, so there is no view cache to + * invalidate. + */ + invalidatePromotedViews(): void {} + + private _eventAbortController = new AbortController() + + constructor( + graph: GraphOrSubgraph, + readonly subgraph: Subgraph, + instanceData: ExportedSubgraphInstance + ) { + super(subgraph.name, subgraph.id) + this.graph = graph + + Object.defineProperty(this, 'widgets', { + get: () => + this.inputs.flatMap((input) => { + const widget = this._projectPromotedWidget(input) + return widget ? [widget] : [] + }), + set: () => { + if (import.meta.env.DEV) + console.warn( + 'Cannot manually set widgets on SubgraphNode; use the promotion system.' + ) + }, + configurable: true, + enumerable: true + }) + + const subgraphEvents = this.subgraph.events + const { signal } = this._eventAbortController + + subgraphEvents.addEventListener( + 'input-added', + (e) => { + const subgraphInput = e.detail.input + const { name, type } = subgraphInput + const existingInput = this.inputs.find( + (input) => + input._subgraphSlot === subgraphInput || + (input._subgraphSlot && input._subgraphSlot.id === subgraphInput.id) + ) + if (existingInput) { + this._addSubgraphInputListeners(subgraphInput, existingInput) + const linkId = subgraphInput.linkIds[0] + if (linkId === undefined) return + + const link = this.subgraph.getLink(linkId) + if (!link) return + + const { inputNode, input } = link.resolve(subgraph) + if (!inputNode || !input) return + + const widget = inputNode.getWidgetFromSlot(input) + if (widget) + this._setWidget(subgraphInput, existingInput, widget, input.widget) + return + } + const input = this.addInput(name, type, { + _subgraphSlot: subgraphInput + }) + this.invalidatePromotedViews() + + this._addSubgraphInputListeners(subgraphInput, input) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-input', + (e) => { + const widget = e.detail.input._widget + if (widget) this.ensureWidgetRemoved(widget) + + this.removeInput(e.detail.index) + this.invalidatePromotedViews() + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'output-added', + (e) => { + const { name, type } = e.detail.output + this.addOutput(name, type) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-output', + (e) => { + this.removeOutput(e.detail.index) + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-input', + (e) => { + const { index, newName } = e.detail + const input = this.inputs.at(index) + if (!input) throw new Error('Subgraph input not found') + + input.label = newName + // Do NOT change input.widget.name — it is the stable internal + // identifier used by onGraphConfigured (widgetInputs.ts) to match + // inputs to widgets. Changing it to the display label would cause + // collisions when two promoted inputs share the same label. + if (input._widget) input._widget.label = newName + if (input.widgetId) { + const state = useWidgetValueStore().getWidget(input.widgetId) + if (state) state.label = newName + } + this.invalidatePromotedViews() + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.INPUT + }) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-output', + (e) => { + const { index, newName } = e.detail + const output = this.outputs.at(index) + if (!output) throw new Error('Subgraph output not found') + + output.label = newName + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.OUTPUT + }) + }, + { signal } + ) + + this.type = subgraph.id + this.configure(instanceData) + + this.addTitleButton({ + name: 'enter_subgraph', + text: '\uE93B', // Unicode for pi-window-maximize + yOffset: 0, // No vertical offset needed, button is centered + xOffset: -10, + fontSize: 16 + }) + } + + override onTitleButtonClick( + button: LGraphButton, + canvas: LGraphCanvas + ): void { + if (button.name === 'enter_subgraph') { + canvas.openSubgraph(this.subgraph, this) + } else { + super.onTitleButtonClick(button, canvas) + } + } + + private _projectPromotedWidget( + input: INodeInputSlot + ): IBaseWidget | undefined { + if (input._widget) return input._widget + + const id = input.widgetId + if (!id) return + + const store = useWidgetValueStore() + const widget: IBaseWidget = { + get name() { + return store.getWidget(id)?.name ?? input.name + }, + get label() { + return store.getWidget(id)?.label ?? input.label ?? input.name + }, + set label(next) { + const state = store.getWidget(id) + if (state) state.label = next + }, + get y() { + return store.getWidget(id)?.y ?? 0 + }, + set y(next) { + const state = store.getWidget(id) + if (state) state.y = next + }, + get type() { + return store.getWidget(id)?.type ?? 'text' + }, + get options() { + return store.getWidget(id)?.options ?? {} + }, + get value() { + const value = store.getWidget(id)?.value + return isWidgetValue(value) ? value : undefined + }, + set value(next) { + store.setValue(id, next) + }, + // Canvas edits operate on a transient concrete widget (toConcreteWidget), + // so the value setter above is never invoked; BaseWidget.setValue writes + // its own local state and then calls this callback, which is the only + // bridge back to the store. + callback(next) { + store.setValue(id, next) + } + } + Object.defineProperty(widget, 'widgetId', { + value: id, + enumerable: false, + configurable: true + }) + input._widget = widget + return input._widget + } + + private _addSubgraphInputListeners( + subgraphInput: SubgraphInput, + input: INodeInputSlot & Partial + ) { + input._subgraphSlot = subgraphInput + + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + input._listenerController = new AbortController() + const { signal } = input._listenerController + + subgraphInput.events.addEventListener( + 'input-connected', + (e) => { + input.shape = this.getSlotShape(subgraphInput, e.detail.input) + if (!e.detail.widget || !e.detail.node) return + + this._setWidget( + subgraphInput, + input, + e.detail.widget, + e.detail.input.widget + ) + }, + { signal } + ) + + subgraphInput.events.addEventListener( + 'input-disconnected', + () => { + this.invalidatePromotedViews() + input.shape = this.getSlotShape(subgraphInput) + + const connectedWidgets = subgraphInput.getConnectedWidgets() + if (connectedWidgets.length > 0) { + this._resolveInputWidget(subgraphInput, input) + this.invalidatePromotedViews() + return + } + + if (input._widget) this.ensureWidgetRemoved(input._widget) + if (input.widgetId) { + const id = input.widgetId + queueMicrotask(() => { + if (this.inputs.some((input) => input.widgetId === id)) return + useWidgetValueStore().deleteWidget(id) + }) + } + + delete input.pos + delete input.widget + delete input.widgetId + input._widget = undefined + this.invalidatePromotedViews() + }, + { signal } + ) + } + + private _rebindInputSubgraphSlots(): void { + this.invalidatePromotedViews() + + const subgraphSlots = [...this.subgraph.inputNode.slots] + const slotsBySignature = new Map() + const slotsByName = new Map() + + for (const slot of subgraphSlots) { + const signature = `${slot.name}:${String(slot.type)}` + const signatureSlots = slotsBySignature.get(signature) + if (signatureSlots) { + signatureSlots.push(slot) + } else { + slotsBySignature.set(signature, [slot]) + } + + const nameSlots = slotsByName.get(slot.name) + if (nameSlots) { + nameSlots.push(slot) + } else { + slotsByName.set(slot.name, [slot]) + } + } + + const assignedSlotIds = new Set() + const takeUnassignedSlot = ( + slots: SubgraphInput[] | undefined + ): SubgraphInput | undefined => { + if (!slots) return undefined + return slots.find((slot) => !assignedSlotIds.has(String(slot.id))) + } + + for (const input of this.inputs) { + const existingSlot = input._subgraphSlot + if ( + existingSlot && + this.subgraph.inputNode.slots.some((slot) => slot === existingSlot) + ) { + assignedSlotIds.add(String(existingSlot.id)) + continue + } + + const signature = `${input.name}:${String(input.type)}` + const matchedSlot = + takeUnassignedSlot(slotsBySignature.get(signature)) ?? + takeUnassignedSlot(slotsByName.get(input.name)) + + if (matchedSlot) { + input._subgraphSlot = matchedSlot + assignedSlotIds.add(String(matchedSlot.id)) + } else { + delete input._subgraphSlot + } + } + } + + override configure(info: ExportedSubgraphInstance): void { + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + } + + this.inputs.length = 0 + this.inputs.push( + ...this.subgraph.inputNode.slots.map((slot) => + Object.assign( + new NodeInputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + shape: this.getSlotShape(slot), + type: slot.type, + link: null + }, + this + ), + { + _subgraphSlot: slot + } + ) + ) + ) + this.invalidatePromotedViews() + + this.outputs.length = 0 + this.outputs.push( + ...this.subgraph.outputNode.slots.map( + (slot) => + new NodeOutputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + type: slot.type, + links: null + }, + this + ) + ) + ) + + super.configure(info) + this._applyPromotedWidgetValues(info.widgets_values) + } + + private _applyPromotedWidgetValues( + widgetValues: ExportedSubgraphInstance['widgets_values'] + ): void { + const quarantineValuesByInputName = this._readQuarantineHostValuesByName() + + let valueIndex = 0 + for (const input of this.inputs) { + if (!input.widgetId) continue + const value = + quarantineValuesByInputName.get(input.name) ?? + widgetValues?.[valueIndex] + if (value !== undefined) { + useWidgetValueStore().setValue(input.widgetId, value) + } + valueIndex += 1 + } + } + + private _readQuarantineHostValuesByName(): Map { + return new Map( + parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + .toReversed() + .flatMap(({ originalEntry: [sourceNodeId, name], hostValue }) => + sourceNodeId === '-1' && + hostValue !== undefined && + isWidgetValue(hostValue) + ? [[name, hostValue] as const] + : [] + ) + ) + } + + override _internalConfigureAfterSlots() { + this._rebindInputSubgraphSlots() + + this.inputs = this.inputs.filter((input) => input._subgraphSlot) + this.invalidatePromotedViews() + + this._hydratePreviewExposures() + + for (const input of this.inputs) { + const subgraphInput = input._subgraphSlot + if (!subgraphInput) { + console.warn( + `[SubgraphNode.configure] No subgraph input found for input ${input.name}, skipping` + ) + continue + } + + this._addSubgraphInputListeners(subgraphInput, input) + this._resolveInputWidget(subgraphInput, input) + } + } + + private _hydratePreviewExposures() { + const store = usePreviewExposureStore() + const rootGraphId = this.rootGraph.id + const hostLocator = String(this.id) + const rawProperty = this.properties.previewExposures + const hasExplicitProperty = Array.isArray(rawProperty) + const fromProperty = parsePreviewExposures(rawProperty) + if (fromProperty.length) { + store.setExposures(rootGraphId, hostLocator, fromProperty) + return + } + if (hasExplicitProperty) { + store.setExposures(rootGraphId, hostLocator, []) + return + } + const legacyKey = createNodeLocatorId(null, this.id) + const legacy = store.getExposures(rootGraphId, legacyKey) + if (legacy.length) { + store.setExposures(rootGraphId, hostLocator, [...legacy]) + return + } + store.setExposures(rootGraphId, hostLocator, []) + } + + rebuildInputWidgetBindings(): void { + this.invalidatePromotedViews() + + for (const input of this.inputs) { + delete input.widget + delete input.pos + delete input.widgetId + this._clearPromotedWidget(input) + const subgraphInput = input._subgraphSlot + if (!subgraphInput) continue + this._resolveInputWidget(subgraphInput, input) + } + + this.invalidatePromotedViews() + } + + private _resolveInputWidget( + subgraphInput: SubgraphInput, + input: INodeInputSlot + ) { + for (const linkId of subgraphInput.linkIds) { + const link = this.subgraph.getLink(linkId) + if (!link) { + console.warn( + `[SubgraphNode.configure] No link found for link ID ${linkId}`, + this + ) + continue + } + + const { inputNode } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + const targetInput = inputNode.inputs.find((inp) => inp.link === linkId) + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) + continue + } + + const widget = inputNode.getWidgetFromSlot(targetInput) + if (widget) { + this._setWidget(subgraphInput, input, widget, targetInput.widget) + break + } + + // Nested promotion: the source is itself a promoted subgraph input with + // no concrete widget. Resolve the deepest interior widget so this input + // still receives widget state and a widgetId. + const nested = this._resolveNestedPromotedSource(inputNode, targetInput) + if (nested) { + this._setWidget(subgraphInput, input, nested.widget, targetInput.widget) + break + } + } + } + + private _resolveNestedPromotedSource( + inputNode: LGraphNode, + targetInput: INodeInputSlot + ): { node: LGraphNode; widget: IBaseWidget } | undefined { + if (!inputNode.isSubgraphNode()) return undefined + + const target = resolveSubgraphInputTarget(inputNode, targetInput.name) + if (!target) return undefined + + const resolved = resolveConcretePromotedWidget( + inputNode, + target.nodeId, + target.widgetName + ) + return resolved.status === 'resolved' ? resolved.resolved : undefined + } + + private _setWidget( + subgraphInput: Readonly, + input: INodeInputSlot, + interiorWidget: Readonly, + inputWidget: IWidgetLocator | undefined + ) { + this.invalidatePromotedViews() + + this._clearPromotedWidget(input) + + input.widget ??= { name: subgraphInput.name } + input.widget.name = subgraphInput.name + if (inputWidget) Object.setPrototypeOf(input.widget, inputWidget) + + const id = widgetId(this.rootGraph.id, this.id, subgraphInput.name) + input.widgetId = id + useWidgetValueStore().registerWidget(id, { + type: interiorWidget.type, + value: interiorWidget.value, + options: cloneDeep(interiorWidget.options ?? {}), + label: input.label ?? subgraphInput.name, + serialize: interiorWidget.serialize, + disabled: interiorWidget.disabled, + isDOMWidget: + 'isDOMWidget' in interiorWidget && + typeof interiorWidget.isDOMWidget === 'boolean' + ? interiorWidget.isDOMWidget + : undefined + }) + input._widget = + this.createPromotedHostWidget(input, id, interiorWidget) ?? + this._projectPromotedWidget(input) + this._setConcreteSlots() + + this.subgraph.events.dispatch('widget-promoted', { + widget: interiorWidget, + subgraphNode: this + }) + } + + /** + * App-layer hook to build a promoted DOM widget; the default falls back to the + * store-backed projection. Litegraph core stays free of Vue/Pinia/DOM. + */ + protected createPromotedHostWidget( + _input: INodeInputSlot, + _id: WidgetId, + _sourceWidget: Readonly + ): IBaseWidget | undefined { + return undefined + } + + /** + * Runs the host widget's `onRemove` (unregistering DOM widgets) and clears it. + * Unlike {@link ensureWidgetRemoved}, dispatches no demotion event, so it is + * safe on re-resolution. + */ + private _clearPromotedWidget(input: INodeInputSlot): void { + input._widget?.onRemove?.() + input._widget = undefined + } + + override onAdded(_graph: LGraph): void { + this.invalidatePromotedViews() + } + + /** + * @param name The name of the input slot. + * @param type The type of the input slot. + * @param inputProperties Properties that are directly assigned to the created input. Default: a new, empty object. + * @returns The new input slot. + */ + override addInput>( + name: string, + type: ISlotType, + inputProperties: TInput = {} as TInput + ): INodeInputSlot & TInput { + return super.addInput(name, type, inputProperties) + } + + override getSlotFromWidget( + widget: IBaseWidget | undefined + ): INodeInputSlot | undefined { + if (widget?.widgetId) { + const promotedInput = this.inputs.find( + (input) => input.widgetId === widget.widgetId + ) + if (promotedInput) return promotedInput + } + return super.getSlotFromWidget(widget) + } + + override getWidgetFromSlot(slot: INodeInputSlot): IBaseWidget | undefined { + if (slot._widget) return slot._widget + return super.getWidgetFromSlot(slot) + } + + override getInputLink(slot: number): LLink | null { + const innerLink = this.subgraph.outputNode.slots[slot].getLinks().at(0) + if (!innerLink) { + console.warn( + `SubgraphNode.getInputLink: no inner link found for slot ${slot}` + ) + return null + } + + const newLink = LLink.create(innerLink) + newLink.origin_id = toNodeId(`${this.id}:${innerLink.origin_id}`) + newLink.origin_slot = innerLink.origin_slot + + return newLink + } + + /** + * @param slot The slot index + * @returns The resolved connections, or undefined if no input node is found. + */ + resolveSubgraphInputLinks(slot: number): ResolvedConnection[] { + const inputSlot = this.subgraph.inputNode.slots[slot] + const innerLinks = inputSlot.getLinks() + if (innerLinks.length === 0) { + console.warn( + `[SubgraphNode.resolveSubgraphInputLinks] No inner links found for input slot [${slot}] ${inputSlot.name}`, + this + ) + return [] + } + return innerLinks.map((link) => link.resolve(this.subgraph)) + } + + /** + * @param slot The slot index + * @returns The output node if found, otherwise undefined. + */ + resolveSubgraphOutputLink(slot: number): ResolvedConnection | undefined { + const outputSlot = this.subgraph.outputNode.slots[slot] + const innerLink = outputSlot.getLinks().at(0) + if (innerLink) { + return innerLink.resolve(this.subgraph) + } + console.warn( + `[SubgraphNode.resolveSubgraphOutputLink] No inner link found for output slot [${slot}] ${outputSlot.name}`, + this + ) + } + + override getInnerNodes( + executableNodes: Map, + subgraphNodePath: readonly SerializedNodeId[] = [], + nodes: ExecutableLGraphNode[] = [], + visited = new Set() + ): ExecutableLGraphNode[] { + if (visited.has(this)) { + const nodeInfo = `${this.id}${this.title ? ` (${this.title})` : ''}` + const subgraphInfo = `'${this.subgraph.name || 'Unnamed Subgraph'}'` + const depth = subgraphNodePath.length + throw new RecursionError( + `Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph ${subgraphInfo}. ` + + `This creates an infinite loop in the subgraph hierarchy.` + ) + } + visited.add(this) + + const subgraphInstanceIdPath = [...subgraphNodePath, this.id] + + const parentSubgraphNode = this.rootGraph + .resolveSubgraphIdPath(subgraphNodePath.map(toNodeId)) + .at(-1) + const subgraphNodeDto = new ExecutableNodeDTO( + this, + subgraphNodePath, + executableNodes, + parentSubgraphNode + ) + executableNodes.set(subgraphNodeDto.id, subgraphNodeDto) + + for (const node of this.subgraph.nodes) { + if ('getInnerNodes' in node && node.getInnerNodes) { + node.getInnerNodes( + executableNodes, + subgraphInstanceIdPath, + nodes, + new Set(visited) + ) + } else { + const aVeryRealNode = new ExecutableNodeDTO( + node, + subgraphInstanceIdPath, + executableNodes, + this + ) + executableNodes.set(aVeryRealNode.id, aVeryRealNode) + nodes.push(aVeryRealNode) + } + } + return nodes + } + + override removeWidget(widget: IBaseWidget): void { + this.ensureWidgetRemoved(widget) + } + + override ensureWidgetRemoved(widget: IBaseWidget): void { + widget.onRemove?.() + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + + override onRemoved(): void { + this._eventAbortController.abort() + + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + this._clearPromotedWidget(input) + } + } + override drawTitleBox( + ctx: CanvasRenderingContext2D, + { + scale, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + box_size = 10 + }: DrawTitleBoxOptions + ): void { + if (this.onDrawTitleBox) { + this.onDrawTitleBox(ctx, title_height, this.renderingSize, scale) + return + } + ctx.save() + ctx.fillStyle = '#3b82f6' + ctx.beginPath() + ctx.roundRect(6, -24.5, 22, 20, 5) + ctx.fill() + if (!low_quality) { + ctx.translate(25, 23) + ctx.scale(-1.5, 1.5) + ctx.drawImage( + workflowBitmapCache.get(), + 0, + -title_height, + box_size, + box_size + ) + } + ctx.restore() + } + + override serialize(): ISerialisedNode { + const serialized = super.serialize() + const serializedProperties = { ...(serialized.properties ?? {}) } + const rootGraphId = this.rootGraph.id + const hostLocator = String(this.id) + + const previewExposures = usePreviewExposureStore().getExposures( + rootGraphId, + hostLocator + ) + serializedProperties.previewExposures = previewExposures.map((entry) => ({ + ...entry + })) + + const quarantine = parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + if (quarantine.length === 0) { + delete serializedProperties.proxyWidgetErrorQuarantine + } else { + serializedProperties.proxyWidgetErrorQuarantine = quarantine.map( + (entry) => ({ ...entry }) + ) + } + + serialized.properties = serializedProperties + + const widgetValues = this.inputs.flatMap((input) => { + if (!input.widgetId) return [] + const value = useWidgetValueStore().getWidget(input.widgetId)?.value + return [isWidgetValue(value) ? value : undefined] + }) + + if (widgetValues.some((value) => value !== undefined)) { + serialized.widgets_values = widgetValues + } else { + delete serialized.widgets_values + } + + return serialized + } + + override clone() { + const clone = super.clone() + + // TODO: Consider deep cloning subgraphs here. + + return clone + } + getSlotShape(slot: SubgraphInput, extraInput?: INodeInputSlot) { + const shapes = slot.linkIds.map( + (id) => this.subgraph.links[id]?.resolve(this.subgraph)?.input?.shape + ) + if (extraInput) shapes.push(extraInput.shape) + return shapes.every((shape) => shape === shapes[0]) ? shapes[0] : undefined + } +} diff --git a/docs/hel-892/structure-reference/1.48.6__src__utils__executionUtil.ts b/docs/hel-892/structure-reference/1.48.6__src__utils__executionUtil.ts new file mode 100644 index 00000000..0b6ad406 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.6__src__utils__executionUtil.ts @@ -0,0 +1,160 @@ +import type { + ExecutableLGraphNode, + ExecutionId, + LGraph +} from '@/lib/litegraph/src/litegraph' +import { + ExecutableNodeDTO, + LGraphEventMode +} from '@/lib/litegraph/src/litegraph' +import type { + ComfyApiWorkflow, + ComfyWorkflowJSON +} from '@/platform/workflow/validation/schemas/workflowSchema' + +import { compressWidgetInputSlots } from './litegraphUtil' + +/** + * Converts the current graph workflow for sending to the API. + * @note Node widgets are updated before serialization to prepare queueing. + * + * @param graph The graph to convert. + * @param options The options for the conversion. + * - `sortNodes`: Whether to sort the nodes by execution order. + * @returns The workflow and node links + */ +export const graphToPrompt = async ( + graph: LGraph, + options: { sortNodes?: boolean } = {} +): Promise<{ workflow: ComfyWorkflowJSON; output: ComfyApiWorkflow }> => { + const { sortNodes = false } = options + + for (const node of graph.computeExecutionOrder(false)) { + const innerNodes = node.getInnerNodes + ? node.getInnerNodes(new Map()) + : [node] + for (const innerNode of innerNodes) { + if (innerNode.isVirtualNode) { + innerNode.applyToGraph?.() + } + } + } + + const workflow = graph.serialize({ sortNodes }) + + // Remove localized_name from the workflow + for (const node of workflow.nodes) { + for (const slot of node.inputs ?? []) { + delete slot.localized_name + } + for (const slot of node.outputs ?? []) { + delete slot.localized_name + } + } + + compressWidgetInputSlots(workflow) + workflow.extra ??= {} + workflow.extra.frontendVersion = __COMFYUI_FRONTEND_VERSION__ + + const nodeDtoMap = new Map() + for (const node of graph.computeExecutionOrder(false)) { + const dto: ExecutableLGraphNode = new ExecutableNodeDTO( + node, + [], + nodeDtoMap + ) + + nodeDtoMap.set(dto.id, dto) + + if ( + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + for (const innerNode of dto.getInnerNodes()) { + nodeDtoMap.set(innerNode.id, innerNode) + } + } + + const output: ComfyApiWorkflow = {} + // Process nodes in order of execution + for (const node of nodeDtoMap.values()) { + // Don't serialize muted nodes + if ( + node.isVirtualNode || + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + const inputs: ComfyApiWorkflow[string]['inputs'] = {} + const { widgets } = node + + // Store all widget values in the API prompt. + // Note: widget.options.serialize controls prompt inclusion (checked here). + // widget.serialize controls workflow persistence (checked by LGraphNode). + if (widgets) { + for (const [i, widget] of widgets.entries()) { + if (!widget.name || widget.options?.serialize === false) continue + + const widgetValue = widget.serializeValue + ? await widget.serializeValue(node, i) + : widget.value + // By default, Array values are reserved to represent node connections. + // We need to wrap the array as an object to avoid the misinterpretation + // of the array as a node connection. + // The backend automatically unwraps the object to an array during + // execution. + inputs[widget.name] = Array.isArray(widgetValue) + ? widget.type === 'curve' + ? { __type__: 'CURVE', __value__: widgetValue } + : { __value__: widgetValue } + : widgetValue + } + } + + // Store all node links + for (const [i, input] of node.inputs.entries()) { + const resolvedInput = node.resolveInput(i) + if (!resolvedInput) continue + + // Resolved to an actual widget value rather than a node connection + if (resolvedInput.widgetInfo) { + const { value } = resolvedInput.widgetInfo + inputs[input.name] = Array.isArray(value) ? { __value__: value } : value + continue + } + + inputs[input.name] = [ + String(resolvedInput.origin_id), + // @ts-expect-error link.origin_slot is already number. + parseInt(resolvedInput.origin_slot) + ] + } + + output[String(node.id)] = { + inputs, + // TODO(huchenlei): Filter out all nodes that cannot be mapped to a + // comfyClass. + class_type: node.comfyClass!, + // Ignored by the backend. + _meta: { + title: node.title + } + } + } + + // Remove inputs connected to removed nodes + for (const { inputs } of Object.values(output)) { + for (const [i, input] of Object.entries(inputs)) { + if (Array.isArray(input) && input.length === 2 && !output[input[0]]) { + delete inputs[i] + } + } + } + + return { workflow: workflow as ComfyWorkflowJSON, output } +} diff --git a/docs/hel-892/structure-reference/1.48.7__LICENSE b/docs/hel-892/structure-reference/1.48.7__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/1.48.7__src__extensions__core__widgetInputs.ts b/docs/hel-892/structure-reference/1.48.7__src__extensions__core__widgetInputs.ts new file mode 100644 index 00000000..3c2ac3a6 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__extensions__core__widgetInputs.ts @@ -0,0 +1,617 @@ +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LLink +} from '@/lib/litegraph/src/litegraph' +import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' +import type { + IBaseWidget, + TWidgetValue +} from '@/lib/litegraph/src/types/widgets' +import { assetService } from '@/platform/assets/services/assetService' +import { createAssetWidget } from '@/platform/assets/utils/createAssetWidget' +import type { ComfyNodeDef, InputSpec } from '@/schemas/nodeDefSchema' +import { app } from '@/scripts/app' +import { + ComfyWidgets, + addValueControlWidgets, + isValidWidgetType +} from '@/scripts/widgets' +import { isPrimitiveNode } from '@/renderer/utils/nodeTypeGuards' +import { CONFIG, GET_CONFIG } from '@/services/litegraphService' +import { mergeInputSpec } from '@/utils/nodeDefUtil' +import { applyTextReplacements } from '@/utils/searchAndReplace' + +import { applyFirstWidgetValueToGraph } from './widgetValuePropagation' + +const replacePropertyName = 'Run widget replace on values' +export class PrimitiveNode extends LGraphNode { + controlValues?: TWidgetValue[] + lastType?: string + static override category: string + constructor(title: string) { + super(title) + this.addOutput('connect to widget input', '*') + this.serialize_widgets = true + this.isVirtualNode = true + + if (!this.properties || !(replacePropertyName in this.properties)) { + this.addProperty(replacePropertyName, false, 'boolean') + } + } + + override applyToGraph(extraLinks: LLink[] = []) { + const sourceWidget = this.widgets?.[0] + const graph = this.graph + if (!sourceWidget || !graph) return + + let v = sourceWidget.value + if (v && this.properties[replacePropertyName]) { + v = applyTextReplacements(graph, v as string) + } + applyFirstWidgetValueToGraph(this, extraLinks, () => v) + } + + override refreshComboInNode() { + const widget = this.widgets?.[0] + if (widget?.type === 'combo') { + // @ts-expect-error fixme ts strict error + widget.options.values = this.outputs[0].widget[GET_CONFIG]()[0] + + // @ts-expect-error fixme ts strict error + if (!widget.options.values.includes(widget.value as string)) { + // @ts-expect-error fixme ts strict error + widget.value = widget.options.values[0] + widget.callback?.(widget.value) + } + } + } + + override onAfterGraphConfigured() { + if (this.outputs[0].links?.length && !this.widgets?.length) { + this._onFirstConnection() + + // Populate widget values from config data + if (this.widgets && this.widgets_values) { + for (let i = 0; i < this.widgets_values.length; i++) { + const w = this.widgets[i] + if (w) { + w.value = this.widgets_values[i] + } + } + } + + // Merge values if required + this._mergeWidgetConfig() + } + } + + override onConnectionsChange( + _type: ISlotType, + _index: number, + connected: boolean + ) { + if (app.configuringGraph) { + // Dont run while the graph is still setting up + return + } + + const links = this.outputs[0].links + if (connected) { + if (links?.length && !this.widgets?.length) { + this._onFirstConnection() + } + } else { + // We may have removed a link that caused the constraints to change + this._mergeWidgetConfig() + + if (!links?.length) { + this.onLastDisconnect() + } + } + } + + override onConnectOutput( + slot: number, + _type: string, + input: INodeInputSlot, + target_node: LGraphNode, + target_slot: number + ) { + // Fires before the link is made allowing us to reject it if it isn't valid + // No widget, we can't connect + if (!input.widget && !(input.type in ComfyWidgets)) { + return false + } + + if (this.outputs[slot].links?.length) { + const valid = this._isValidConnection(input) + if (valid) { + // On connect of additional outputs, copy our value to their widget + this.applyToGraph([{ target_id: target_node.id, target_slot } as LLink]) + } + return valid + } + + return true + } + + private _onFirstConnection(recreating?: boolean) { + // First connection can fire before the graph is ready on initial load so random things can be missing + if (!this.outputs[0].links || !this.graph) { + this.onLastDisconnect() + return + } + const linkId = this.outputs[0].links[0] + const link = this.graph.links[linkId] + if (!link) return + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode || !theirNode.inputs) return + + const input = theirNode.inputs[link.target_slot] + if (!input) return + + let widget + if (!input.widget) { + if (!(input.type in ComfyWidgets)) return + widget = { name: input.name, [GET_CONFIG]: () => [input.type, {}] } //fake widget + } else { + widget = input.widget + } + + // @ts-expect-error fixme ts strict error + const config = widget[GET_CONFIG]?.() + if (!config) return + + const { type } = getWidgetType(config) + // Update our output to restrict to the widget type + this.outputs[0].type = type + this.outputs[0].name = type + this.outputs[0].widget = widget + + this._createWidget( + widget[CONFIG] ?? config, + theirNode, + widget.name, + // @ts-expect-error fixme ts strict error + recreating + ) + } + + private _createWidget( + inputData: InputSpec, + node: LGraphNode, + widgetName: string, + recreating: boolean + ) { + let type = inputData[0] + + if (type instanceof Array) { + type = 'COMBO' + } + + // Store current size as addWidget resizes the node + const [oldWidth, oldHeight] = this.size + let widget: IBaseWidget + + if ( + type === 'COMBO' && + assetService.shouldUseAssetBrowser(node.comfyClass, widgetName) + ) { + widget = this._createAssetWidget(node, widgetName, inputData) + const theirWidget = node.widgets?.find((w) => w.name === widgetName) + if (theirWidget) widget.value = theirWidget.value + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + return + } + + if (isValidWidgetType(type)) { + widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}).widget + } else { + // @ts-expect-error InputSpec is not typed correctly + widget = this.addWidget(type, 'value', null, () => {}, {}) + } + + if (node?.widgets && widget) { + const theirWidget = node.widgets.find((w) => w.name === widgetName) + if (theirWidget) { + widget.value = theirWidget.value + } + } + + if ( + !inputData?.[1]?.control_after_generate && + (widget.type === 'number' || widget.type === 'combo') + ) { + let control_value = this.widgets_values?.[1] + if (!control_value) { + control_value = 'fixed' + } + addValueControlWidgets( + this, + widget, + control_value as string, + undefined, + inputData + ) + if (this.widgets?.[1]) widget.linkedWidgets = [this.widgets[1]] + + const filter = this.widgets_values?.[2] + if (filter && this.widgets && this.widgets.length === 3) { + this.widgets[2].value = filter + } + } + + // Restore any saved control values + const controlValues = this.controlValues + if ( + this.widgets && + this.lastType === this.widgets[0]?.type && + controlValues?.length === this.widgets.length - 1 + ) { + for (let i = 0; i < controlValues.length; i++) { + this.widgets[i + 1].value = controlValues[i] + } + } + + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + } + + private _createAssetWidget( + targetNode: LGraphNode, + targetInputName: string, + inputData: InputSpec + ): IBaseWidget { + const defaultValue = inputData[1]?.default as string | undefined + return createAssetWidget({ + node: this, + widgetName: 'value', + nodeTypeForBrowser: targetNode.comfyClass ?? '', + inputNameForBrowser: targetInputName, + defaultValue + }) + } + + private _finalizeWidget( + widget: IBaseWidget, + oldWidth: number, + oldHeight: number, + recreating: boolean + ) { + widget.callback = useChainCallback(widget.callback, () => { + this.applyToGraph() + }) + + this.setSize([ + Math.max(this.size[0], oldWidth), + Math.max(this.size[1], oldHeight) + ]) + + if (!recreating) { + const sz = this.computeSize() + if (this.size[0] < sz[0]) { + this.size[0] = sz[0] + } + if (this.size[1] < sz[1]) { + this.size[1] = sz[1] + } + + requestAnimationFrame(() => { + this.onResize?.(this.size) + }) + } + } + + recreateWidget() { + const values = this.widgets?.map((w) => w.value) + this._removeWidgets() + this._onFirstConnection(true) + if (values?.length && this.widgets) { + for (let i = 0; i < this.widgets.length; i++) + this.widgets[i].value = values[i] + } + return this.widgets?.[0] + } + + private _mergeWidgetConfig() { + // Merge widget configs if the node has multiple outputs + const output = this.outputs[0] + const links = output.links ?? [] + + const hasConfig = !!output.widget?.[CONFIG] + if (hasConfig) { + delete output.widget?.[CONFIG] + } + + if (links?.length < 2 && hasConfig) { + // Copy the widget options from the source + if (links.length) { + this.recreateWidget() + } + + return + } + const config1 = (output.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config1) return + const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT' + if (!isNumber || !this.graph) return + + for (const linkId of links) { + const link = this.graph.links[linkId] + if (!link) continue // Can be null when removing a node + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode) continue + const theirInput = theirNode.inputs[link.target_slot] + + // Call is valid connection so it can merge the configs when validating + this._isValidConnection(theirInput, hasConfig) + } + } + + private _isValidConnection(input: INodeInputSlot, forceUpdate?: boolean) { + // Only allow connections where the configs match + const output = this.outputs?.[0] + const config2 = (input.widget?.[GET_CONFIG] as () => InputSpec)?.() + if (!config2) return false + + return !!mergeIfValid.call( + this, + output, + config2, + forceUpdate, + this.recreateWidget + ) + } + + private _removeWidgets() { + if (this.widgets) { + // Allow widgets to cleanup + for (const w of this.widgets) { + if (w.onRemove) { + w.onRemove() + } + } + + // Temporarily store the current values in case the node is being recreated + this.controlValues = [] + this.lastType = this.widgets[0]?.type + for (let i = 1; i < this.widgets.length; i++) { + this.controlValues.push(this.widgets[i].value) + } + setTimeout(() => { + delete this.lastType + delete this.controlValues + }, 15) + this.widgets.length = 0 + } + } + + onLastDisconnect() { + // We can't remove + re-add the output here as if you drag a link over the same link + // it removes, then re-adds, causing it to break + this.outputs[0].type = '*' + this.outputs[0].name = 'connect to widget input' + delete this.outputs[0].widget + + this._removeWidgets() + } +} + +export function getWidgetConfig( + slot: INodeInputSlot | INodeOutputSlot +): InputSpec { + return (slot.widget?.[CONFIG] ?? + (slot.widget?.[GET_CONFIG] as () => InputSpec)?.() ?? [ + '*', + {} + ]) as InputSpec +} + +function getConfig(this: LGraphNode, widgetName: string) { + const { nodeData } = this.constructor + return ( + nodeData?.input?.required?.[widgetName] ?? + nodeData?.input?.optional?.[widgetName] + ) +} + +/** + * Convert a widget to an input slot. + * @deprecated Widget to socket conversion is no longer necessary, as they co-exist now. + * @param node The node to convert the widget to an input slot for. + * @param widget The widget to convert to an input slot. + * @returns The input slot that was converted from the widget or undefined if the widget is not found. + * @knipIgnoreUnusedButUsedByCustomNodes + */ +export function convertToInput( + node: LGraphNode, + widget: IBaseWidget +): INodeInputSlot | undefined { + console.warn( + 'Please remove call to convertToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return node.inputs.find((slot) => slot.widget?.name === widget.name) +} + +function getWidgetType(config: InputSpec) { + // Special handling for COMBO so we restrict links based on the entries + let type = config[0] + if (type instanceof Array) { + type = 'COMBO' + } + return { type } +} + +export function setWidgetConfig(slot: INodeInputSlot, config?: InputSpec) { + if (!slot.widget) return + if (config) { + slot.widget[GET_CONFIG] = () => config + } else { + delete slot.widget + } + + if (!(slot instanceof NodeSlot)) return + const graph = slot.node.graph + if (!graph) return + const link = graph.getLink(slot.link) + if (!link) return + const originNode = graph.getNodeById(link.origin_id) + if (!originNode || !isPrimitiveNode(originNode)) return + if (config) { + originNode.recreateWidget() + } else if (!app.configuringGraph) { + originNode.disconnectOutput(0) + originNode.onLastDisconnect() + } +} + +export function mergeIfValid( + output: INodeOutputSlot | INodeInputSlot, + config2: InputSpec, + forceUpdate?: boolean, + recreateWidget?: () => void, + config1?: InputSpec +): { customConfig: InputSpec[1] } { + if (!config1) { + config1 = getWidgetConfig(output) + } + + const customSpec = mergeInputSpec(config1, config2) + + if (customSpec || forceUpdate) { + if (customSpec) { + // @ts-expect-error fixme ts strict error + output.widget[CONFIG] = customSpec + } + + // @ts-expect-error fixme ts strict error + const widget = recreateWidget?.call(this) + // When deleting a node this can be null + if (widget) { + // @ts-expect-error fixme ts strict error + const min = widget.options.min + // @ts-expect-error fixme ts strict error + const max = widget.options.max + // @ts-expect-error fixme ts strict error + if (min != null && widget.value < min) widget.value = min + // @ts-expect-error fixme ts strict error + if (max != null && widget.value > max) widget.value = max + // @ts-expect-error fixme ts strict error + widget.callback(widget.value) + } + } + + return { customConfig: customSpec?.[1] ?? {} } +} + +app.registerExtension({ + name: 'Comfy.WidgetInputs', + async beforeRegisterNodeDef( + nodeType: typeof LGraphNode, + _nodeData: ComfyNodeDef + ) { + // @ts-expect-error adding extra property + nodeType.prototype.convertWidgetToInput = function (this: LGraphNode) { + console.warn( + 'Please remove call to convertWidgetToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return false + } + + nodeType.prototype.onGraphConfigured = useChainCallback( + nodeType.prototype.onGraphConfigured, + function (this: LGraphNode) { + if (!this.inputs) return + this.widgets ??= [] + + for (const input of this.inputs) { + if (input.widget) { + const name = input.widget.name + if (!input.widget[GET_CONFIG]) { + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + + const w = this.widgets?.find((w) => w.name === name) + if (!w) { + this.removeInput(this.inputs.findIndex((i) => i === input)) + } + } + } + } + ) + + nodeType.prototype.onConfigure = useChainCallback( + nodeType.prototype.onConfigure, + function (this: LGraphNode) { + if (!app.configuringGraph && this.inputs) { + // On copy + paste of nodes, ensure that widget configs are set up + for (const input of this.inputs) { + if (input.widget && !input.widget[GET_CONFIG]) { + const name = input.widget.name + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + } + } + } + ) + + // Double click a widget input to automatically attach a primitive + const origOnInputDblClick = nodeType.prototype.onInputDblClick + nodeType.prototype.onInputDblClick = function ( + this: LGraphNode, + ...[slot, ...args]: Parameters> + ) { + const r = origOnInputDblClick?.apply(this, [slot, ...args]) + + const input = this.inputs[slot] + if (!input.widget) { + // Not a widget input or already handled input + if ( + !(input.type in ComfyWidgets) && + !( + ( + input.widget?.[GET_CONFIG] as (() => InputSpec) | undefined + )?.()?.[0] instanceof Array + ) + ) { + return r //also Not a ComfyWidgets input or combo (do nothing) + } + } + + // Create a primitive node + const node = LiteGraph.createNode('PrimitiveNode') + const graph = app.canvas.graph + if (!node || !graph) return r + + graph?.add(node) + + // Calculate a position that won't directly overlap another node + const pos: [number, number] = [ + this.pos[0] - node.size[0] - 30, + this.pos[1] + ] + while (graph.getNodeOnPos(pos[0], pos[1], graph.nodes)) + pos[1] += LiteGraph.NODE_TITLE_HEIGHT + + node.pos = pos + node.connect(0, this, slot) + node.title = input.name + + return r + } + }, + registerCustomNodes() { + LiteGraph.registerNodeType( + 'PrimitiveNode', + Object.assign(PrimitiveNode, { + title: 'Primitive' + }) + ) + PrimitiveNode.category = 'utilities/primitive' + } +}) diff --git a/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__LLink.ts b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__LLink.ts new file mode 100644 index 00000000..78e86137 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__LLink.ts @@ -0,0 +1,507 @@ +import { + SUBGRAPH_INPUT_ID, + SUBGRAPH_OUTPUT_ID +} from '@/lib/litegraph/src/constants' +import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations' +import { LayoutSource } from '@/renderer/core/layout/types' +import { toLinkId } from '@/types/linkId' +import { UNASSIGNED_NODE_ID, toNodeId, serializeNodeId } from '@/types/nodeId' +import { toRerouteId } from '@/types/rerouteId' + +import type { LinkId } from '@/types/linkId' +import type { RerouteId } from '@/types/rerouteId' +import type { LGraphNode } from './LGraphNode' +import type { NodeId, SerializedNodeId } from '@/types/nodeId' +import type { Reroute } from './Reroute' +import type { + CanvasColour, + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LinkNetwork, + LinkSegment, + Point, + ReadonlyLinkNetwork +} from './interfaces' +import type { Serialisable, SerialisableLLink } from './types/serialisation' + +const layoutMutations = useLayoutMutations() + +export type { LinkId } from '@/types/linkId' +export type SerialisedLLinkArray = [ + id: number, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + type: ISlotType +] + +// Resolved connection union; eliminates subgraph in/out as a possibility +export type ResolvedConnection = BaseResolvedConnection & + ( + | (ResolvedSubgraphInput & ResolvedNormalOutput) + | (ResolvedNormalInput & ResolvedSubgraphOutput) + | (ResolvedNormalInput & ResolvedNormalOutput) + ) + +interface BaseResolvedConnection { + link: LLink + /** The node on the input side of the link (owns {@link input}) */ + inputNode?: LGraphNode + /** The input the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: INodeInputSlot + /** The node on the output side of the link (owns {@link output}) */ + outputNode?: LGraphNode + /** The output the link is connected to (mutually exclusive with {@link subgraphInput}) */ + output?: INodeOutputSlot + /** The subgraph output the link is connected to (mutually exclusive with {@link input}) */ + subgraphOutput?: SubgraphOutput + /** The subgraph input the link is connected to (mutually exclusive with {@link output}) */ + subgraphInput?: SubgraphInput +} + +interface ResolvedNormalInput { + inputNode: LGraphNode | undefined + input: INodeInputSlot | undefined + subgraphOutput?: undefined +} + +interface ResolvedNormalOutput { + outputNode: LGraphNode | undefined + output: INodeOutputSlot | undefined + subgraphInput?: undefined +} + +interface ResolvedSubgraphInput { + inputNode?: undefined + /** The actual input slot the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: undefined + subgraphOutput: SubgraphOutput +} + +interface ResolvedSubgraphOutput { + outputNode?: undefined + output?: undefined + subgraphInput: SubgraphInput +} + +type BasicReadonlyNetwork = Pick< + ReadonlyLinkNetwork, + 'getNodeById' | 'links' | 'getLink' | 'inputNode' | 'outputNode' +> + +// this is the class in charge of storing link information +export class LLink implements LinkSegment, Serialisable { + static _drawDebug = false + + /** Link ID */ + id: LinkId + parentId?: RerouteId + type: ISlotType + /** Output node ID */ + origin_id: NodeId + /** Output slot index */ + origin_slot: number + /** Input node ID */ + target_id: NodeId + /** Input slot index */ + target_slot: number + + data?: number | string | boolean | { toToolTip?(): string } + _data?: unknown + /** Centre point of the link, calculated during render only - can be inaccurate */ + _pos: Point + /** @todo Clean up - never implemented in comfy. */ + _last_time?: number + /** The last canvas 2D path that was used to render this link */ + path?: Path2D + /** @inheritdoc */ + _centreAngle?: number + + /** @inheritdoc */ + _dragging?: boolean + + private _color?: CanvasColour | null + /** Custom colour for this link only */ + public get color(): CanvasColour | null | undefined { + return this._color + } + + public set color(value: CanvasColour) { + this._color = value === '' ? null : value + } + + public get isFloatingOutput(): boolean { + return this.origin_id === UNASSIGNED_NODE_ID && this.origin_slot === -1 + } + + public get isFloatingInput(): boolean { + return this.target_id === UNASSIGNED_NODE_ID && this.target_slot === -1 + } + + public get isFloating(): boolean { + return this.isFloatingOutput || this.isFloatingInput + } + + /** `true` if this link is connected to a subgraph input node (the actual origin is in a different graph). */ + get originIsIoNode(): boolean { + return this.origin_id === SUBGRAPH_INPUT_ID + } + + /** `true` if this link is connected to a subgraph output node (the actual target is in a different graph). */ + get targetIsIoNode(): boolean { + return this.target_id === SUBGRAPH_OUTPUT_ID + } + + constructor( + id: LinkId, + type: ISlotType, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + parentId?: RerouteId + ) { + this.id = id + this.type = type + this.origin_id = toNodeId(origin_id) + this.origin_slot = origin_slot + this.target_id = toNodeId(target_id) + this.target_slot = target_slot + this.parentId = parentId + + this._data = null + // center + this._pos = [0, 0] + } + + /** @deprecated Use {@link LLink.create} */ + static createFromArray(data: SerialisedLLinkArray): LLink { + return new LLink( + toLinkId(data[0]), + data[5], + data[1], + data[2], + data[3], + data[4] + ) + } + + /** + * LLink static factory: creates a new LLink from the provided data. + * @param data Serialised LLink data to create the link from + * @returns A new LLink + */ + static create(data: SerialisableLLink): LLink { + return new LLink( + toLinkId(data.id), + data.type, + data.origin_id, + data.origin_slot, + data.target_id, + data.target_slot, + data.parentId === undefined ? undefined : toRerouteId(data.parentId) + ) + } + + /** + * Gets all reroutes from the output slot to this segment. If this segment is a reroute, it will not be included. + * @returns An ordered array of all reroutes from the node output to + * this reroute or the reroute before it. Otherwise, an empty array. + */ + static getReroutes( + network: Pick, + linkSegment: LinkSegment + ): Reroute[] { + if (linkSegment.parentId === undefined) return [] + return network.reroutes.get(linkSegment.parentId)?.getReroutes() ?? [] + } + + static getFirstReroute( + network: Pick, + linkSegment: LinkSegment + ): Reroute | undefined { + return LLink.getReroutes(network, linkSegment).at(0) + } + + /** + * Finds the reroute in the chain after the provided reroute ID. + * @param network The network this link belongs to + * @param linkSegment The starting point of the search (input side). + * Typically the LLink object itself, but can be any link segment. + * @param rerouteId The matching reroute will have this set as its {@link parentId}. + * @returns The reroute that was found, `undefined` if no reroute was found, or `null` if an infinite loop was detected. + */ + static findNextReroute( + network: Pick, + linkSegment: LinkSegment, + rerouteId: RerouteId + ): Reroute | null | undefined { + if (linkSegment.parentId === undefined) return + return network.reroutes + .get(linkSegment.parentId) + ?.findNextReroute(rerouteId) + } + + /** + * Gets the origin node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the origin node of + * @returns The origin node of the link, or `undefined` if the link is not found or the origin node is not found + */ + static getOriginNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.origin_id + return network.getNodeById(id) ?? undefined + } + + /** + * Gets the target node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the target node of + * @returns The target node of the link, or `undefined` if the link is not found or the target node is not found + */ + static getTargetNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.target_id + return network.getNodeById(id) ?? undefined + } + + /** + * Resolves a link ID to the link, node, and slot objects. + * @param linkId The {@link id} of the link to resolve + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + static resolve( + linkId: LinkId | null | undefined, + network: BasicReadonlyNetwork + ): ResolvedConnection | undefined { + return network.getLink(linkId)?.resolve(network) + } + + /** + * Resolves a list of link IDs to the link, node, and slot objects. + * Discards invalid link IDs. + * @param linkIds An iterable of link {@link id}s to resolve + * @param network The link network to search + * @returns An array of resolved connections. If a link is not found, it is not included in the array. + * @see {@link LLink.resolve} + */ + static resolveMany( + linkIds: Iterable, + network: BasicReadonlyNetwork + ): ResolvedConnection[] { + const resolved: ResolvedConnection[] = [] + for (const id of linkIds) { + const r = network.getLink(id)?.resolve(network) + if (r) resolved.push(r) + } + return resolved + } + + /** + * Resolves the primitive ID values stored in the link to the referenced objects. + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + resolve(network: BasicReadonlyNetwork): ResolvedConnection { + const inputNode = + this.target_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.target_id) ?? undefined) + const input = inputNode?.inputs[this.target_slot] + const subgraphInput = this.originIsIoNode + ? network.inputNode?.slots[this.origin_slot] + : undefined + if (subgraphInput) { + return { inputNode, input, subgraphInput, link: this } + } + + const outputNode = + this.origin_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.origin_id) ?? undefined) + const output = outputNode?.outputs[this.origin_slot] + const subgraphOutput = this.targetIsIoNode + ? network.outputNode?.slots[this.target_slot] + : undefined + if (subgraphOutput) { + return { + outputNode, + output, + subgraphInput: undefined, + subgraphOutput, + link: this + } + } + + return { + inputNode, + outputNode, + input, + output, + subgraphInput, + subgraphOutput, + link: this + } + } + + configure(o: LLink | SerialisedLLinkArray) { + if (Array.isArray(o)) { + this.id = toLinkId(o[0]) + this.origin_id = toNodeId(o[1]) + this.origin_slot = o[2] + this.target_id = toNodeId(o[3]) + this.target_slot = o[4] + this.type = o[5] + } else { + this.id = o.id + this.type = o.type + this.origin_id = o.origin_id + this.origin_slot = o.origin_slot + this.target_id = o.target_id + this.target_slot = o.target_slot + this.parentId = o.parentId + } + } + + /** + * Checks if the specified node id and output index are this link's origin (output side). + * @param nodeId ID of the node to check + * @param outputIndex The array index of the node output + * @returns `true` if the origin matches, otherwise `false`. + */ + hasOrigin(nodeId: SerializedNodeId, outputIndex: number): boolean { + return ( + this.origin_id === toNodeId(nodeId) && this.origin_slot === outputIndex + ) + } + + /** + * Checks if the specified node id and input index are this link's target (input side). + * @param nodeId ID of the node to check + * @param inputIndex The array index of the node input + * @returns `true` if the target matches, otherwise `false`. + */ + hasTarget(nodeId: SerializedNodeId, inputIndex: number): boolean { + return ( + this.target_id === toNodeId(nodeId) && this.target_slot === inputIndex + ) + } + + /** + * Creates a floating link from this link. + * @param slotType The side of the link that is still connected + * @param parentId The parent reroute ID of the link + * @returns A new LLink that is floating + */ + toFloating(slotType: 'input' | 'output', parentId: RerouteId): LLink { + const exported = this.asSerialisable() + exported.id = toLinkId(-1) + exported.parentId = parentId + + if (slotType === 'input') { + exported.origin_id = UNASSIGNED_NODE_ID + exported.origin_slot = -1 + } else { + exported.target_id = UNASSIGNED_NODE_ID + exported.target_slot = -1 + } + + return LLink.create(exported) + } + + /** + * Disconnects a link and removes it from the graph, cleaning up any reroutes that are no longer used + * @param network The container (LGraph) where reroutes should be updated + * @param keepReroutes If `undefined`, reroutes will be automatically removed if no links remain. + * If `input` or `output`, reroutes will not be automatically removed, and retain a connection to the input or output, respectively. + */ + disconnect(network: LinkNetwork, keepReroutes?: 'input' | 'output'): void { + const reroutes = LLink.getReroutes(network, this) + + const lastReroute = reroutes.at(-1) + + // When floating from output, 1-to-1 ratio of floating link to final reroute (tree-like) + const outputFloating = + keepReroutes === 'output' && + lastReroute?.linkIds.size === 1 && + lastReroute.floatingLinkIds.size === 0 + + // When floating from inputs, the final (input side) reroute may have many floating links + if (outputFloating || (keepReroutes === 'input' && lastReroute)) { + const newLink = LLink.create(this) + newLink.id = toLinkId(-1) + + if (keepReroutes === 'input') { + newLink.origin_id = UNASSIGNED_NODE_ID + newLink.origin_slot = -1 + + lastReroute.floating = { slotType: 'input' } + } else { + newLink.target_id = UNASSIGNED_NODE_ID + newLink.target_slot = -1 + + lastReroute.floating = { slotType: 'output' } + } + + network.addFloatingLink(newLink) + } + + for (const reroute of reroutes) { + reroute.linkIds.delete(this.id) + if (!keepReroutes && !reroute.totalLinks) { + network.reroutes.delete(reroute.id) + // Delete reroute from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteReroute(reroute.id) + } + } + network.links.delete(this.id) + // Delete link from Layout Store + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.deleteLink(this.id) + } + + /** + * @deprecated Prefer {@link LLink.asSerialisable} (returns an object, not an array) + * @returns An array representing this LLink + */ + serialize(): SerialisedLLinkArray { + return [ + this.id, + serializeNodeId(this.origin_id), + this.origin_slot, + serializeNodeId(this.target_id), + this.target_slot, + this.type + ] + } + + asSerialisable(): SerialisableLLink { + const copy: SerialisableLLink = { + id: this.id, + origin_id: serializeNodeId(this.origin_id), + origin_slot: this.origin_slot, + target_id: serializeNodeId(this.target_id), + target_slot: this.target_slot, + type: this.type + } + if (this.parentId !== undefined) copy.parentId = this.parentId + return copy + } +} diff --git a/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts new file mode 100644 index 00000000..35220e8b --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts @@ -0,0 +1,429 @@ +import { toLinkId } from '@/types/linkId' +import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { SerializedNodeId } from '@/types/nodeId' +import type { LinkId } from '@/lib/litegraph/src/LLink' +import { InvalidLinkError } from '@/lib/litegraph/src/infrastructure/InvalidLinkError' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import { SlotIndexError } from '@/lib/litegraph/src/infrastructure/SlotIndexError' +import type { ISlotType } from '@/lib/litegraph/src/interfaces' +import { LGraphEventMode, LiteGraph } from '@/lib/litegraph/src/litegraph' + +import type { Subgraph } from './Subgraph' +import type { SubgraphNode } from './SubgraphNode' + +export type ExecutionId = string + +/** + * Interface describing the data transfer objects used when compiling a graph for execution. + */ +export type ExecutableLGraphNode = Omit< + ExecutableNodeDTO, + 'graph' | 'node' | 'subgraphNode' +> + +/** + * The end result of resolving a DTO input. + * When a widget value is returned, {@link widgetInfo} is present and {@link origin_slot} is `-1`. + */ +type ResolvedInput = { + /** DTO for the node that the link originates from. */ + node: ExecutableLGraphNode + /** Full unique execution ID of the node that the link originates from. In the case of a widget value, this is the ID of the subgraph node. */ + origin_id: ExecutionId + /** The slot index of the output on the node that the link originates from. `-1` when widget value is set. */ + origin_slot: number + /** Boxed widget value (e.g. for widgets). If this box is `undefined`, then an input link is connected, and widget values from the subgraph node are ignored. */ + widgetInfo?: { value: unknown } +} + +/** + * Concrete implementation of {@link ExecutableLGraphNode}. + * @remarks This is the class that is used to create the data transfer objects for executable nodes. + */ +export class ExecutableNodeDTO implements ExecutableLGraphNode { + applyToGraph?( + ...args: Parameters> + ): ReturnType> + + /** The graph that this node is a part of. */ + readonly graph: LGraph | Subgraph + + inputs: { linkId: LinkId | null; name: string; type: ISlotType }[] + + /** Backing field for {@link id}. */ + private _id: ExecutionId + + /** + * The path to the actual node through subgraph instances, represented as a list of all subgraph node IDs (instances), + * followed by the actual original node ID within the subgraph. Each segment is separated by `:`. + * + * e.g. `1:2:3`: + * - `1` is the node ID of the first subgraph node in the parent workflow + * - `2` is the node ID of the second subgraph node in the first subgraph + * - `3` is the node ID of the actual node in the subgraph definition + */ + get id() { + return this._id + } + + get type() { + return this.node.type + } + + get title() { + return this.node.title + } + + get mode() { + return this.node.mode + } + + get comfyClass() { + return this.node.comfyClass + } + + get isVirtualNode() { + return this.node.isVirtualNode + } + + get widgets() { + return this.node.widgets + } + + get subgraphId() { + return this.subgraphNode?.subgraph.id + } + + constructor( + /** The actual node that this DTO wraps. */ + readonly node: LGraphNode | SubgraphNode, + /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */ + readonly subgraphNodePath: readonly SerializedNodeId[], + /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */ + readonly nodesByExecutionId: Map, + /** The actual subgraph instance that contains this node, otherwise undefined. */ + readonly subgraphNode?: SubgraphNode + ) { + if (!node.graph) throw new NullGraphError() + + // Set the internal ID of the DTO + this._id = [...this.subgraphNodePath, this.node.id].join(':') + this.graph = node.graph + this.inputs = this.node.inputs.map((x) => ({ + linkId: x.link == null ? null : toLinkId(x.link), + name: x.name, + type: x.type + })) + + // Only create a wrapper if the node has an applyToGraph method + if (this.node.applyToGraph) { + this.applyToGraph = (...args) => this.node.applyToGraph?.(...args) + } + } + + /** Returns either the DTO itself, or the DTOs of the inner nodes of the subgraph. */ + getInnerNodes(): ExecutableLGraphNode[] { + return this.node.isSubgraphNode() + ? this.node.getInnerNodes(this.nodesByExecutionId, this.subgraphNodePath) + : [this] + } + + /** + * Resolves the executable node & link IDs for a given input slot. + * @param slot The slot index of the input. + * @param visited Leave empty unless overriding this method. + * A set of unique IDs, used to guard against infinite recursion. + * If overriding, ensure that the set is passed on all recursive calls. + * @returns The node and the origin ID / slot index of the output. + */ + resolveInput( + slot: number, + visited = new Set(), + type?: ISlotType + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[I]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving input ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + const input = this.inputs.at(slot) + if (!input) + throw new SlotIndexError( + `No input found for flattened id [${this.id}] slot [${slot}]` + ) + + // Nothing connected + if (input.linkId == null) return + + const link = this.graph.getLink(input.linkId) + if (!link) + throw new InvalidLinkError( + `No link found in parent graph for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const { subgraphNode } = this + + // Link goes up and out of this subgraph + if (subgraphNode && link.originIsIoNode) { + const subgraphNodeInput = subgraphNode.inputs.at(link.origin_slot) + if (!subgraphNodeInput) + throw new SlotIndexError( + `No input found for slot [${link.origin_slot}] ${input.name}` + ) + + // Nothing connected + const linkId = subgraphNodeInput.link + if (linkId == null) { + const id = subgraphNodeInput.widgetId + if (!id) return + + return { + node: this, + origin_id: this.id, + origin_slot: -1, + widgetInfo: { value: useWidgetValueStore().getWidget(id)?.value } + } + } + + if (!subgraphNode.graph) + throw new NullGraphError( + `SubgraphNode ${subgraphNode.id} has no graph during input resolution` + ) + const outerLink = subgraphNode.graph.getLink(linkId) + if (!outerLink) + throw new InvalidLinkError( + `No outer link found for slot [${link.origin_slot}] ${input.name}` + ) + + const subgraphNodeExecutionId: ExecutionId = + this.subgraphNodePath.join(':') + const subgraphNodeDto = this.nodesByExecutionId.get( + subgraphNodeExecutionId + ) + if (!subgraphNodeDto) + throw new Error( + `No subgraph node DTO found for id [${subgraphNodeExecutionId}]` + ) + + return subgraphNodeDto.resolveInput(outerLink.target_slot, visited) + } + + // Not part of a subgraph; use the original link + const outputNode = this.graph.getNodeById(link.origin_id) + if (!outputNode) + throw new InvalidLinkError( + `No input node found for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const outputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + outputNode.id + ].join(':') + const outputNodeDto = this.nodesByExecutionId.get(outputNodeExecutionId) + if (!outputNodeDto) + throw new Error( + `No output node DTO found for id [${outputNodeExecutionId}]` + ) + + return outputNodeDto.resolveOutput( + link.origin_slot, + type ?? input.type, + visited + ) + } + + /** + * Determines whether this output is a valid endpoint for a link (non-virtual, non-bypass). + * @param slot The slot index of the output. + * @param type The type of the input + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns The node and the origin ID / slot index of the output. + */ + resolveOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[O]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving output ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + // Muted nodes produce no output + if (this.mode === LGraphEventMode.NEVER) return + + // Upstreamed: Bypass nodes are bypassed using the first input with matching type + if (this.mode === LGraphEventMode.BYPASS) { + // Bypass nodes by finding first input with matching type + const matchingIndex = this._getBypassSlotIndex(slot, type) + + // No input types match - bypass not possible + if (matchingIndex === -1) { + console.warn( + `[ExecutableNodeDTO.resolveOutput] No input types match type [${type}] for id [${this.id}] slot [${slot}]`, + this + ) + return + } + + return this.resolveInput(matchingIndex, visited) + } + + const { node } = this + if (node.isSubgraphNode()) + return this._resolveSubgraphOutput(slot, type, visited) + + if (node.isVirtualNode) { + // Cross-graph virtual nodes (e.g. Set/Get) resolve their source directly. + const virtualSource = this.node.resolveVirtualOutput?.(slot) + if (virtualSource) { + const inputNodeDto = [...this.nodesByExecutionId.values()].find( + (dto) => + dto instanceof ExecutableNodeDTO && dto.node === virtualSource.node + ) + if (!inputNodeDto) + throw new Error( + `No DTO found for virtual source node [${virtualSource.node.id}]` + ) + + return inputNodeDto.resolveOutput(virtualSource.slot, type, visited) + } + const virtualLink = this.node.getInputLink(slot) + if (virtualLink) { + const { inputNode } = virtualLink.resolve(this.graph) + if (!inputNode) + throw new InvalidLinkError( + `Virtual node failed to resolve parent [${this.id}] slot [${slot}]` + ) + + const inputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + inputNode.id + ].join(':') + const inputNodeDto = this.nodesByExecutionId.get(inputNodeExecutionId) + if (!inputNodeDto) + throw new Error(`No input node DTO found for id [${inputNode.id}]`) + + return inputNodeDto.resolveInput(virtualLink.target_slot, visited, type) + } + + // Virtual nodes without a matching input should be discarded. + return + } + + return { + node: this, + origin_id: this.id, + origin_slot: slot + } + } + + /** + * Finds the index of the input slot on this node that matches the given output {@link slot} index. + * Used when bypassing nodes. + * @param slot The output slot index on this node + * @param type The type of the final target input (so type list matches are accurate) + * @returns The index of the input slot on this node, otherwise `-1`. + */ + private _getBypassSlotIndex(slot: number, type: ISlotType) { + const { inputs } = this + const oppositeInput = inputs[slot] + const outputType = this.node.outputs[slot].type + + // Any type short circuit - match slot ID, fallback to first slot + if (type === '*' || type === '') { + return inputs.length > slot ? slot : 0 + } + + // Prefer input with the same slot ID + if ( + oppositeInput && + LiteGraph.isValidConnection(oppositeInput.type, outputType) && + LiteGraph.isValidConnection(oppositeInput.type, type) + ) { + return slot + } + + // Preserve legacy behaviour; use exact match first. + const exactMatch = inputs.findIndex((input) => input.type === type) + if (exactMatch !== -1) return exactMatch + + // Find first matching slot - prefer exact type + return inputs.findIndex( + (input) => + LiteGraph.isValidConnection(input.type, outputType) && + LiteGraph.isValidConnection(input.type, type) + ) + } + + /** + * Resolves the link inside a subgraph node, from the subgraph IO node to the node inside the subgraph. + * @param slot The slot index of the output on the subgraph node. + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns A DTO for the node, and the origin ID / slot index of the output. + */ + private _resolveSubgraphOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const { node } = this + const output = node.outputs.at(slot) + + if (!output) + throw new SlotIndexError( + `No output found for flattened id [${this.id}] slot [${slot}]` + ) + if (!node.isSubgraphNode()) + throw new TypeError(`Node is not a subgraph node: ${node.id}`) + + // Link inside the subgraph + const innerResolved = node.resolveSubgraphOutputLink(slot) + if (!innerResolved) return + + const innerNode = innerResolved.outputNode + if (!innerNode) + throw new Error( + `No output node found for id [${this.id}] slot [${slot}] ${output.name}` + ) + + // Recurse into the subgraph + const innerNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + node.id, + innerNode.id + ].join(':') + const innerNodeDto = this.nodesByExecutionId.get(innerNodeExecutionId) + if (!innerNodeDto) + throw new Error( + `No inner node DTO found for id [${innerNodeExecutionId}]` + ) + + return innerNodeDto.resolveOutput( + innerResolved.link.origin_slot, + type, + visited + ) + } +} diff --git a/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__Subgraph.ts b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__Subgraph.ts new file mode 100644 index 00000000..e1f2f0b2 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__Subgraph.ts @@ -0,0 +1,3 @@ +// Re-export Subgraph and GraphOrSubgraph from LGraph.ts to maintain compatibility +// This is a temporary fix to resolve circular dependency issues +export { Subgraph, type GraphOrSubgraph } from '@/lib/litegraph/src/LGraph' diff --git a/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__SubgraphNode.ts b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__SubgraphNode.ts new file mode 100644 index 00000000..6ea9b179 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__lib__litegraph__src__subgraph__SubgraphNode.ts @@ -0,0 +1,948 @@ +import cloneDeep from 'es-toolkit/compat/cloneDeep' +import type { BaseLGraph, LGraph, SubgraphId } from '@/lib/litegraph/src/LGraph' +import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' +import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode' +import { LLink } from '@/lib/litegraph/src/LLink' +import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import type { + ISubgraphInput, + IWidgetLocator +} from '@/lib/litegraph/src/interfaces' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { INodeInputSlot, ISlotType } from '@/lib/litegraph/src/litegraph' +import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' +import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' +import { toNodeId } from '@/types/nodeId' +import type { SerializedNodeId } from '@/types/nodeId' +import type { + GraphOrSubgraph, + Subgraph +} from '@/lib/litegraph/src/subgraph/Subgraph' +import type { + ExportedSubgraphInstance, + ISerialisedNode +} from '@/lib/litegraph/src/types/serialisation' +import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' +import type { + IBaseWidget, + TWidgetValue +} from '@/lib/litegraph/src/types/widgets' +import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' +import { resolveConcretePromotedWidget } from '@/core/graph/subgraph/resolveConcretePromotedWidget' +import { resolveSubgraphInputTarget } from '@/core/graph/subgraph/resolveSubgraphInputTarget' +import { parsePreviewExposures } from '@/core/schemas/previewExposureSchema' +import { parseProxyWidgetErrorQuarantine } from '@/core/schemas/proxyWidgetQuarantineSchema' +import { usePreviewExposureStore } from '@/stores/previewExposureStore' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { createNodeLocatorId } from '@/types/nodeIdentification' +import type { WidgetId } from '@/types/widgetId' +import { widgetId } from '@/types/widgetId' + +import { ExecutableNodeDTO } from './ExecutableNodeDTO' +import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO' +import type { SubgraphInput } from './SubgraphInput' +import { createBitmapCache } from './svgBitmapCache' + +const workflowSvg = new Image() +workflowSvg.src = + "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='16' height='16'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-linecap='round' stroke-width='1.3' d='M9.18613 3.09999H6.81377M9.18613 12.9H7.55288c-3.08678 0-5.35171-2.99581-4.60305-6.08843l.3054-1.26158M14.7486 2.1721l-.5931 2.45c-.132.54533-.6065.92789-1.1508.92789h-2.2993c-.77173 0-1.33797-.74895-1.1508-1.5221l.5931-2.45c.132-.54533.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.74896 1.1508 1.52211Zm-8.3033 0-.59309 2.45c-.13201.54533-.60646.92789-1.15076.92789H2.4021c-.7717 0-1.33793-.74895-1.15077-1.5221l.59309-2.45c.13201-.54533.60647-.9279 1.15077-.9279h2.29935c.77169 0 1.33792.74896 1.15076 1.52211Zm8.3033 9.8-.5931 2.45c-.132.5453-.6065.9279-1.1508.9279h-2.2993c-.77173 0-1.33797-.749-1.1508-1.5221l.5931-2.45c.132-.5453.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.7489 1.1508 1.5221Z'/%3E%3C/svg%3E %3C/svg%3E" + +const workflowBitmapCache = createBitmapCache(workflowSvg, 32) + +export class SubgraphNode extends LGraphNode implements BaseLGraph { + declare inputs: (INodeInputSlot & Partial)[] + + override readonly type: SubgraphId + override readonly isVirtualNode = true as const + override graph: GraphOrSubgraph | null + + get rootGraph(): LGraph { + if (!this.graph) + throw new NullGraphError(`SubgraphNode ${this.id} has no graph`) + return this.graph.rootGraph + } + + get isDetached(): boolean { + return !this.graph + } + + override get displayType(): string { + return 'Subgraph node' + } + + override isSubgraphNode(): this is SubgraphNode { + return true + } + + declare widgets: IBaseWidget[] + + /** + * Retained as a no-op for extension compatibility: promoted host widgets are + * now store-backed and addressed by widgetId, so there is no view cache to + * invalidate. + */ + invalidatePromotedViews(): void {} + + private _eventAbortController = new AbortController() + + constructor( + graph: GraphOrSubgraph, + readonly subgraph: Subgraph, + instanceData: ExportedSubgraphInstance + ) { + super(subgraph.name, subgraph.id) + this.graph = graph + + Object.defineProperty(this, 'widgets', { + get: () => + this.inputs.flatMap((input) => { + const widget = this._projectPromotedWidget(input) + return widget ? [widget] : [] + }), + set: () => { + if (import.meta.env.DEV) + console.warn( + 'Cannot manually set widgets on SubgraphNode; use the promotion system.' + ) + }, + configurable: true, + enumerable: true + }) + + const subgraphEvents = this.subgraph.events + const { signal } = this._eventAbortController + + subgraphEvents.addEventListener( + 'input-added', + (e) => { + const subgraphInput = e.detail.input + const { name, type } = subgraphInput + const existingInput = this.inputs.find( + (input) => + input._subgraphSlot === subgraphInput || + (input._subgraphSlot && input._subgraphSlot.id === subgraphInput.id) + ) + if (existingInput) { + this._addSubgraphInputListeners(subgraphInput, existingInput) + const linkId = subgraphInput.linkIds[0] + if (linkId === undefined) return + + const link = this.subgraph.getLink(linkId) + if (!link) return + + const { inputNode, input } = link.resolve(subgraph) + if (!inputNode || !input) return + + const widget = inputNode.getWidgetFromSlot(input) + if (widget) + this._setWidget(subgraphInput, existingInput, widget, input.widget) + return + } + const input = this.addInput(name, type, { + _subgraphSlot: subgraphInput + }) + this.invalidatePromotedViews() + + this._addSubgraphInputListeners(subgraphInput, input) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-input', + (e) => { + const widget = e.detail.input._widget + if (widget) this.ensureWidgetRemoved(widget) + + this.removeInput(e.detail.index) + this.invalidatePromotedViews() + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'output-added', + (e) => { + const { name, type } = e.detail.output + this.addOutput(name, type) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-output', + (e) => { + this.removeOutput(e.detail.index) + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-input', + (e) => { + const { index, newName } = e.detail + const input = this.inputs.at(index) + if (!input) throw new Error('Subgraph input not found') + + input.label = newName + // Do NOT change input.widget.name — it is the stable internal + // identifier used by onGraphConfigured (widgetInputs.ts) to match + // inputs to widgets. Changing it to the display label would cause + // collisions when two promoted inputs share the same label. + if (input._widget) input._widget.label = newName + if (input.widgetId) { + const state = useWidgetValueStore().getWidget(input.widgetId) + if (state) state.label = newName + } + this.invalidatePromotedViews() + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.INPUT + }) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-output', + (e) => { + const { index, newName } = e.detail + const output = this.outputs.at(index) + if (!output) throw new Error('Subgraph output not found') + + output.label = newName + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.OUTPUT + }) + }, + { signal } + ) + + this.type = subgraph.id + this.configure(instanceData) + + this.addTitleButton({ + name: 'enter_subgraph', + text: '\uE93B', // Unicode for pi-window-maximize + yOffset: 0, // No vertical offset needed, button is centered + xOffset: -10, + fontSize: 16 + }) + } + + override onTitleButtonClick( + button: LGraphButton, + canvas: LGraphCanvas + ): void { + if (button.name === 'enter_subgraph') { + canvas.openSubgraph(this.subgraph, this) + } else { + super.onTitleButtonClick(button, canvas) + } + } + + private _projectPromotedWidget( + input: INodeInputSlot + ): IBaseWidget | undefined { + if (input._widget) return input._widget + + const id = input.widgetId + if (!id) return + + const store = useWidgetValueStore() + const widget: IBaseWidget = { + get name() { + return store.getWidget(id)?.name ?? input.name + }, + get label() { + return store.getWidget(id)?.label ?? input.label ?? input.name + }, + set label(next) { + const state = store.getWidget(id) + if (state) state.label = next + }, + get y() { + return store.getWidget(id)?.y ?? 0 + }, + set y(next) { + const state = store.getWidget(id) + if (state) state.y = next + }, + get type() { + return store.getWidget(id)?.type ?? 'text' + }, + get options() { + return store.getWidget(id)?.options ?? {} + }, + get value() { + const value = store.getWidget(id)?.value + return isWidgetValue(value) ? value : undefined + }, + set value(next) { + store.setValue(id, next) + }, + // Canvas edits operate on a transient concrete widget (toConcreteWidget), + // so the value setter above is never invoked; BaseWidget.setValue writes + // its own local state and then calls this callback, which is the only + // bridge back to the store. + callback(next) { + store.setValue(id, next) + } + } + Object.defineProperty(widget, 'widgetId', { + value: id, + enumerable: false, + configurable: true + }) + input._widget = widget + return input._widget + } + + private _addSubgraphInputListeners( + subgraphInput: SubgraphInput, + input: INodeInputSlot & Partial + ) { + input._subgraphSlot = subgraphInput + + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + input._listenerController = new AbortController() + const { signal } = input._listenerController + + subgraphInput.events.addEventListener( + 'input-connected', + (e) => { + input.shape = this.getSlotShape(subgraphInput, e.detail.input) + if (!e.detail.widget || !e.detail.node) return + + this._setWidget( + subgraphInput, + input, + e.detail.widget, + e.detail.input.widget + ) + }, + { signal } + ) + + subgraphInput.events.addEventListener( + 'input-disconnected', + () => { + this.invalidatePromotedViews() + input.shape = this.getSlotShape(subgraphInput) + + const connectedWidgets = subgraphInput.getConnectedWidgets() + if (connectedWidgets.length > 0) { + this._resolveInputWidget(subgraphInput, input) + this.invalidatePromotedViews() + return + } + + if (input._widget) this.ensureWidgetRemoved(input._widget) + if (input.widgetId) { + const id = input.widgetId + queueMicrotask(() => { + if (this.inputs.some((input) => input.widgetId === id)) return + useWidgetValueStore().deleteWidget(id) + }) + } + + delete input.pos + delete input.widget + delete input.widgetId + input._widget = undefined + this.invalidatePromotedViews() + }, + { signal } + ) + } + + private _rebindInputSubgraphSlots(): void { + this.invalidatePromotedViews() + + const subgraphSlots = [...this.subgraph.inputNode.slots] + const slotsBySignature = new Map() + const slotsByName = new Map() + + for (const slot of subgraphSlots) { + const signature = `${slot.name}:${String(slot.type)}` + const signatureSlots = slotsBySignature.get(signature) + if (signatureSlots) { + signatureSlots.push(slot) + } else { + slotsBySignature.set(signature, [slot]) + } + + const nameSlots = slotsByName.get(slot.name) + if (nameSlots) { + nameSlots.push(slot) + } else { + slotsByName.set(slot.name, [slot]) + } + } + + const assignedSlotIds = new Set() + const takeUnassignedSlot = ( + slots: SubgraphInput[] | undefined + ): SubgraphInput | undefined => { + if (!slots) return undefined + return slots.find((slot) => !assignedSlotIds.has(String(slot.id))) + } + + for (const input of this.inputs) { + const existingSlot = input._subgraphSlot + if ( + existingSlot && + this.subgraph.inputNode.slots.some((slot) => slot === existingSlot) + ) { + assignedSlotIds.add(String(existingSlot.id)) + continue + } + + const signature = `${input.name}:${String(input.type)}` + const matchedSlot = + takeUnassignedSlot(slotsBySignature.get(signature)) ?? + takeUnassignedSlot(slotsByName.get(input.name)) + + if (matchedSlot) { + input._subgraphSlot = matchedSlot + assignedSlotIds.add(String(matchedSlot.id)) + } else { + delete input._subgraphSlot + } + } + } + + override configure(info: ExportedSubgraphInstance): void { + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + } + + this.inputs.length = 0 + this.inputs.push( + ...this.subgraph.inputNode.slots.map((slot) => + Object.assign( + new NodeInputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + shape: this.getSlotShape(slot), + type: slot.type, + link: null + }, + this + ), + { + _subgraphSlot: slot + } + ) + ) + ) + this.invalidatePromotedViews() + + this.outputs.length = 0 + this.outputs.push( + ...this.subgraph.outputNode.slots.map( + (slot) => + new NodeOutputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + type: slot.type, + links: null + }, + this + ) + ) + ) + + super.configure(info) + this._applyPromotedWidgetValues(info.widgets_values) + } + + private _applyPromotedWidgetValues( + widgetValues: ExportedSubgraphInstance['widgets_values'] + ): void { + const quarantineValuesByInputName = this._readQuarantineHostValuesByName() + + let valueIndex = 0 + for (const input of this.inputs) { + if (!input.widgetId) continue + const value = + quarantineValuesByInputName.get(input.name) ?? + widgetValues?.[valueIndex] + if (value !== undefined) { + useWidgetValueStore().setValue(input.widgetId, value) + } + valueIndex += 1 + } + } + + private _readQuarantineHostValuesByName(): Map { + return new Map( + parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + .toReversed() + .flatMap(({ originalEntry: [sourceNodeId, name], hostValue }) => + sourceNodeId === '-1' && + hostValue !== undefined && + isWidgetValue(hostValue) + ? [[name, hostValue] as const] + : [] + ) + ) + } + + override _internalConfigureAfterSlots() { + this._rebindInputSubgraphSlots() + + this.inputs = this.inputs.filter((input) => input._subgraphSlot) + this.invalidatePromotedViews() + + this._hydratePreviewExposures() + + for (const input of this.inputs) { + const subgraphInput = input._subgraphSlot + if (!subgraphInput) { + console.warn( + `[SubgraphNode.configure] No subgraph input found for input ${input.name}, skipping` + ) + continue + } + + this._addSubgraphInputListeners(subgraphInput, input) + this._resolveInputWidget(subgraphInput, input) + } + } + + private _hydratePreviewExposures() { + const store = usePreviewExposureStore() + const rootGraphId = this.rootGraph.id + const hostLocator = String(this.id) + const rawProperty = this.properties.previewExposures + const hasExplicitProperty = Array.isArray(rawProperty) + const fromProperty = parsePreviewExposures(rawProperty) + if (fromProperty.length) { + store.setExposures(rootGraphId, hostLocator, fromProperty) + return + } + if (hasExplicitProperty) { + store.setExposures(rootGraphId, hostLocator, []) + return + } + const legacyKey = createNodeLocatorId(null, this.id) + const legacy = store.getExposures(rootGraphId, legacyKey) + if (legacy.length) { + store.setExposures(rootGraphId, hostLocator, [...legacy]) + return + } + store.setExposures(rootGraphId, hostLocator, []) + } + + rebuildInputWidgetBindings(): void { + this.invalidatePromotedViews() + + for (const input of this.inputs) { + delete input.widget + delete input.pos + delete input.widgetId + this._clearPromotedWidget(input) + const subgraphInput = input._subgraphSlot + if (!subgraphInput) continue + this._resolveInputWidget(subgraphInput, input) + } + + this.invalidatePromotedViews() + } + + private _resolveInputWidget( + subgraphInput: SubgraphInput, + input: INodeInputSlot + ) { + for (const linkId of subgraphInput.linkIds) { + const link = this.subgraph.getLink(linkId) + if (!link) { + console.warn( + `[SubgraphNode.configure] No link found for link ID ${linkId}`, + this + ) + continue + } + + const { inputNode } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + const targetInput = inputNode.inputs.find((inp) => inp.link === linkId) + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) + continue + } + + const widget = inputNode.getWidgetFromSlot(targetInput) + if (widget) { + this._setWidget(subgraphInput, input, widget, targetInput.widget) + break + } + + // Nested promotion: the source is itself a promoted subgraph input with + // no concrete widget. Resolve the deepest interior widget so this input + // still receives widget state and a widgetId. + const nested = this._resolveNestedPromotedSource(inputNode, targetInput) + if (nested) { + this._setWidget(subgraphInput, input, nested.widget, targetInput.widget) + break + } + } + } + + private _resolveNestedPromotedSource( + inputNode: LGraphNode, + targetInput: INodeInputSlot + ): { node: LGraphNode; widget: IBaseWidget } | undefined { + if (!inputNode.isSubgraphNode()) return undefined + + const target = resolveSubgraphInputTarget(inputNode, targetInput.name) + if (!target) return undefined + + const resolved = resolveConcretePromotedWidget( + inputNode, + target.nodeId, + target.widgetName + ) + return resolved.status === 'resolved' ? resolved.resolved : undefined + } + + private _setWidget( + subgraphInput: Readonly, + input: INodeInputSlot, + interiorWidget: Readonly, + inputWidget: IWidgetLocator | undefined + ) { + this.invalidatePromotedViews() + + this._clearPromotedWidget(input) + + input.widget ??= { name: subgraphInput.name } + input.widget.name = subgraphInput.name + if (inputWidget) Object.setPrototypeOf(input.widget, inputWidget) + + const id = widgetId(this.rootGraph.id, this.id, subgraphInput.name) + input.widgetId = id + useWidgetValueStore().registerWidget(id, { + type: interiorWidget.type, + value: interiorWidget.value, + options: cloneDeep(interiorWidget.options ?? {}), + label: input.label ?? subgraphInput.name, + serialize: interiorWidget.serialize, + disabled: interiorWidget.disabled, + isDOMWidget: + 'isDOMWidget' in interiorWidget && + typeof interiorWidget.isDOMWidget === 'boolean' + ? interiorWidget.isDOMWidget + : undefined + }) + input._widget = + this.createPromotedHostWidget(input, id, interiorWidget) ?? + this._projectPromotedWidget(input) + this._setConcreteSlots() + + this.subgraph.events.dispatch('widget-promoted', { + widget: interiorWidget, + subgraphNode: this + }) + } + + /** + * App-layer hook to build a promoted DOM widget; the default falls back to the + * store-backed projection. Litegraph core stays free of Vue/Pinia/DOM. + */ + protected createPromotedHostWidget( + _input: INodeInputSlot, + _id: WidgetId, + _sourceWidget: Readonly + ): IBaseWidget | undefined { + return undefined + } + + /** + * Runs the host widget's `onRemove` (unregistering DOM widgets) and clears it. + * Unlike {@link ensureWidgetRemoved}, dispatches no demotion event, so it is + * safe on re-resolution. + */ + private _clearPromotedWidget(input: INodeInputSlot): void { + input._widget?.onRemove?.() + input._widget = undefined + } + + override onAdded(_graph: LGraph): void { + this.invalidatePromotedViews() + } + + /** + * @param name The name of the input slot. + * @param type The type of the input slot. + * @param inputProperties Properties that are directly assigned to the created input. Default: a new, empty object. + * @returns The new input slot. + */ + override addInput>( + name: string, + type: ISlotType, + inputProperties: TInput = {} as TInput + ): INodeInputSlot & TInput { + return super.addInput(name, type, inputProperties) + } + + override getSlotFromWidget( + widget: IBaseWidget | undefined + ): INodeInputSlot | undefined { + if (widget?.widgetId) { + const promotedInput = this.inputs.find( + (input) => input.widgetId === widget.widgetId + ) + if (promotedInput) return promotedInput + } + return super.getSlotFromWidget(widget) + } + + override getWidgetFromSlot(slot: INodeInputSlot): IBaseWidget | undefined { + if (slot._widget) return slot._widget + return super.getWidgetFromSlot(slot) + } + + override getInputLink(slot: number): LLink | null { + const innerLink = this.subgraph.outputNode.slots[slot].getLinks().at(0) + if (!innerLink) { + console.warn( + `SubgraphNode.getInputLink: no inner link found for slot ${slot}` + ) + return null + } + + const newLink = LLink.create(innerLink) + newLink.origin_id = toNodeId(`${this.id}:${innerLink.origin_id}`) + newLink.origin_slot = innerLink.origin_slot + + return newLink + } + + /** + * @param slot The slot index + * @returns The resolved connections, or undefined if no input node is found. + */ + resolveSubgraphInputLinks(slot: number): ResolvedConnection[] { + const inputSlot = this.subgraph.inputNode.slots[slot] + const innerLinks = inputSlot.getLinks() + if (innerLinks.length === 0) { + console.warn( + `[SubgraphNode.resolveSubgraphInputLinks] No inner links found for input slot [${slot}] ${inputSlot.name}`, + this + ) + return [] + } + return innerLinks.map((link) => link.resolve(this.subgraph)) + } + + /** + * @param slot The slot index + * @returns The output node if found, otherwise undefined. + */ + resolveSubgraphOutputLink(slot: number): ResolvedConnection | undefined { + const outputSlot = this.subgraph.outputNode.slots[slot] + const innerLink = outputSlot.getLinks().at(0) + if (innerLink) { + return innerLink.resolve(this.subgraph) + } + console.warn( + `[SubgraphNode.resolveSubgraphOutputLink] No inner link found for output slot [${slot}] ${outputSlot.name}`, + this + ) + } + + override getInnerNodes( + executableNodes: Map, + subgraphNodePath: readonly SerializedNodeId[] = [], + nodes: ExecutableLGraphNode[] = [], + visited = new Set() + ): ExecutableLGraphNode[] { + if (visited.has(this)) { + const nodeInfo = `${this.id}${this.title ? ` (${this.title})` : ''}` + const subgraphInfo = `'${this.subgraph.name || 'Unnamed Subgraph'}'` + const depth = subgraphNodePath.length + throw new RecursionError( + `Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph ${subgraphInfo}. ` + + `This creates an infinite loop in the subgraph hierarchy.` + ) + } + visited.add(this) + + const subgraphInstanceIdPath = [...subgraphNodePath, this.id] + + const parentSubgraphNode = this.rootGraph + .resolveSubgraphIdPath(subgraphNodePath.map(toNodeId)) + .at(-1) + const subgraphNodeDto = new ExecutableNodeDTO( + this, + subgraphNodePath, + executableNodes, + parentSubgraphNode + ) + executableNodes.set(subgraphNodeDto.id, subgraphNodeDto) + + for (const node of this.subgraph.nodes) { + if ('getInnerNodes' in node && node.getInnerNodes) { + node.getInnerNodes( + executableNodes, + subgraphInstanceIdPath, + nodes, + new Set(visited) + ) + } else { + const aVeryRealNode = new ExecutableNodeDTO( + node, + subgraphInstanceIdPath, + executableNodes, + this + ) + executableNodes.set(aVeryRealNode.id, aVeryRealNode) + nodes.push(aVeryRealNode) + } + } + return nodes + } + + override removeWidget(widget: IBaseWidget): void { + this.ensureWidgetRemoved(widget) + } + + override ensureWidgetRemoved(widget: IBaseWidget): void { + widget.onRemove?.() + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + + override onRemoved(): void { + this._eventAbortController.abort() + + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + this._clearPromotedWidget(input) + } + } + override drawTitleBox( + ctx: CanvasRenderingContext2D, + { + scale, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + box_size = 10 + }: DrawTitleBoxOptions + ): void { + if (this.onDrawTitleBox) { + this.onDrawTitleBox(ctx, title_height, this.renderingSize, scale) + return + } + ctx.save() + ctx.fillStyle = '#3b82f6' + ctx.beginPath() + ctx.roundRect(6, -24.5, 22, 20, 5) + ctx.fill() + if (!low_quality) { + ctx.translate(25, 23) + ctx.scale(-1.5, 1.5) + ctx.drawImage( + workflowBitmapCache.get(), + 0, + -title_height, + box_size, + box_size + ) + } + ctx.restore() + } + + override serialize(): ISerialisedNode { + const serialized = super.serialize() + const serializedProperties = { ...(serialized.properties ?? {}) } + const rootGraphId = this.rootGraph.id + const hostLocator = String(this.id) + + const previewExposures = usePreviewExposureStore().getExposures( + rootGraphId, + hostLocator + ) + serializedProperties.previewExposures = previewExposures.map((entry) => ({ + ...entry + })) + + const quarantine = parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + if (quarantine.length === 0) { + delete serializedProperties.proxyWidgetErrorQuarantine + } else { + serializedProperties.proxyWidgetErrorQuarantine = quarantine.map( + (entry) => ({ ...entry }) + ) + } + + serialized.properties = serializedProperties + + const widgetValues = this.inputs.flatMap((input) => { + if (!input.widgetId) return [] + const value = useWidgetValueStore().getWidget(input.widgetId)?.value + return [isWidgetValue(value) ? value : undefined] + }) + + if (widgetValues.some((value) => value !== undefined)) { + serialized.widgets_values = widgetValues + } else { + delete serialized.widgets_values + } + + return serialized + } + + override clone() { + const clone = super.clone() + + // TODO: Consider deep cloning subgraphs here. + + return clone + } + getSlotShape(slot: SubgraphInput, extraInput?: INodeInputSlot) { + const shapes = slot.linkIds.map( + (id) => this.subgraph.links[id]?.resolve(this.subgraph)?.input?.shape + ) + if (extraInput) shapes.push(extraInput.shape) + return shapes.every((shape) => shape === shapes[0]) ? shapes[0] : undefined + } +} diff --git a/docs/hel-892/structure-reference/1.48.7__src__utils__executionUtil.ts b/docs/hel-892/structure-reference/1.48.7__src__utils__executionUtil.ts new file mode 100644 index 00000000..0b6ad406 --- /dev/null +++ b/docs/hel-892/structure-reference/1.48.7__src__utils__executionUtil.ts @@ -0,0 +1,160 @@ +import type { + ExecutableLGraphNode, + ExecutionId, + LGraph +} from '@/lib/litegraph/src/litegraph' +import { + ExecutableNodeDTO, + LGraphEventMode +} from '@/lib/litegraph/src/litegraph' +import type { + ComfyApiWorkflow, + ComfyWorkflowJSON +} from '@/platform/workflow/validation/schemas/workflowSchema' + +import { compressWidgetInputSlots } from './litegraphUtil' + +/** + * Converts the current graph workflow for sending to the API. + * @note Node widgets are updated before serialization to prepare queueing. + * + * @param graph The graph to convert. + * @param options The options for the conversion. + * - `sortNodes`: Whether to sort the nodes by execution order. + * @returns The workflow and node links + */ +export const graphToPrompt = async ( + graph: LGraph, + options: { sortNodes?: boolean } = {} +): Promise<{ workflow: ComfyWorkflowJSON; output: ComfyApiWorkflow }> => { + const { sortNodes = false } = options + + for (const node of graph.computeExecutionOrder(false)) { + const innerNodes = node.getInnerNodes + ? node.getInnerNodes(new Map()) + : [node] + for (const innerNode of innerNodes) { + if (innerNode.isVirtualNode) { + innerNode.applyToGraph?.() + } + } + } + + const workflow = graph.serialize({ sortNodes }) + + // Remove localized_name from the workflow + for (const node of workflow.nodes) { + for (const slot of node.inputs ?? []) { + delete slot.localized_name + } + for (const slot of node.outputs ?? []) { + delete slot.localized_name + } + } + + compressWidgetInputSlots(workflow) + workflow.extra ??= {} + workflow.extra.frontendVersion = __COMFYUI_FRONTEND_VERSION__ + + const nodeDtoMap = new Map() + for (const node of graph.computeExecutionOrder(false)) { + const dto: ExecutableLGraphNode = new ExecutableNodeDTO( + node, + [], + nodeDtoMap + ) + + nodeDtoMap.set(dto.id, dto) + + if ( + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + for (const innerNode of dto.getInnerNodes()) { + nodeDtoMap.set(innerNode.id, innerNode) + } + } + + const output: ComfyApiWorkflow = {} + // Process nodes in order of execution + for (const node of nodeDtoMap.values()) { + // Don't serialize muted nodes + if ( + node.isVirtualNode || + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + const inputs: ComfyApiWorkflow[string]['inputs'] = {} + const { widgets } = node + + // Store all widget values in the API prompt. + // Note: widget.options.serialize controls prompt inclusion (checked here). + // widget.serialize controls workflow persistence (checked by LGraphNode). + if (widgets) { + for (const [i, widget] of widgets.entries()) { + if (!widget.name || widget.options?.serialize === false) continue + + const widgetValue = widget.serializeValue + ? await widget.serializeValue(node, i) + : widget.value + // By default, Array values are reserved to represent node connections. + // We need to wrap the array as an object to avoid the misinterpretation + // of the array as a node connection. + // The backend automatically unwraps the object to an array during + // execution. + inputs[widget.name] = Array.isArray(widgetValue) + ? widget.type === 'curve' + ? { __type__: 'CURVE', __value__: widgetValue } + : { __value__: widgetValue } + : widgetValue + } + } + + // Store all node links + for (const [i, input] of node.inputs.entries()) { + const resolvedInput = node.resolveInput(i) + if (!resolvedInput) continue + + // Resolved to an actual widget value rather than a node connection + if (resolvedInput.widgetInfo) { + const { value } = resolvedInput.widgetInfo + inputs[input.name] = Array.isArray(value) ? { __value__: value } : value + continue + } + + inputs[input.name] = [ + String(resolvedInput.origin_id), + // @ts-expect-error link.origin_slot is already number. + parseInt(resolvedInput.origin_slot) + ] + } + + output[String(node.id)] = { + inputs, + // TODO(huchenlei): Filter out all nodes that cannot be mapped to a + // comfyClass. + class_type: node.comfyClass!, + // Ignored by the backend. + _meta: { + title: node.title + } + } + } + + // Remove inputs connected to removed nodes + for (const { inputs } of Object.values(output)) { + for (const [i, input] of Object.entries(inputs)) { + if (Array.isArray(input) && input.length === 2 && !output[input[0]]) { + delete inputs[i] + } + } + } + + return { workflow: workflow as ComfyWorkflowJSON, output } +} diff --git a/docs/hel-892/structure-reference/1.53.6__LICENSE b/docs/hel-892/structure-reference/1.53.6__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/1.53.6__src__extensions__core__widgetInputs.ts b/docs/hel-892/structure-reference/1.53.6__src__extensions__core__widgetInputs.ts new file mode 100644 index 00000000..5ee5a528 --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__extensions__core__widgetInputs.ts @@ -0,0 +1,675 @@ +import { intersection } from 'es-toolkit/compat' + +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { createWidgetRestorationState } from '@/lib/litegraph/src/LGraphNode' +import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { + INodeInputSlot, + INodeOutputSlot, + ISerialisedNode, + ISlotType, + LLink +} from '@/lib/litegraph/src/litegraph' +import type { IWidgetLocator } from '@/lib/litegraph/src/interfaces' +import { NodeSlot } from '@/lib/litegraph/src/node/NodeSlot' +import { outputHasLinks, outputLinks } from '@/lib/litegraph/src/node/slotLinks' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' +import { assetService } from '@/platform/assets/services/assetService' +import { createAssetWidget } from '@/platform/assets/utils/createAssetWidget' +import { + getComboSpecComboOptions, + isComboInputSpec +} from '@/schemas/nodeDefSchema' +import type { ComfyNodeDef, InputSpec } from '@/schemas/nodeDefSchema' +import { app } from '@/scripts/app' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import type { WidgetValue } from '@/types/simplifiedWidget' +import { + ComfyWidgets, + addValueControlWidgets, + isValidWidgetType +} from '@/scripts/widgets' +import { isPrimitiveNode } from '@/renderer/utils/nodeTypeGuards' +import { CONFIG, GET_CONFIG } from '@/services/litegraphService' +import { mergeInputSpec } from '@/utils/nodeDefUtil' +import { applyTextReplacements } from '@/utils/searchAndReplace' + +import { applyFirstWidgetValueToGraph } from './widgetValuePropagation' + +const replacePropertyName = 'Run widget replace on values' +export class PrimitiveNode extends LGraphNode { + controlValues?: WidgetValue[] + lastType?: string + static override category: string + constructor(title: string) { + super(title) + this.addOutput('connect to widget input', '*') + this.serialize_widgets = true + this.isVirtualNode = true + + if (!this.properties || !(replacePropertyName in this.properties)) { + this.addProperty(replacePropertyName, false, 'boolean') + } + } + + override applyToGraph(extraLinks: LLink[] = []) { + const sourceWidget = this.widgets?.[0] + const graph = this.graph + if (!sourceWidget || !graph) return + + let v = sourceWidget.value + if (v && this.properties[replacePropertyName]) { + v = applyTextReplacements(graph, v as string) + } + applyFirstWidgetValueToGraph(this, extraLinks, () => v) + } + + override refreshComboInNode(defs?: Record): void { + const widget = this.widgets?.[0] + if (widget?.type !== 'combo') return + + const newValues = this._resolveComboValues(defs) + if (newValues === undefined) return + + widget.options.values = newValues + + const value = widget.value + if ( + (typeof value !== 'string' && typeof value !== 'number') || + !newValues.includes(value) + ) { + widget.value = newValues[0] + widget.callback?.(widget.value) + } + } + + private _resolveComboValues( + defs?: Record + ): (string | number)[] | undefined { + const fromDefs = defs ? this._comboValuesFromDefs(defs) : undefined + if (fromDefs !== undefined) return fromDefs + + const slotWidget = this.outputs?.[0]?.widget + const config = slotWidget?.[GET_CONFIG]?.() + if (!config || !isComboInputSpec(config)) return undefined + + return getComboSpecComboOptions(config) + } + + private _comboValuesFromDefs( + defs: Record + ): (string | number)[] | undefined { + const graph = this.graph + const links = graph ? outputLinks(graph, this.id, 0) : [] + if (!graph || !links?.length) return undefined + + let values: (string | number)[] | undefined + for (const link of links) { + const targetNode = graph.getNodeById(link?.target_id) + const targetType = targetNode?.type + const targetInput = link + ? targetNode?.inputs[link.target_slot] + : undefined + const inputName = targetInput?.widget?.name ?? targetInput?.name + if (!targetType || !inputName) return undefined + + const def = defs[targetType] + const inputSpec = + def?.input?.required?.[inputName] ?? def?.input?.optional?.[inputName] + if (!inputSpec || !isComboInputSpec(inputSpec)) return undefined + + const options = getComboSpecComboOptions(inputSpec) + values = values === undefined ? options : intersection(values, options) + } + + return values + } + + override configure(serialisedNode: ISerialisedNode) { + const type = serialisedNode.outputs?.[0]?.type + super.configure(serialisedNode) + if (!this.graph || this.widgets?.length || typeof type !== 'string') return + + useWidgetValueStore().setNodeWidgetRestoration( + this.graph.rootGraph.id, + this.id, + createWidgetRestorationState(serialisedNode) + ) + } + + override onAfterGraphConfigured() { + if ( + this.graph && + outputHasLinks(this.graph, this.id, 0) && + !this.widgets?.length + ) { + this._onFirstConnection() + + // Merge values if required + this._mergeWidgetConfig() + } + } + + private _clearWidgetRestoration() { + if (this.graph) + useWidgetValueStore().clearNodeWidgetRestoration( + this.graph.rootGraph.id, + this.id + ) + } + + override onConnectionsChange( + _type: ISlotType, + _index: number, + connected: boolean + ) { + if (app.configuringGraph) { + // Dont run while the graph is still setting up + return + } + + const hasLinks = this.graph ? outputHasLinks(this.graph, this.id, 0) : false + if (connected) { + if (hasLinks && !this.widgets?.length) { + this._onFirstConnection() + } + } else { + // We may have removed a link that caused the constraints to change + this._mergeWidgetConfig() + + if (!hasLinks) { + this.onLastDisconnect() + } + } + } + + override onConnectOutput( + slot: number, + _type: string, + input: INodeInputSlot, + target_node: LGraphNode, + target_slot: number + ) { + // Fires before the link is made allowing us to reject it if it isn't valid + // No widget, we can't connect + if (!input.widget && !(input.type in ComfyWidgets)) { + return false + } + + if (this.graph && outputHasLinks(this.graph, this.id, slot)) { + const valid = this._isValidConnection(input) + if (valid) { + // On connect of additional outputs, copy our value to their widget + this.applyToGraph([{ target_id: target_node.id, target_slot } as LLink]) + } + return valid + } + + return true + } + + private _onFirstConnection(recreating = false) { + // First connection can fire before the graph is ready on initial load so random things can be missing + if (!this.graph) { + this.onLastDisconnect() + return + } + const [link] = outputLinks(this.graph, this.id, 0) + if (!link) { + if (outputHasLinks(this.graph, this.id, 0)) { + console.warn( + `PrimitiveNode ${this.id}: link store reports output 0 connected but no link resolves in the graph; resetting the widget.` + ) + } + this.onLastDisconnect() + return + } + + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode || !theirNode.inputs) return + + const input = theirNode.inputs[link.target_slot] + if (!input) return + + let widget: IWidgetLocator + if (!input.widget) { + const inputType = input.type + if (typeof inputType !== 'string' || !(inputType in ComfyWidgets)) return + widget = { name: input.name, [GET_CONFIG]: () => [inputType, {}] } //fake widget + } else { + widget = input.widget + } + + const config = widget[GET_CONFIG]?.() + if (!config) return + + const { type } = getWidgetType(config) + if (recreating || this.outputs[0].type !== type) + this._clearWidgetRestoration() + // Update our output to restrict to the widget type + this.outputs[0].type = type + this.outputs[0].name = type + this.outputs[0].widget = widget + + this._createWidget( + widget[CONFIG] ?? config, + theirNode, + widget.name, + recreating + ) + } + + private _createWidget( + inputData: InputSpec, + node: LGraphNode, + widgetName: string, + recreating: boolean + ) { + let type = inputData[0] + + if (type instanceof Array) { + type = 'COMBO' + } + + // Store current size as addWidget resizes the node + const [oldWidth, oldHeight] = this.size + let widget: IBaseWidget + const restoredValue = this.graph + ? useWidgetValueStore().getRestoredWidgetValue( + this.graph.rootGraph.id, + this.id, + 'value', + 0 + ) + : undefined + + try { + if ( + type === 'COMBO' && + assetService.shouldUseAssetBrowser(node.comfyClass, widgetName) + ) { + widget = this._createAssetWidget(node, widgetName, inputData) + const theirWidget = node.widgets?.find((w) => w.name === widgetName) + if (theirWidget) widget.value = theirWidget.value + if (restoredValue) widget.value = restoredValue.value + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + return + } + + if (isValidWidgetType(type)) { + widget = (ComfyWidgets[type](this, 'value', inputData, app) || {}) + .widget + } else { + // @ts-expect-error InputSpec is not typed correctly + widget = this.addWidget(type, 'value', null, () => {}, {}) + } + + if (node?.widgets && widget) { + const theirWidget = node.widgets.find((w) => w.name === widgetName) + if (theirWidget) { + widget.value = theirWidget.value + } + } + if (restoredValue) widget.value = restoredValue.value + + if ( + !inputData?.[1]?.control_after_generate && + (widget.type === 'number' || widget.type === 'combo') + ) { + addValueControlWidgets(this, widget, 'fixed', undefined, inputData) + if (this.widgets?.[1]) widget.linkedWidgets = [this.widgets[1]] + } + + // Restore any saved control values + const controlValues = this.controlValues + if ( + this.widgets && + this.lastType === this.widgets[0]?.type && + controlValues?.length === this.widgets.length - 1 + ) { + for (let i = 0; i < controlValues.length; i++) { + this.widgets[i + 1].value = controlValues[i] + } + } + + this._finalizeWidget(widget, oldWidth, oldHeight, recreating) + } finally { + this._clearWidgetRestoration() + } + } + + private _createAssetWidget( + targetNode: LGraphNode, + targetInputName: string, + inputData: InputSpec + ): IBaseWidget { + const defaultValue = inputData[1]?.default as string | undefined + return createAssetWidget({ + node: this, + widgetName: 'value', + nodeTypeForBrowser: targetNode.comfyClass ?? '', + inputNameForBrowser: targetInputName, + defaultValue + }) + } + + private _finalizeWidget( + widget: IBaseWidget, + oldWidth: number, + oldHeight: number, + recreating: boolean + ) { + widget.callback = useChainCallback(widget.callback, () => { + this.applyToGraph() + }) + + this.setSize([ + Math.max(this.size[0], oldWidth), + Math.max(this.size[1], oldHeight) + ]) + + if (!recreating) { + const sz = this.computeSize() + this.size = [Math.max(this.size[0], sz[0]), Math.max(this.size[1], sz[1])] + + requestAnimationFrame(() => { + this.onResize?.(this.size) + }) + } + } + + recreateWidget() { + const values = this.widgets?.map((w) => w.value) + this._removeWidgets() + this._onFirstConnection(!!values?.length) + if (values?.length && this.widgets) { + for (let i = 0; i < this.widgets.length; i++) + this.widgets[i].value = values[i] + } + return this.widgets?.[0] + } + + private _mergeWidgetConfig() { + // Merge widget configs if the node has multiple outputs + const output = this.outputs[0] + const links = this.graph ? outputLinks(this.graph, this.id, 0) : [] + + const hasConfig = !!output.widget?.[CONFIG] + if (hasConfig) { + delete output.widget?.[CONFIG] + } + + if (links.length < 2 && hasConfig) { + // Copy the widget options from the source + if (links.length) { + this.recreateWidget() + } + + return + } + const config1 = output.widget?.[GET_CONFIG]?.() + if (!config1) return + const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT' + if (!isNumber || !this.graph) return + + for (const link of links) { + const theirNode = this.graph.getNodeById(link.target_id) + if (!theirNode) continue + const theirInput = theirNode.inputs[link.target_slot] + + // Call is valid connection so it can merge the configs when validating + this._isValidConnection(theirInput, hasConfig) + } + } + + private _isValidConnection(input: INodeInputSlot, forceUpdate?: boolean) { + // Only allow connections where the configs match + const output = this.outputs?.[0] + const config2 = input.widget?.[GET_CONFIG]?.() + if (!config2) return false + + return !!mergeIfValid.call( + this, + output, + config2, + forceUpdate, + this.recreateWidget + ) + } + + private _removeWidgets() { + if (this.widgets) { + // Allow widgets to cleanup + for (const w of this.widgets) { + if (w.onRemove) { + w.onRemove() + } + } + + // Temporarily store the current values in case the node is being recreated + this.controlValues = [] + this.lastType = this.widgets[0]?.type + for (let i = 1; i < this.widgets.length; i++) { + this.controlValues.push(this.widgets[i].value) + } + setTimeout(() => { + delete this.lastType + delete this.controlValues + }, 15) + this.widgets.length = 0 + } + } + + onLastDisconnect() { + this._clearWidgetRestoration() + // We can't remove + re-add the output here as if you drag a link over the same link + // it removes, then re-adds, causing it to break + this.outputs[0].type = '*' + this.outputs[0].name = 'connect to widget input' + delete this.outputs[0].widget + + this._removeWidgets() + } +} + +export function getWidgetConfig( + slot: INodeInputSlot | INodeOutputSlot +): InputSpec { + return slot.widget?.[CONFIG] ?? slot.widget?.[GET_CONFIG]?.() ?? ['*', {}] +} + +function getConfig(this: LGraphNode, widgetName: string) { + const { nodeData } = this.constructor + return ( + nodeData?.input?.required?.[widgetName] ?? + nodeData?.input?.optional?.[widgetName] + ) +} + +/** + * Convert a widget to an input slot. + * @deprecated Widget to socket conversion is no longer necessary, as they co-exist now. + * @param node The node to convert the widget to an input slot for. + * @param widget The widget to convert to an input slot. + * @returns The input slot that was converted from the widget or undefined if the widget is not found. + */ +export function convertToInput( + node: LGraphNode, + widget: IBaseWidget +): INodeInputSlot | undefined { + console.warn( + 'Please remove call to convertToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return node.inputs.find((slot) => slot.widget?.name === widget.name) +} + +function getWidgetType(config: InputSpec) { + // Special handling for COMBO so we restrict links based on the entries + let type = config[0] + if (type instanceof Array) { + type = 'COMBO' + } + return { type } +} + +export function setWidgetConfig(slot: INodeInputSlot, config?: InputSpec) { + if (!slot.widget) return + if (config) { + slot.widget[GET_CONFIG] = () => config + } else { + delete slot.widget + } + + if (!(slot instanceof NodeSlot)) return + const { node } = slot + if (!node.graph) return + const link = node.getInputLink(node.inputs.indexOf(slot)) + if (!link) return + const originNode = node.graph.getNodeById(link.origin_id) + if (!originNode || !isPrimitiveNode(originNode)) return + if (config) { + originNode.recreateWidget() + } else if (!app.configuringGraph) { + originNode.disconnectOutput(0) + originNode.onLastDisconnect() + } +} + +export function mergeIfValid( + output: INodeOutputSlot | INodeInputSlot, + config2: InputSpec, + forceUpdate?: boolean, + recreateWidget?: () => void, + config1?: InputSpec +): { customConfig: InputSpec[1] } { + if (!config1) { + config1 = getWidgetConfig(output) + } + + const customSpec = mergeInputSpec(config1, config2) + + if (customSpec || forceUpdate) { + if (customSpec) { + // @ts-expect-error fixme ts strict error + output.widget[CONFIG] = customSpec + } + + // @ts-expect-error fixme ts strict error + const widget = recreateWidget?.call(this) + // When deleting a node this can be null + if (widget) { + // @ts-expect-error fixme ts strict error + const min = widget.options.min + // @ts-expect-error fixme ts strict error + const max = widget.options.max + // @ts-expect-error fixme ts strict error + if (min != null && widget.value < min) widget.value = min + // @ts-expect-error fixme ts strict error + if (max != null && widget.value > max) widget.value = max + // @ts-expect-error fixme ts strict error + widget.callback(widget.value) + } + } + + return { customConfig: customSpec?.[1] ?? {} } +} + +app.registerExtension({ + name: 'Comfy.WidgetInputs', + async beforeRegisterNodeDef( + nodeType: typeof LGraphNode, + _nodeData: ComfyNodeDef + ) { + // @ts-expect-error adding extra property + nodeType.prototype.convertWidgetToInput = function (this: LGraphNode) { + console.warn( + 'Please remove call to convertWidgetToInput. Widget to socket conversion is no longer necessary, as they co-exist now.' + ) + return false + } + + nodeType.prototype.onGraphConfigured = useChainCallback( + nodeType.prototype.onGraphConfigured, + function (this: LGraphNode) { + if (!this.inputs) return + this.widgets ??= [] + + for (const input of this.inputs) { + if (input.widget) { + const name = input.widget.name + if (!input.widget[GET_CONFIG]) { + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + + const w = this.widgets?.find((w) => w.name === name) + if (!w) { + this.removeInput(this.inputs.findIndex((i) => i === input)) + } + } + } + } + ) + + nodeType.prototype.onConfigure = useChainCallback( + nodeType.prototype.onConfigure, + function (this: LGraphNode) { + if (!app.configuringGraph && this.inputs) { + // On copy + paste of nodes, ensure that widget configs are set up + for (const input of this.inputs) { + if (input.widget && !input.widget[GET_CONFIG]) { + const name = input.widget.name + input.widget[GET_CONFIG] = () => getConfig.call(this, name) + } + } + } + } + ) + + // Double click a widget input to automatically attach a primitive + const origOnInputDblClick = nodeType.prototype.onInputDblClick + nodeType.prototype.onInputDblClick = function ( + this: LGraphNode, + ...[slot, ...args]: Parameters> + ) { + const r = origOnInputDblClick?.apply(this, [slot, ...args]) + + const input = this.inputs[slot] + if (!input.widget) { + // Not a widget input or already handled input + if (typeof input.type !== 'string' || !(input.type in ComfyWidgets)) { + return r //also Not a ComfyWidgets input or combo (do nothing) + } + } + + // Create a primitive node + const node = LiteGraph.createNode('PrimitiveNode') + const graph = app.canvas.graph + if (!node || !graph) return r + + graph?.add(node) + + // Calculate a position that won't directly overlap another node + const pos: [number, number] = [ + this.pos[0] - node.size[0] - 30, + this.pos[1] + ] + while (graph.getNodeOnPos(pos[0], pos[1], graph.nodes)) + pos[1] += LiteGraph.NODE_TITLE_HEIGHT + + node.pos = pos + node.connect(0, this, slot) + node.title = input.name + + return r + } + }, + registerCustomNodes() { + LiteGraph.registerNodeType( + 'PrimitiveNode', + Object.assign(PrimitiveNode, { + title: 'Primitive' + }) + ) + PrimitiveNode.category = 'utilities/primitive' + } +}) diff --git a/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__LLink.ts b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__LLink.ts new file mode 100644 index 00000000..23d360de --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__LLink.ts @@ -0,0 +1,730 @@ +import { + SUBGRAPH_INPUT_ID, + SUBGRAPH_OUTPUT_ID +} from '@/lib/litegraph/src/constants' +import type { SubgraphInput } from '@/lib/litegraph/src/subgraph/SubgraphInput' +import type { SubgraphOutput } from '@/lib/litegraph/src/subgraph/SubgraphOutput' +import { layoutStore } from '@/renderer/core/layout/store/layoutStore' +import { useLinkStore } from '@/stores/linkStore' +import { graphScopeOf, toOwningGraphId } from '@/types/graphScopeId' +import type { GraphScope } from '@/types/graphScopeId' +import { zeroUuid } from '@/utils/uuid' +import { toLinkId } from '@/types/linkId' +import { UNASSIGNED_NODE_ID, toNodeId, serializeNodeId } from '@/types/nodeId' +import { toRerouteId } from '@/types/rerouteId' + +import type { EndpointPatch } from '@/stores/linkStore' +import type { LinkId } from '@/types/linkId' +import type { LinkTopology } from '@/types/linkTopology' +import type { RerouteId } from '@/types/rerouteId' +import type { LGraph } from './LGraph' +import type { LGraphNode } from './LGraphNode' +import type { NodeId, SerializedNodeId } from '@/types/nodeId' +import type { Reroute } from './Reroute' +import type { + CanvasColour, + INodeInputSlot, + INodeOutputSlot, + ISlotType, + LinkNetwork, + LinkSegment, + Point, + ReadonlyLinkNetwork +} from './interfaces' +import type { Serialisable, SerialisableLLink } from './types/serialisation' +import { toRaw } from 'vue' + +export type { LinkId } from '@/types/linkId' +export type SerialisedLLinkArray = [ + id: number, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + type: ISlotType +] + +const linkByTopology = new WeakMap() + +let topologyFacadeDescriptors: PropertyDescriptorMap | undefined + +export function resolveLinkTopology(topology: LinkTopology): LLink | undefined { + return linkByTopology.get(toRaw(topology)) +} + +function defineEnumerableTopologyFacade(link: LLink): void { + topologyFacadeDescriptors ??= [ + 'id', + 'type', + 'origin_id', + 'origin_slot', + 'target_id', + 'target_slot', + 'parentId' + ].reduce((descriptors, key) => { + const descriptor = Object.getOwnPropertyDescriptor(LLink.prototype, key) + if (descriptor) descriptors[key] = { ...descriptor, enumerable: true } + return descriptors + }, {}) + Object.defineProperties(link, topologyFacadeDescriptors) +} + +// Resolved connection union; eliminates subgraph in/out as a possibility +export type ResolvedConnection = BaseResolvedConnection & + ( + | (ResolvedSubgraphInput & ResolvedNormalOutput) + | (ResolvedNormalInput & ResolvedSubgraphOutput) + | (ResolvedNormalInput & ResolvedNormalOutput) + ) + +interface BaseResolvedConnection { + link: LLink + /** The node on the input side of the link (owns {@link input}) */ + inputNode?: LGraphNode + /** The input the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: INodeInputSlot + /** The node on the output side of the link (owns {@link output}) */ + outputNode?: LGraphNode + /** The output the link is connected to (mutually exclusive with {@link subgraphInput}) */ + output?: INodeOutputSlot + /** The subgraph output the link is connected to (mutually exclusive with {@link input}) */ + subgraphOutput?: SubgraphOutput + /** The subgraph input the link is connected to (mutually exclusive with {@link output}) */ + subgraphInput?: SubgraphInput +} + +interface ResolvedNormalInput { + inputNode: LGraphNode | undefined + input: INodeInputSlot | undefined + subgraphOutput?: undefined +} + +interface ResolvedNormalOutput { + outputNode: LGraphNode | undefined + output: INodeOutputSlot | undefined + subgraphInput?: undefined +} + +interface ResolvedSubgraphInput { + inputNode?: undefined + /** The actual input slot the link is connected to (mutually exclusive with {@link subgraphOutput}) */ + input?: undefined + subgraphOutput: SubgraphOutput +} + +interface ResolvedSubgraphOutput { + outputNode?: undefined + output?: undefined + subgraphInput: SubgraphInput +} + +type BasicReadonlyNetwork = Pick< + ReadonlyLinkNetwork, + 'getNodeById' | 'links' | 'getLink' | 'inputNode' | 'outputNode' +> + +// this is the class in charge of storing link information +export class LLink implements LinkSegment, Serialisable { + static _drawDebug = false + + /** + * The link's topology state. Once registered with {@link useLinkStore}, + * this is the store's reactive proxy, so field writes are tracked. + */ + _state: LinkTopology + + /** The graph this link is registered with in {@link useLinkStore}, if any. */ + _graphScope?: GraphScope + + /** Link ID */ + get id() { + return this._state.id + } + + set id(value: LinkId) { + if (this._graphScope) { + if (value !== this._state.id) { + console.error('LiteGraph: refusing to change a registered link id') + } + return + } + Object.assign(this._state, { id: value }) + } + + get type() { + return this._state.type + } + + set type(value: ISlotType) { + this._state.type = value + } + + /** Output node ID */ + get origin_id() { + return this._state.originNodeId + } + + set origin_id(value: NodeId) { + this.updateEndpoints({ originNodeId: value }) + } + + /** Output slot index */ + get origin_slot() { + return this._state.originSlot + } + + set origin_slot(value: number) { + this.updateEndpoints({ originSlot: value }) + } + + /** Input node ID */ + get target_id() { + return this._state.targetNodeId + } + + set target_id(value: NodeId) { + this.updateEndpoints({ targetNodeId: value }) + } + + /** Input slot index */ + get target_slot() { + return this._state.targetSlot + } + + set target_slot(value: number) { + this.updateEndpoints({ targetSlot: value }) + } + + updateEndpoints(patch: EndpointPatch): void { + if (!this._graphScope) { + Object.assign(this._state, patch) + return + } + + const result = useLinkStore().updateEndpoint( + this._graphScope, + this._state, + patch + ) + if (!result.ok) + console.error('Failed to update link endpoints', result.error) + } + + get parentId() { + return this._state.parentId + } + + set parentId(value: RerouteId | undefined) { + this._state.parentId = value + } + + data?: number | string | boolean | { toToolTip?(): string } + _data?: unknown + /** Centre point of the link, calculated during render only - can be inaccurate */ + _pos: Point + /** @todo Clean up - never implemented in comfy. */ + _last_time?: number + /** The last canvas 2D path that was used to render this link */ + path?: Path2D + /** @inheritdoc */ + _centreAngle?: number + + /** @inheritdoc */ + _dragging?: boolean + + private _color?: CanvasColour | null + /** Custom colour for this link only */ + public get color(): CanvasColour | null | undefined { + return this._color + } + + public set color(value: CanvasColour) { + this._color = value === '' ? null : value + } + + public get isFloatingOutput(): boolean { + return this.origin_id === UNASSIGNED_NODE_ID && this.origin_slot === -1 + } + + public get isFloatingInput(): boolean { + return this.target_id === UNASSIGNED_NODE_ID && this.target_slot === -1 + } + + public get isFloating(): boolean { + return this.isFloatingOutput || this.isFloatingInput + } + + /** `true` if this link is connected to a subgraph input node (the actual origin is in a different graph). */ + get originIsIoNode(): boolean { + return this.origin_id === SUBGRAPH_INPUT_ID + } + + /** `true` if this link is connected to a subgraph output node (the actual target is in a different graph). */ + get targetIsIoNode(): boolean { + return this.target_id === SUBGRAPH_OUTPUT_ID + } + + constructor( + id: LinkId, + type: ISlotType, + origin_id: SerializedNodeId, + origin_slot: number, + target_id: SerializedNodeId, + target_slot: number, + parentId?: RerouteId + ) { + this._state = { + id, + graphId: toOwningGraphId(zeroUuid), + type, + originNodeId: toNodeId(origin_id), + originSlot: origin_slot, + targetNodeId: toNodeId(target_id), + targetSlot: target_slot, + parentId + } + this._data = null + this._pos = [0, 0] + defineEnumerableTopologyFacade(this) + } + + /** @deprecated Use {@link LLink.create} */ + static createFromArray(data: SerialisedLLinkArray): LLink { + return new LLink( + toLinkId(data[0]), + data[5], + data[1], + data[2], + data[3], + data[4] + ) + } + + /** + * LLink static factory: creates a new LLink from the provided data. + * @param data Serialised LLink data to create the link from + * @returns A new LLink + */ + static create(data: SerialisableLLink): LLink { + return new LLink( + toLinkId(data.id), + data.type, + data.origin_id, + data.origin_slot, + data.target_id, + data.target_slot, + data.parentId === undefined ? undefined : toRerouteId(data.parentId) + ) + } + + /** + * Gets all reroutes from the output slot to this segment. If this segment is a reroute, it will not be included. + * @returns An ordered array of all reroutes from the node output to + * this reroute or the reroute before it. Otherwise, an empty array. + */ + static getReroutes( + network: Pick, + linkSegment: LinkSegment + ): Reroute[] { + if (linkSegment.parentId === undefined) return [] + return network.reroutes.get(linkSegment.parentId)?.getReroutes() ?? [] + } + + static getFirstReroute( + network: Pick, + linkSegment: LinkSegment + ): Reroute | undefined { + return LLink.getReroutes(network, linkSegment).at(0) + } + + /** + * Finds the reroute in the chain after the provided reroute ID. + * @param network The network this link belongs to + * @param linkSegment The starting point of the search (input side). + * Typically the LLink object itself, but can be any link segment. + * @param rerouteId The matching reroute will have this set as its {@link parentId}. + * @returns The reroute that was found, `undefined` if no reroute was found, or `null` if an infinite loop was detected. + */ + static findNextReroute( + network: Pick, + linkSegment: LinkSegment, + rerouteId: RerouteId + ): Reroute | null | undefined { + if (linkSegment.parentId === undefined) return + return network.reroutes + .get(linkSegment.parentId) + ?.findNextReroute(rerouteId) + } + + /** + * Gets the origin node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the origin node of + * @returns The origin node of the link, or `undefined` if the link is not found or the origin node is not found + */ + static getOriginNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.origin_id + return network.getNodeById(id) ?? undefined + } + + /** + * Gets the target node of a link. + * @param network The network to search + * @param linkId The ID of the link to get the target node of + * @returns The target node of the link, or `undefined` if the link is not found or the target node is not found + */ + static getTargetNode( + network: BasicReadonlyNetwork, + linkId: LinkId + ): LGraphNode | undefined { + const id = network.links.get(linkId)?.target_id + return network.getNodeById(id) ?? undefined + } + + /** + * Resolves a link ID to the link, node, and slot objects. + * @param linkId The {@link id} of the link to resolve + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + static resolve( + linkId: LinkId | null | undefined, + network: BasicReadonlyNetwork + ): ResolvedConnection | undefined { + return network.getLink(linkId)?.resolve(network) + } + + /** + * Resolves a list of link IDs to the link, node, and slot objects. + * Discards invalid link IDs. + * @param linkIds An iterable of link {@link id}s to resolve + * @param network The link network to search + * @returns An array of resolved connections. If a link is not found, it is not included in the array. + * @see {@link LLink.resolve} + */ + static resolveMany( + linkIds: Iterable, + network: BasicReadonlyNetwork + ): ResolvedConnection[] { + const resolved: ResolvedConnection[] = [] + for (const id of linkIds) { + const r = network.getLink(id)?.resolve(network) + if (r) resolved.push(r) + } + return resolved + } + + /** + * Resolves the primitive ID values stored in the link to the referenced objects. + * @param network The link network to search + * @returns An object containing the input and output nodes, as well as the input and output slots. + * @remarks This method is heavier than others; it will always resolve all objects. + * Whilst the performance difference should in most cases be negligible, + * it is recommended to use simpler methods where appropriate. + */ + resolve(network: BasicReadonlyNetwork): ResolvedConnection { + const inputNode = + this.target_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.target_id) ?? undefined) + const input = inputNode?.inputs[this.target_slot] + const subgraphInput = this.originIsIoNode + ? network.inputNode?.slots[this.origin_slot] + : undefined + if (subgraphInput) { + return { inputNode, input, subgraphInput, link: this } + } + + const outputNode = + this.origin_id === UNASSIGNED_NODE_ID + ? undefined + : (network.getNodeById(this.origin_id) ?? undefined) + const output = outputNode?.outputs[this.origin_slot] + const subgraphOutput = this.targetIsIoNode + ? network.outputNode?.slots[this.target_slot] + : undefined + if (subgraphOutput) { + return { + outputNode, + output, + subgraphInput: undefined, + subgraphOutput, + link: this + } + } + + return { + inputNode, + outputNode, + input, + output, + subgraphInput, + subgraphOutput, + link: this + } + } + + configure(o: LLink | SerialisedLLinkArray) { + if (Array.isArray(o)) { + this.id = toLinkId(o[0]) + this.updateEndpoints({ + originNodeId: toNodeId(o[1]), + originSlot: o[2], + targetNodeId: toNodeId(o[3]), + targetSlot: o[4] + }) + this.type = o[5] + } else { + this.id = o.id + this.type = o.type + this.updateEndpoints({ + originNodeId: o.origin_id, + originSlot: o.origin_slot, + targetNodeId: o.target_id, + targetSlot: o.target_slot + }) + this.parentId = o.parentId + } + } + + /** + * Checks if the specified node id and output index are this link's origin (output side). + * @param nodeId ID of the node to check + * @param outputIndex The array index of the node output + * @returns `true` if the origin matches, otherwise `false`. + */ + hasOrigin(nodeId: SerializedNodeId, outputIndex: number): boolean { + return ( + this.origin_id === toNodeId(nodeId) && this.origin_slot === outputIndex + ) + } + + /** + * Checks if the specified node id and input index are this link's target (input side). + * @param nodeId ID of the node to check + * @param inputIndex The array index of the node input + * @returns `true` if the target matches, otherwise `false`. + */ + hasTarget(nodeId: SerializedNodeId, inputIndex: number): boolean { + return ( + this.target_id === toNodeId(nodeId) && this.target_slot === inputIndex + ) + } + + /** + * Creates a floating link from this link. + * @param slotType The side of the link that is still connected + * @param parentId The parent reroute ID of the link + * @returns A new LLink that is floating + */ + toFloating(slotType: 'input' | 'output', parentId: RerouteId): LLink { + const exported = this.asSerialisable() + exported.id = toLinkId(-1) + exported.parentId = parentId + + if (slotType === 'input') { + exported.origin_id = UNASSIGNED_NODE_ID + exported.origin_slot = -1 + } else { + exported.target_id = UNASSIGNED_NODE_ID + exported.target_slot = -1 + } + + return LLink.create(exported) + } + + /** + * Disconnects a link and removes it from the graph, cleaning up any reroutes that are no longer used + * @param network The container (LGraph) where reroutes should be updated + * @param keepReroutes If `undefined`, reroutes will be automatically removed if no links remain. + * If `input` or `output`, reroutes will not be automatically removed, and retain a connection to the input or output, respectively. + */ + disconnect(network: LinkNetwork, keepReroutes?: 'input' | 'output'): void { + const reroutes = LLink.getReroutes(network, this) + + const lastReroute = reroutes.at(-1) + + // When floating from output, 1-to-1 ratio of floating link to final reroute (tree-like) + const outputFloating = + keepReroutes === 'output' && + lastReroute !== undefined && + (lastReroute.linkIds.size === 0 || + (lastReroute.linkIds.size === 1 && lastReroute.linkIds.has(this.id))) && + lastReroute.floatingLinkIds.size === 0 + + // When floating from inputs, the final (input side) reroute may have many floating links + if (outputFloating || (keepReroutes === 'input' && lastReroute)) { + const newLink = LLink.create(this) + newLink.id = toLinkId(-1) + + if (keepReroutes === 'input') { + newLink.origin_id = UNASSIGNED_NODE_ID + newLink.origin_slot = -1 + + lastReroute.floating = { slotType: 'input' } + } else { + newLink.target_id = UNASSIGNED_NODE_ID + newLink.target_slot = -1 + + lastReroute.floating = { slotType: 'output' } + } + + network.addFloatingLink(newLink) + } + + if (network.links.get(this.id) === this) network.links.delete(this.id) + unregisterLinkTopology(this) + layoutStore.deleteLinkLayout(this.id) + + for (const reroute of reroutes) { + if (!keepReroutes && !reroute.totalLinks) { + network._removeReroute(reroute.id) + } + } + } + + /** + * @deprecated Prefer {@link LLink.asSerialisable} (returns an object, not an array) + * @returns An array representing this LLink + */ + serialize(): SerialisedLLinkArray { + return [ + this.id, + serializeNodeId(this.origin_id), + this.origin_slot, + serializeNodeId(this.target_id), + this.target_slot, + this.type + ] + } + + asSerialisable(): SerialisableLLink { + const copy: SerialisableLLink = { + id: this.id, + origin_id: serializeNodeId(this.origin_id), + origin_slot: this.origin_slot, + target_id: serializeNodeId(this.target_id), + target_slot: this.target_slot, + type: this.type + } + if (this.parentId !== undefined) copy.parentId = this.parentId + return copy + } +} + +/** + * Finds the floating links attached to a slot. A floating link has exactly + * one assigned endpoint, so its attachment is fully encoded in its own + * origin/target fields; nothing is stored on the slot. + * @param network The network whose floating links to search + * @param side Which side of the slot's node the links attach to + * @param nodeId The node (or subgraph IO node id) owning the slot + * @param slot The slot index + */ +export function slotFloatingLinks( + network: Pick, + side: 'input' | 'output', + nodeId: NodeId, + slot: number +): LLink[] { + const result: LLink[] = [] + for (const link of network.floatingLinks.values()) { + const attached = + side === 'input' + ? link.target_id === nodeId && link.target_slot === slot + : link.origin_id === nodeId && link.origin_slot === slot + if (attached) result.push(link) + } + return result +} + +/** + * Registers a link's topology into {@link useLinkStore} and adopts the + * store's reactive proxy as {@link LLink._state}, so the store and the link + * always agree and field writes are tracked. Call this at every site that + * adds a link to a graph's link map (or floating link map). + * + * {@link LLink._graphScope} is only set when the store keeps this link's state: + * a link that loses a first-wins id collision stays detached, so its writes + * and removal cannot corrupt the winner's registration. + * @param graph The graph (or subgraph) the link belongs to + * @param link The link to register + */ +export function registerLinkTopology( + graph: Pick, + link: LLink +): boolean { + if (link.id === toLinkId(-1)) return false + const scope = graphScopeOf(graph) + const registered = useLinkStore().registerLink(scope, link._state) + if (!registered) return false + adoptLinkTopology(link, scope, registered) + return true +} + +export function replaceLinkTopology( + graph: Pick, + incumbent: LLink | undefined, + replacement: LLink +): boolean { + if (replacement.id === toLinkId(-1)) return false + const scope = graphScopeOf(graph) + const registered = useLinkStore().replaceLink( + scope, + incumbent?._state, + replacement._state + ) + if (!registered) return false + if (incumbent) { + linkByTopology.delete(toRaw(incumbent._state)) + incumbent._graphScope = undefined + } + adoptLinkTopology(replacement, scope, registered) + return true +} + +function adoptLinkTopology( + link: LLink, + scope: GraphScope, + registered: LinkTopology +): void { + link._state = registered + link._graphScope = scope + linkByTopology.set(toRaw(registered), link) +} + +/** + * Removes a link's topology from {@link useLinkStore} and detaches the link. + * No-op for links that never won registration ({@link LLink._graphScope} unset), + * so a first-wins collision loser cannot remove the winner's entry. + * @param link The link to unregister + */ +export function unregisterLinkTopology(link: LLink): void { + if (!link._graphScope) return + useLinkStore().deleteLink(link._graphScope, link._state) + linkByTopology.delete(toRaw(link._state)) + link._graphScope = undefined +} + +/** + * Unregisters every link and floating link a graph owns. Used when a graph's + * links leave the store without a whole-bucket wipe: subgraph-definition + * removal, and clearing a graph that shares its bucket with other graphs. + * @param graph The graph whose links should be unregistered + */ +export function unregisterAllLinkTopologies( + graph: Pick +): void { + for (const link of [ + ...graph.links.values(), + ...graph.floatingLinks.values() + ]) { + unregisterLinkTopology(link) + } +} diff --git a/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts new file mode 100644 index 00000000..560adac9 --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts @@ -0,0 +1,431 @@ +import { inputLinkId } from '@/lib/litegraph/src/node/slotLinks' +import type { LGraph } from '@/lib/litegraph/src/LGraph' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { SerializedNodeId } from '@/types/nodeId' +import type { LinkId } from '@/lib/litegraph/src/LLink' +import { InvalidLinkError } from '@/lib/litegraph/src/infrastructure/InvalidLinkError' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import { SlotIndexError } from '@/lib/litegraph/src/infrastructure/SlotIndexError' +import type { ISlotType } from '@/lib/litegraph/src/interfaces' +import { LGraphEventMode, LiteGraph } from '@/lib/litegraph/src/litegraph' + +import type { Subgraph } from './Subgraph' +import type { SubgraphNode } from './SubgraphNode' + +export type ExecutionId = string + +/** + * Interface describing the data transfer objects used when compiling a graph for execution. + */ +export type ExecutableLGraphNode = Omit< + ExecutableNodeDTO, + 'graph' | 'node' | 'subgraphNode' +> + +/** + * The end result of resolving a DTO input. + * When a widget value is returned, {@link widgetInfo} is present and {@link origin_slot} is `-1`. + */ +type ResolvedInput = { + /** DTO for the node that the link originates from. */ + node: ExecutableLGraphNode + /** Full unique execution ID of the node that the link originates from. In the case of a widget value, this is the ID of the subgraph node. */ + origin_id: ExecutionId + /** The slot index of the output on the node that the link originates from. `-1` when widget value is set. */ + origin_slot: number + /** Boxed widget value (e.g. for widgets). If this box is `undefined`, then an input link is connected, and widget values from the subgraph node are ignored. */ + widgetInfo?: { value: unknown } +} + +/** + * Concrete implementation of {@link ExecutableLGraphNode}. + * @remarks This is the class that is used to create the data transfer objects for executable nodes. + */ +export class ExecutableNodeDTO implements ExecutableLGraphNode { + applyToGraph?( + ...args: Parameters> + ): ReturnType> + + /** The graph that this node is a part of. */ + readonly graph: LGraph | Subgraph + + inputs: { linkId: LinkId | null; name: string; type: ISlotType }[] + + /** Backing field for {@link id}. */ + private _id: ExecutionId + + /** + * The path to the actual node through subgraph instances, represented as a list of all subgraph node IDs (instances), + * followed by the actual original node ID within the subgraph. Each segment is separated by `:`. + * + * e.g. `1:2:3`: + * - `1` is the node ID of the first subgraph node in the parent workflow + * - `2` is the node ID of the second subgraph node in the first subgraph + * - `3` is the node ID of the actual node in the subgraph definition + */ + get id() { + return this._id + } + + get type() { + return this.node.type + } + + get title() { + return this.node.title + } + + get mode() { + return this.node.mode + } + + get comfyClass() { + return this.node.comfyClass + } + + get isVirtualNode() { + return this.node.isVirtualNode + } + + get widgets() { + return this.node.widgets + } + + get subgraphId() { + return this.subgraphNode?.subgraph.id + } + + constructor( + /** The actual node that this DTO wraps. */ + readonly node: LGraphNode | SubgraphNode, + /** A list of subgraph instance node IDs from the root graph to the containing instance. @see {@link id} */ + readonly subgraphNodePath: readonly SerializedNodeId[], + /** A flattened map of all DTOs in this node network. Subgraph instances have been expanded into their inner nodes. */ + readonly nodesByExecutionId: Map, + /** The actual subgraph instance that contains this node, otherwise undefined. */ + readonly subgraphNode?: SubgraphNode + ) { + if (!node.graph) throw new NullGraphError() + + // Set the internal ID of the DTO + this._id = [...this.subgraphNodePath, this.node.id].join(':') + this.graph = node.graph + this.inputs = this.node.inputs.map((x, index) => ({ + linkId: inputLinkId(node.graph!, node.id, index) ?? null, + name: x.name, + type: x.type + })) + + // Only create a wrapper if the node has an applyToGraph method + if (this.node.applyToGraph) { + this.applyToGraph = (...args) => this.node.applyToGraph?.(...args) + } + } + + /** Returns either the DTO itself, or the DTOs of the inner nodes of the subgraph. */ + getInnerNodes(): ExecutableLGraphNode[] { + return this.node.isSubgraphNode() + ? this.node.getInnerNodes(this.nodesByExecutionId, this.subgraphNodePath) + : [this] + } + + /** + * Resolves the executable node & link IDs for a given input slot. + * @param slot The slot index of the input. + * @param visited Leave empty unless overriding this method. + * A set of unique IDs, used to guard against infinite recursion. + * If overriding, ensure that the set is passed on all recursive calls. + * @returns The node and the origin ID / slot index of the output. + */ + resolveInput( + slot: number, + visited = new Set(), + type?: ISlotType + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[I]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving input ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + const input = this.inputs.at(slot) + if (!input) + throw new SlotIndexError( + `No input found for flattened id [${this.id}] slot [${slot}]` + ) + + // Nothing connected + if (input.linkId == null) return + + const link = this.graph.getLink(input.linkId) + if (!link) + throw new InvalidLinkError( + `No link found in parent graph for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const { subgraphNode } = this + + // Link goes up and out of this subgraph + if (subgraphNode && link.originIsIoNode) { + const subgraphNodeInput = subgraphNode.inputs.at(link.origin_slot) + if (!subgraphNodeInput) + throw new SlotIndexError( + `No input found for slot [${link.origin_slot}] ${input.name}` + ) + + if (!subgraphNode.graph) + throw new NullGraphError( + `SubgraphNode ${subgraphNode.id} has no graph during input resolution` + ) + // Nothing connected + const linkId = + inputLinkId(subgraphNode.graph, subgraphNode.id, link.origin_slot) ?? + null + if (linkId === null) { + const id = subgraphNodeInput.widgetId + if (!id) return + + return { + node: this, + origin_id: this.id, + origin_slot: -1, + widgetInfo: { value: useWidgetValueStore().getWidget(id)?.value } + } + } + + const outerLink = subgraphNode.graph.getLink(linkId) + if (!outerLink) + throw new InvalidLinkError( + `No outer link found for slot [${link.origin_slot}] ${input.name}` + ) + + const subgraphNodeExecutionId: ExecutionId = + this.subgraphNodePath.join(':') + const subgraphNodeDto = this.nodesByExecutionId.get( + subgraphNodeExecutionId + ) + if (!subgraphNodeDto) + throw new Error( + `No subgraph node DTO found for id [${subgraphNodeExecutionId}]` + ) + + return subgraphNodeDto.resolveInput(outerLink.target_slot, visited) + } + + // Not part of a subgraph; use the original link + const outputNode = this.graph.getNodeById(link.origin_id) + if (!outputNode) + throw new InvalidLinkError( + `No input node found for id [${this.id}] slot [${slot}] ${input.name}` + ) + + const outputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + outputNode.id + ].join(':') + const outputNodeDto = this.nodesByExecutionId.get(outputNodeExecutionId) + if (!outputNodeDto) + throw new Error( + `No output node DTO found for id [${outputNodeExecutionId}]` + ) + + return outputNodeDto.resolveOutput( + link.origin_slot, + type ?? input.type, + visited + ) + } + + /** + * Determines whether this output is a valid endpoint for a link (non-virtual, non-bypass). + * @param slot The slot index of the output. + * @param type The type of the input + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns The node and the origin ID / slot index of the output. + */ + resolveOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const uniqueId = `${this.subgraphNode?.subgraph.id}:${this.node.id}[O]${slot}` + if (visited.has(uniqueId)) { + const nodeInfo = `${this.node.id}${this.node.title ? ` (${this.node.title})` : ''}` + const pathInfo = + this.subgraphNodePath.length > 0 + ? ` at path ${this.subgraphNodePath.join(':')}` + : '' + throw new RecursionError( + `Circular reference detected while resolving output ${slot} of node ${nodeInfo}${pathInfo}. ` + + `This creates an infinite loop in link resolution. UniqueID: [${uniqueId}]` + ) + } + visited.add(uniqueId) + + // Muted nodes produce no output + if (this.mode === LGraphEventMode.NEVER) return + + // Upstreamed: Bypass nodes are bypassed using the first input with matching type + if (this.mode === LGraphEventMode.BYPASS) { + // Bypass nodes by finding first input with matching type + const matchingIndex = this._getBypassSlotIndex(slot, type) + + // No input types match - bypass not possible + if (matchingIndex === -1) { + console.warn( + `[ExecutableNodeDTO.resolveOutput] No input types match type [${type}] for id [${this.id}] slot [${slot}]`, + this + ) + return + } + + return this.resolveInput(matchingIndex, visited) + } + + const { node } = this + if (node.isSubgraphNode()) + return this._resolveSubgraphOutput(slot, type, visited) + + if (node.isVirtualNode) { + // Cross-graph virtual nodes (e.g. Set/Get) resolve their source directly. + const virtualSource = this.node.resolveVirtualOutput?.(slot) + if (virtualSource) { + const inputNodeDto = [...this.nodesByExecutionId.values()].find( + (dto) => + dto instanceof ExecutableNodeDTO && dto.node === virtualSource.node + ) + if (!inputNodeDto) + throw new Error( + `No DTO found for virtual source node [${virtualSource.node.id}]` + ) + + return inputNodeDto.resolveOutput(virtualSource.slot, type, visited) + } + const virtualLink = this.node.getInputLink(slot) + if (virtualLink) { + const { inputNode } = virtualLink.resolve(this.graph) + if (!inputNode) + throw new InvalidLinkError( + `Virtual node failed to resolve parent [${this.id}] slot [${slot}]` + ) + + const inputNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + inputNode.id + ].join(':') + const inputNodeDto = this.nodesByExecutionId.get(inputNodeExecutionId) + if (!inputNodeDto) + throw new Error(`No input node DTO found for id [${inputNode.id}]`) + + return inputNodeDto.resolveInput(virtualLink.target_slot, visited, type) + } + + // Virtual nodes without a matching input should be discarded. + return + } + + return { + node: this, + origin_id: this.id, + origin_slot: slot + } + } + + /** + * Finds the index of the input slot on this node that matches the given output {@link slot} index. + * Used when bypassing nodes. + * @param slot The output slot index on this node + * @param type The type of the final target input (so type list matches are accurate) + * @returns The index of the input slot on this node, otherwise `-1`. + */ + private _getBypassSlotIndex(slot: number, type: ISlotType) { + const { inputs } = this + const oppositeInput = inputs[slot] + const outputType = this.node.outputs[slot].type + + // Any type short circuit - match slot ID, fallback to first slot + if (type === '*' || type === '') { + return inputs.length > slot ? slot : 0 + } + + // Prefer input with the same slot ID + if ( + oppositeInput && + LiteGraph.isValidConnection(oppositeInput.type, outputType) && + LiteGraph.isValidConnection(oppositeInput.type, type) + ) { + return slot + } + + // Preserve legacy behaviour; use exact match first. + const exactMatch = inputs.findIndex((input) => input.type === type) + if (exactMatch !== -1) return exactMatch + + // Find first matching slot - prefer exact type + return inputs.findIndex( + (input) => + LiteGraph.isValidConnection(input.type, outputType) && + LiteGraph.isValidConnection(input.type, type) + ) + } + + /** + * Resolves the link inside a subgraph node, from the subgraph IO node to the node inside the subgraph. + * @param slot The slot index of the output on the subgraph node. + * @param visited A set of unique IDs to guard against infinite recursion. See {@link resolveInput}. + * @returns A DTO for the node, and the origin ID / slot index of the output. + */ + private _resolveSubgraphOutput( + slot: number, + type: ISlotType, + visited: Set + ): ResolvedInput | undefined { + const { node } = this + const output = node.outputs.at(slot) + + if (!output) + throw new SlotIndexError( + `No output found for flattened id [${this.id}] slot [${slot}]` + ) + if (!node.isSubgraphNode()) + throw new TypeError(`Node is not a subgraph node: ${node.id}`) + + // Link inside the subgraph + const innerResolved = node.resolveSubgraphOutputLink(slot) + if (!innerResolved) return + + const innerNode = innerResolved.outputNode + if (!innerNode) + throw new Error( + `No output node found for id [${this.id}] slot [${slot}] ${output.name}` + ) + + // Recurse into the subgraph + const innerNodeExecutionId: ExecutionId = [ + ...this.subgraphNodePath, + node.id, + innerNode.id + ].join(':') + const innerNodeDto = this.nodesByExecutionId.get(innerNodeExecutionId) + if (!innerNodeDto) + throw new Error( + `No inner node DTO found for id [${innerNodeExecutionId}]` + ) + + return innerNodeDto.resolveOutput( + innerResolved.link.origin_slot, + type, + visited + ) + } +} diff --git a/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__Subgraph.ts b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__Subgraph.ts new file mode 100644 index 00000000..e1f2f0b2 --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__Subgraph.ts @@ -0,0 +1,3 @@ +// Re-export Subgraph and GraphOrSubgraph from LGraph.ts to maintain compatibility +// This is a temporary fix to resolve circular dependency issues +export { Subgraph, type GraphOrSubgraph } from '@/lib/litegraph/src/LGraph' diff --git a/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts new file mode 100644 index 00000000..ea863b82 --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts @@ -0,0 +1,1025 @@ +import cloneDeep from 'es-toolkit/compat/cloneDeep' +import type { BaseLGraph, LGraph, SubgraphId } from '@/lib/litegraph/src/LGraph' +import type { LGraphButton } from '@/lib/litegraph/src/LGraphButton' +import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' +import { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { DrawTitleBoxOptions } from '@/lib/litegraph/src/LGraphNode' +import { LLink } from '@/lib/litegraph/src/LLink' +import type { ResolvedConnection } from '@/lib/litegraph/src/LLink' +import { NullGraphError } from '@/lib/litegraph/src/infrastructure/NullGraphError' +import { RecursionError } from '@/lib/litegraph/src/infrastructure/RecursionError' +import type { + ISubgraphInput, + IWidgetLocator +} from '@/lib/litegraph/src/interfaces' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { INodeInputSlot, ISlotType } from '@/lib/litegraph/src/litegraph' +import { NodeInputSlot } from '@/lib/litegraph/src/node/NodeInputSlot' +import { NodeOutputSlot } from '@/lib/litegraph/src/node/NodeOutputSlot' +import { UNASSIGNED_NODE_ID, toNodeId } from '@/types/nodeId' +import type { SerializedNodeId } from '@/types/nodeId' +import type { + GraphOrSubgraph, + Subgraph +} from '@/lib/litegraph/src/subgraph/Subgraph' +import type { + ExportedSubgraphInstance, + ISerialisedNode +} from '@/lib/litegraph/src/types/serialisation' +import { NodeSlotType } from '@/lib/litegraph/src/types/globalEnums' +import type { + IBaseWidget, + TWidgetValue +} from '@/lib/litegraph/src/types/widgets' +import { isWidgetValue } from '@/lib/litegraph/src/types/widgets' +import { isNodeBindable } from '@/lib/litegraph/src/utils/type' +import { deriveWidgetRenderState } from '@/lib/litegraph/src/utils/widget' +import { toConcreteWidget } from '@/lib/litegraph/src/widgets/widgetMap' +import type { WidgetTypeMap } from '@/lib/litegraph/src/widgets/widgetMap' +import { resolveConcretePromotedWidget } from '@/core/graph/subgraph/resolveConcretePromotedWidget' +import { resolveSubgraphInputTarget } from '@/core/graph/subgraph/resolveSubgraphInputTarget' +import { parsePreviewExposures } from '@/core/schemas/previewExposureSchema' +import { parseProxyWidgetErrorQuarantine } from '@/core/schemas/proxyWidgetQuarantineSchema' +import { + getPreviewExposureHostLocator, + tryGetPreviewExposureHostLocator, + usePreviewExposureStore +} from '@/stores/previewExposureStore' +import { useWidgetValueStore } from '@/stores/widgetValueStore' +import { createNodeLocatorId } from '@/types/nodeIdentification' +import type { NodeState } from '@/types/nodeState' +import type { WidgetId } from '@/types/widgetId' +import { widgetId } from '@/types/widgetId' + +import { ExecutableNodeDTO } from './ExecutableNodeDTO' +import type { ExecutableLGraphNode, ExecutionId } from './ExecutableNodeDTO' +import { createPromotedWidgetStoreProjection } from './promotedWidgetStoreProjection' +import type { SubgraphInput } from './SubgraphInput' +import { createBitmapCache } from './svgBitmapCache' + +const workflowSvg = new Image() +workflowSvg.src = + "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' width='16' height='16'%3E%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-linecap='round' stroke-width='1.3' d='M9.18613 3.09999H6.81377M9.18613 12.9H7.55288c-3.08678 0-5.35171-2.99581-4.60305-6.08843l.3054-1.26158M14.7486 2.1721l-.5931 2.45c-.132.54533-.6065.92789-1.1508.92789h-2.2993c-.77173 0-1.33797-.74895-1.1508-1.5221l.5931-2.45c.132-.54533.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.74896 1.1508 1.52211Zm-8.3033 0-.59309 2.45c-.13201.54533-.60646.92789-1.15076.92789H2.4021c-.7717 0-1.33793-.74895-1.15077-1.5221l.59309-2.45c.13201-.54533.60647-.9279 1.15077-.9279h2.29935c.77169 0 1.33792.74896 1.15076 1.52211Zm8.3033 9.8-.5931 2.45c-.132.5453-.6065.9279-1.1508.9279h-2.2993c-.77173 0-1.33797-.749-1.1508-1.5221l.5931-2.45c.132-.5453.6065-.9279 1.1508-.9279h2.2993c.7717 0 1.3379.7489 1.1508 1.5221Z'/%3E%3C/svg%3E %3C/svg%3E" + +const workflowBitmapCache = createBitmapCache(workflowSvg, 32) + +export class SubgraphNode extends LGraphNode implements BaseLGraph { + override get inputs(): (INodeInputSlot & Partial)[] { + return super.inputs + } + + override set inputs(value: (INodeInputSlot & Partial)[]) { + super.inputs = value + } + + override get type(): SubgraphId { + return super.type as SubgraphId + } + + override set type(value: string) { + super.type = value + } + + override readonly isVirtualNode = true as const + override graph: GraphOrSubgraph | null + + get rootGraph(): LGraph { + if (!this.graph) + throw new NullGraphError(`SubgraphNode ${this.id} has no graph`) + return this.graph.rootGraph + } + + get isDetached(): boolean { + return !this.graph + } + + override get displayType(): string { + return 'Subgraph node' + } + + override isSubgraphNode(): this is SubgraphNode { + return true + } + + declare widgets: IBaseWidget[] + + /** Widgets added programmatically (e.g. addDOMWidget) outside the promotion system. */ + private readonly _extraWidgets: IBaseWidget[] = [] + + /** + * Retained as a no-op for extension compatibility: promoted host widgets are + * now store-backed and addressed by widgetId, so there is no view cache to + * invalidate. + */ + invalidatePromotedViews(): void {} + + private _eventAbortController = new AbortController() + + constructor( + graph: GraphOrSubgraph, + readonly subgraph: Subgraph, + instanceData: ExportedSubgraphInstance + ) { + super(subgraph.name, subgraph.id) + this.graph = graph + + Object.defineProperty(this, 'widgets', { + get: () => [ + ...this.inputs.flatMap((input) => { + const widget = this._projectPromotedWidget(input) + return widget ? [widget] : [] + }), + ...this._extraWidgets + ], + set: () => { + if (import.meta.env.DEV) + console.warn( + 'Cannot manually set widgets on SubgraphNode; use the promotion system.' + ) + }, + configurable: true, + enumerable: true + }) + + const subgraphEvents = this.subgraph.events + const { signal } = this._eventAbortController + + subgraphEvents.addEventListener( + 'input-added', + (e) => { + const subgraphInput = e.detail.input + const { name, type } = subgraphInput + const existingInput = this.inputs.find( + (input) => + input._subgraphSlot === subgraphInput || + (input._subgraphSlot && input._subgraphSlot.id === subgraphInput.id) + ) + if (existingInput) { + this._addSubgraphInputListeners(subgraphInput, existingInput) + const linkId = subgraphInput.linkIds[0] + if (linkId === undefined) return + + const link = this.subgraph.getLink(linkId) + if (!link) return + + const { inputNode, input } = link.resolve(subgraph) + if (!inputNode || !input) return + + const widget = inputNode.getWidgetFromSlot(input) + if (widget) + this._setWidget(subgraphInput, existingInput, widget, input.widget) + return + } + const input = this.addInput(name, type, { + _subgraphSlot: subgraphInput + }) + this.invalidatePromotedViews() + + this._addSubgraphInputListeners(subgraphInput, input) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-input', + (e) => { + const widget = e.detail.input._widget + if (widget) this.ensureWidgetRemoved(widget) + + this.removeInput(e.detail.index) + this.invalidatePromotedViews() + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'output-added', + (e) => { + const { name, type } = e.detail.output + this.addOutput(name, type) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'removing-output', + (e) => { + this.removeOutput(e.detail.index) + this.setDirtyCanvas(true, true) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-input', + (e) => { + const { index, newName } = e.detail + const input = this.inputs.at(index) + if (!input) { + console.error('Subgraph input not found') + return + } + + input.label = newName + // Do NOT change input.widget.name — it is the stable internal + // identifier used by onGraphConfigured (widgetInputs.ts) to match + // inputs to widgets. Changing it to the display label would cause + // collisions when two promoted inputs share the same label. + if (input._widget) input._widget.label = newName + if (input.widgetId) { + const state = useWidgetValueStore().getWidget(input.widgetId) + if (state) state.label = newName + } + this.invalidatePromotedViews() + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.INPUT + }) + }, + { signal } + ) + + subgraphEvents.addEventListener( + 'renaming-output', + (e) => { + const { index, newName } = e.detail + const output = this.outputs.at(index) + if (!output) { + console.error('Subgraph output not found') + return + } + + output.label = newName + this.graph?.trigger('node:slot-label:changed', { + nodeId: this.id, + slotType: NodeSlotType.OUTPUT + }) + }, + { signal } + ) + + this.configure(instanceData) + + this.addTitleButton({ + name: 'enter_subgraph', + text: '\uE93B', // Unicode for pi-window-maximize + yOffset: 0, // No vertical offset needed, button is centered + xOffset: -10, + fontSize: 16 + }) + } + + override onTitleButtonClick( + button: LGraphButton, + canvas: LGraphCanvas + ): void { + if (button.name === 'enter_subgraph') { + canvas.openSubgraph(this.subgraph, this) + } else { + super.onTitleButtonClick(button, canvas) + } + } + + private _projectPromotedWidget( + input: INodeInputSlot + ): IBaseWidget | undefined { + if (input._widget) return input._widget + + const id = input.widgetId + if (!id) return + + input._widget = createPromotedWidgetStoreProjection(input, id) + return input._widget + } + + private _addSubgraphInputListeners( + subgraphInput: SubgraphInput, + input: INodeInputSlot & Partial + ) { + input._subgraphSlot = subgraphInput + + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + input._listenerController = new AbortController() + const { signal } = input._listenerController + + subgraphInput.events.addEventListener( + 'input-connected', + (e) => { + input.shape = this.getSlotShape(subgraphInput, e.detail.input) + if (!e.detail.widget || !e.detail.node) return + + this._setWidget( + subgraphInput, + input, + e.detail.widget, + e.detail.input.widget + ) + }, + { signal } + ) + + subgraphInput.events.addEventListener( + 'input-disconnected', + () => { + this.invalidatePromotedViews() + input.shape = this.getSlotShape(subgraphInput) + + const connectedWidgets = subgraphInput.getConnectedWidgets() + if (connectedWidgets.length > 0) { + this._resolveInputWidget(subgraphInput, input) + this.invalidatePromotedViews() + return + } + + if (input._widget) this.ensureWidgetRemoved(input._widget) + if (input.widgetId) { + const id = input.widgetId + queueMicrotask(() => { + if (this.inputs.some((input) => input.widgetId === id)) return + useWidgetValueStore().deleteWidget(id) + }) + } + + input.pos = undefined + input.widget = undefined + input.widgetId = undefined + input._widget = undefined + this.invalidatePromotedViews() + }, + { signal } + ) + } + + private _rebindInputSubgraphSlots(): void { + this.invalidatePromotedViews() + + const subgraphSlots = [...this.subgraph.inputNode.slots] + const slotsBySignature = new Map() + const slotsByName = new Map() + + for (const slot of subgraphSlots) { + const signature = `${slot.name}:${String(slot.type)}` + const signatureSlots = slotsBySignature.get(signature) + if (signatureSlots) { + signatureSlots.push(slot) + } else { + slotsBySignature.set(signature, [slot]) + } + + const nameSlots = slotsByName.get(slot.name) + if (nameSlots) { + nameSlots.push(slot) + } else { + slotsByName.set(slot.name, [slot]) + } + } + + const assignedSlotIds = new Set() + const takeUnassignedSlot = ( + slots: SubgraphInput[] | undefined + ): SubgraphInput | undefined => { + if (!slots) return undefined + return slots.find((slot) => !assignedSlotIds.has(String(slot.id))) + } + + for (const input of this.inputs) { + const existingSlot = input._subgraphSlot + if ( + existingSlot && + this.subgraph.inputNode.slots.some((slot) => slot === existingSlot) + ) { + assignedSlotIds.add(String(existingSlot.id)) + continue + } + + const signature = `${input.name}:${String(input.type)}` + const matchedSlot = + takeUnassignedSlot(slotsBySignature.get(signature)) ?? + takeUnassignedSlot(slotsByName.get(input.name)) + + if (matchedSlot) { + input._subgraphSlot = matchedSlot + assignedSlotIds.add(String(matchedSlot.id)) + } else { + delete input._subgraphSlot + } + } + } + + override configure(info: ExportedSubgraphInstance): void { + for (const input of this.inputs) { + this._clearPromotedWidget(input) + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + } + + this.inputs.length = 0 + this.inputs.push( + ...this.subgraph.inputNode.slots.map((slot) => + Object.assign( + new NodeInputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + shape: this.getSlotShape(slot), + type: slot.type, + link: null + }, + this + ), + { + _subgraphSlot: slot + } + ) + ) + ) + this.invalidatePromotedViews() + + this.outputs.length = 0 + this.outputs.push( + ...this.subgraph.outputNode.slots.map( + (slot) => + new NodeOutputSlot( + { + name: slot.name, + localized_name: slot.localized_name, + label: slot.label, + type: slot.type, + links: null + }, + this + ) + ) + ) + + super.configure(info) + if (!info.widgets_values_named || !LiteGraph.namedValuesRestore) + this._applyPromotedWidgetValues(info.widgets_values) + } + + private _applyPromotedWidgetValues( + widgetValues: ExportedSubgraphInstance['widgets_values'] + ): void { + const quarantineValuesByInputName = this._readQuarantineHostValuesByName() + + let valueIndex = 0 + for (const input of this.inputs) { + if (!input.widgetId) continue + const value = quarantineValuesByInputName.has(input.name) + ? quarantineValuesByInputName.get(input.name) + : widgetValues?.[valueIndex] + if (value !== undefined) { + useWidgetValueStore().setValue(input.widgetId, value) + } + valueIndex += 1 + } + } + + private _readQuarantineHostValuesByName(): Map { + return new Map( + parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + .toReversed() + .flatMap(({ originalEntry: [sourceNodeId, name], hostValue }) => + sourceNodeId === '-1' && hostValue !== undefined + ? [[name, hostValue] as const] + : [] + ) + ) + } + + override _internalConfigureAfterSlots() { + this._rebindInputSubgraphSlots() + + this.inputs = this.inputs.filter((input) => input._subgraphSlot) + this.invalidatePromotedViews() + + this._hydratePreviewExposures() + + for (const input of this.inputs) { + const subgraphInput = input._subgraphSlot + if (!subgraphInput) { + console.warn( + `[SubgraphNode.configure] No subgraph input found for input ${input.name}, skipping` + ) + continue + } + + this._addSubgraphInputListeners(subgraphInput, input) + this._resolveInputWidget(subgraphInput, input) + } + } + + private _hydratePreviewExposures() { + const store = usePreviewExposureStore() + const rootGraphId = this.rootGraph.id + const rawProperty = this.properties.previewExposures + const hasExplicitProperty = Array.isArray(rawProperty) + const fromProperty = parsePreviewExposures(rawProperty) + if (fromProperty.length || hasExplicitProperty) { + const hostLocator = tryGetPreviewExposureHostLocator(this) + if (hostLocator) + store.setExposures(rootGraphId, hostLocator, fromProperty) + return + } + const legacyKey = createNodeLocatorId(null, this.id) + const legacy = store.getExposures(rootGraphId, legacyKey) + if (!legacy.length) return + const hostLocator = getPreviewExposureHostLocator(this) + if (!hostLocator) return + store.setExposures(rootGraphId, hostLocator, [...legacy]) + if (legacyKey !== hostLocator) { + store.setExposures(rootGraphId, legacyKey, []) + } + } + + rebuildInputWidgetBindings(): void { + this.invalidatePromotedViews() + + const store = useWidgetValueStore() + const previousBindings = new Map( + this.inputs.flatMap((input) => { + if (!input.widgetId) return [] + const state = store.getWidget(input.widgetId) + return state + ? [[input, { id: input.widgetId, value: state.value }]] + : [] + }) + ) + + for (const input of this.inputs) { + const subgraphInput = input._subgraphSlot + if (!subgraphInput) continue + this._resolveInputWidget(subgraphInput, input) + const previous = previousBindings.get(input) + if (previous && input.widgetId) { + store.setValue(input.widgetId, previous.value) + } + } + + const activeIds = new Set(this.inputs.map((input) => input.widgetId)) + for (const { id } of previousBindings.values()) { + if (!activeIds.has(id)) store.deleteWidget(id) + } + + this.invalidatePromotedViews() + } + + private _resolveInputWidget( + subgraphInput: SubgraphInput, + input: INodeInputSlot + ) { + for (const linkId of subgraphInput.linkIds) { + const link = this.subgraph.getLink(linkId) + if (!link) { + console.warn( + `[SubgraphNode.configure] No link found for link ID ${linkId}`, + this + ) + continue + } + + const { inputNode, input: targetInput } = link.resolve(this.subgraph) + if (!inputNode) { + console.warn('Failed to resolve inputNode', link, this) + continue + } + + if (!targetInput) { + console.warn('Failed to find corresponding input', link, inputNode) + continue + } + + const widget = inputNode.getWidgetFromSlot(targetInput) + if (widget) { + this._setWidget(subgraphInput, input, widget, targetInput.widget) + break + } + + // Nested promotion: the source is itself a promoted subgraph input with + // no concrete widget. Resolve the deepest interior widget so this input + // still receives widget state and a widgetId. + const nested = this._resolveNestedPromotedSource(inputNode, targetInput) + if (nested) { + this._setWidget(subgraphInput, input, nested.widget, targetInput.widget) + break + } + } + } + + private _resolveNestedPromotedSource( + inputNode: LGraphNode, + targetInput: INodeInputSlot + ): { node: LGraphNode; widget: IBaseWidget } | undefined { + if (!inputNode.isSubgraphNode()) return undefined + + const target = resolveSubgraphInputTarget(inputNode, targetInput.name) + if (!target) return undefined + + const resolved = resolveConcretePromotedWidget( + inputNode, + target.nodeId, + target.widgetName + ) + return resolved.status === 'resolved' ? resolved.resolved : undefined + } + + private _setWidget( + subgraphInput: Readonly, + input: INodeInputSlot, + interiorWidget: Readonly, + inputWidget: IWidgetLocator | undefined + ) { + this.invalidatePromotedViews() + + this._clearPromotedWidget(input) + + input.widget ??= { name: subgraphInput.name } + input.widget.name = subgraphInput.name + if (inputWidget) Object.setPrototypeOf(input.widget, inputWidget) + + if (this.id === UNASSIGNED_NODE_ID) { + // Registering now would key the store under a construction-time id + // shared by every not-yet-added SubgraphNode (e.g. a clipboard clone + // that gets discarded), letting a later unrelated instance inherit + // this value. onAdded() performs the deferred registration once a + // real id is assigned. + input.widgetId = undefined + return + } + + const id = widgetId(this.rootGraph.id, this.id, subgraphInput.name) + const store = useWidgetValueStore() + const registered = store.registerWidget( + id, + { + type: interiorWidget.type, + value: interiorWidget.value, + options: cloneDeep(interiorWidget.options ?? {}), + label: input.label ?? subgraphInput.name, + serialize: interiorWidget.serialize, + disabled: interiorWidget.disabled + }, + deriveWidgetRenderState(interiorWidget) + ) + if (!registered) { + input.pos = undefined + input.widget = undefined + input.widgetId = undefined + input._widget = undefined + return + } + + input.widgetId = id + input._widget = + this.createPromotedHostWidget(input, id, interiorWidget) ?? + this._projectPromotedWidget(input) + this._setConcreteSlots() + + this.subgraph.events.dispatch('widget-promoted', { + widget: interiorWidget, + subgraphNode: this + }) + } + + /** + * App-layer hook to build a promoted DOM widget; the default falls back to the + * store-backed projection. Litegraph core stays free of Vue/Pinia/DOM. + */ + protected createPromotedHostWidget( + _input: INodeInputSlot, + _id: WidgetId, + _sourceWidget: Readonly + ): IBaseWidget | undefined { + return undefined + } + + /** + * Runs the host widget's `onRemove` (unregistering DOM widgets) and clears it. + * Unlike {@link ensureWidgetRemoved}, dispatches no demotion event, so it is + * safe on re-resolution. + */ + private _clearPromotedWidget(input: INodeInputSlot): void { + input._widget?.onRemove?.() + input._widget = undefined + } + + override onAdded(_graph: LGraph): void { + const store = useWidgetValueStore() + for (const input of this.inputs) { + const previousId = input.widgetId + if (!previousId) { + // Registration deferred by _setWidget while this.id was still + // UNASSIGNED_NODE_ID (e.g. widget resolution during construction). + // Perform it now that a real id is assigned. + if (input._subgraphSlot) + this._resolveInputWidget(input._subgraphSlot, input) + continue + } + const nextId = widgetId(this.rootGraph.id, this.id, input.name) + if (nextId === previousId) continue + + const state = store.getWidget(previousId) + if (!state) continue + const renderState = store.getWidgetRenderState(previousId) + const migrated = store.registerWidget( + nextId, + { ...state }, + { ...renderState } + ) + if (!migrated) continue + store.setValue(nextId, state.value) + store.deleteWidget(previousId) + input.widgetId = nextId + this._clearPromotedWidget(input) + if (input._subgraphSlot) { + this._resolveInputWidget(input._subgraphSlot, input) + } + input._widget ??= this._projectPromotedWidget(input) + } + } + + /** + * @param name The name of the input slot. + * @param type The type of the input slot. + * @param inputProperties Properties that are directly assigned to the created input. Default: a new, empty object. + * @returns The new input slot. + */ + override addInput>( + name: string, + type: ISlotType, + inputProperties: TInput = {} as TInput + ): INodeInputSlot & TInput { + return super.addInput(name, type, inputProperties) + } + + override getSlotFromWidget( + widget: IBaseWidget | undefined + ): INodeInputSlot | undefined { + if (widget?.widgetId) { + const promotedInput = this.inputs.find( + (input) => input.widgetId === widget.widgetId + ) + if (promotedInput) return promotedInput + } + return super.getSlotFromWidget(widget) + } + + override getWidgetFromSlot(slot: INodeInputSlot): IBaseWidget | undefined { + if (slot._widget) return slot._widget + return super.getWidgetFromSlot(slot) + } + + override getInputLink(slot: number): LLink | null { + const innerLink = this.subgraph.outputNode.slots[slot].getLinks().at(0) + if (!innerLink) { + console.warn( + `SubgraphNode.getInputLink: no inner link found for slot ${slot}` + ) + return null + } + + const newLink = LLink.create(innerLink) + newLink.origin_id = toNodeId(`${this.id}:${innerLink.origin_id}`) + newLink.origin_slot = innerLink.origin_slot + + return newLink + } + + /** + * @param slot The slot index + * @returns The resolved connections, or undefined if no input node is found. + */ + resolveSubgraphInputLinks(slot: number): ResolvedConnection[] { + const inputSlot = this.subgraph.inputNode.slots[slot] + const innerLinks = inputSlot.getLinks() + if (innerLinks.length === 0) { + console.warn( + `[SubgraphNode.resolveSubgraphInputLinks] No inner links found for input slot [${slot}] ${inputSlot.name}`, + this + ) + return [] + } + return innerLinks.map((link) => link.resolve(this.subgraph)) + } + + /** + * @param slot The slot index + * @returns The output node if found, otherwise undefined. + */ + resolveSubgraphOutputLink(slot: number): ResolvedConnection | undefined { + const outputSlot = this.subgraph.outputNode.slots[slot] + const innerLink = outputSlot.getLinks().at(0) + if (innerLink) { + return innerLink.resolve(this.subgraph) + } + console.warn( + `[SubgraphNode.resolveSubgraphOutputLink] No inner link found for output slot [${slot}] ${outputSlot.name}`, + this + ) + } + + override getInnerNodes( + executableNodes: Map, + subgraphNodePath: readonly SerializedNodeId[] = [], + nodes: ExecutableLGraphNode[] = [], + visited = new Set() + ): ExecutableLGraphNode[] { + if (visited.has(this)) { + const nodeInfo = `${this.id}${this.title ? ` (${this.title})` : ''}` + const subgraphInfo = `'${this.subgraph.name || 'Unnamed Subgraph'}'` + const depth = subgraphNodePath.length + throw new RecursionError( + `Circular reference detected at depth ${depth} in node ${nodeInfo} of subgraph ${subgraphInfo}. ` + + `This creates an infinite loop in the subgraph hierarchy.` + ) + } + visited.add(this) + + const subgraphInstanceIdPath = [...subgraphNodePath, this.id] + + const parentSubgraphNode = this.rootGraph + .resolveSubgraphIdPath(subgraphNodePath.map(toNodeId)) + .at(-1) + const subgraphNodeDto = new ExecutableNodeDTO( + this, + subgraphNodePath, + executableNodes, + parentSubgraphNode + ) + executableNodes.set(subgraphNodeDto.id, subgraphNodeDto) + + for (const node of this.subgraph.nodes) { + if ('getInnerNodes' in node && node.getInnerNodes) { + node.getInnerNodes( + executableNodes, + subgraphInstanceIdPath, + nodes, + new Set(visited) + ) + } else { + const aVeryRealNode = new ExecutableNodeDTO( + node, + subgraphInstanceIdPath, + executableNodes, + this + ) + executableNodes.set(aVeryRealNode.id, aVeryRealNode) + nodes.push(aVeryRealNode) + } + } + return nodes + } + + override addCustomWidget( + customWidget: TPlainWidget + ): TPlainWidget | WidgetTypeMap[TPlainWidget['type']] { + const widget = toConcreteWidget(customWidget, this, false) ?? customWidget + this._extraWidgets.push(widget) + this._widgetSlotsDirty = true + + if (this.id !== UNASSIGNED_NODE_ID && isNodeBindable(widget)) { + widget.setNodeId(this.id) + } + + return widget + } + + override removeWidget(widget: IBaseWidget): void { + this.ensureWidgetRemoved(widget) + } + + override ensureWidgetRemoved(widget: IBaseWidget): void { + widget.onRemove?.() + + const index = this._extraWidgets.indexOf(widget) + if (index !== -1) { + this._extraWidgets.splice(index, 1) + this._widgetSlotsDirty = true + return + } + + this.subgraph.events.dispatch('widget-demoted', { + widget, + subgraphNode: this + }) + } + + override onRemoved(): void { + this._eventAbortController.abort() + + for (const input of this.inputs) { + if ( + input._listenerController && + typeof input._listenerController.abort === 'function' + ) { + input._listenerController.abort() + } + this._clearPromotedWidget(input) + } + for (const widget of this._extraWidgets) widget.onRemove?.() + } + override drawTitleBox( + ctx: CanvasRenderingContext2D, + { + scale, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + box_size = 10 + }: DrawTitleBoxOptions + ): void { + if (this.onDrawTitleBox) { + this.onDrawTitleBox(ctx, title_height, this.renderingSize, scale) + return + } + ctx.save() + ctx.fillStyle = '#3b82f6' + ctx.beginPath() + ctx.roundRect(6, -24.5, 22, 20, 5) + ctx.fill() + if (!low_quality) { + ctx.translate(25, 23) + ctx.scale(-1.5, 1.5) + ctx.drawImage( + workflowBitmapCache.get(), + 0, + -title_height, + box_size, + box_size + ) + } + ctx.restore() + } + + override serialize(): ISerialisedNode { + return this.serializeFromStoreState(this._state) + } + + override serializeFromStoreState(state: NodeState): ISerialisedNode { + const serialized = super.serializeFromStoreState(state) + const serializedProperties = { ...(serialized.properties ?? {}) } + const rootGraphId = this.rootGraph.id + const hostLocator = tryGetPreviewExposureHostLocator(this) + + const previewExposures = hostLocator + ? usePreviewExposureStore().getExposures(rootGraphId, hostLocator) + : [] + serializedProperties.previewExposures = previewExposures.map((entry) => ({ + ...entry + })) + + const quarantine = parseProxyWidgetErrorQuarantine( + this.properties.proxyWidgetErrorQuarantine + ) + if (quarantine.length === 0) { + delete serializedProperties.proxyWidgetErrorQuarantine + } else { + serializedProperties.proxyWidgetErrorQuarantine = quarantine.map( + (entry) => ({ ...entry }) + ) + } + + serialized.properties = serializedProperties + + const widgetValues = this.inputs.flatMap((input) => { + if (!input.widgetId) return [] + const value = useWidgetValueStore().getWidget(input.widgetId)?.value + return [isWidgetValue(value) ? value : undefined] + }) + + if (widgetValues.some((value) => value !== undefined)) { + serialized.widgets_values = widgetValues + } else { + delete serialized.widgets_values + } + + return serialized + } + + override clone() { + const clone = super.clone() + + // TODO: Consider deep cloning subgraphs here. + + return clone + } + getSlotShape(slot: SubgraphInput, extraInput?: INodeInputSlot) { + const shapes = slot.linkIds.map( + (id) => this.subgraph.links[id]?.resolve(this.subgraph)?.input?.shape + ) + if (extraInput) shapes.push(extraInput.shape) + return shapes.every((shape) => shape === shapes[0]) ? shapes[0] : undefined + } +} diff --git a/docs/hel-892/structure-reference/1.53.6__src__utils__executionUtil.ts b/docs/hel-892/structure-reference/1.53.6__src__utils__executionUtil.ts new file mode 100644 index 00000000..5d6945f9 --- /dev/null +++ b/docs/hel-892/structure-reference/1.53.6__src__utils__executionUtil.ts @@ -0,0 +1,192 @@ +import type { + ExecutableLGraphNode, + ExecutionId, + LGraph +} from '@/lib/litegraph/src/litegraph' +import { + ExecutableNodeDTO, + LGraphEventMode +} from '@/lib/litegraph/src/litegraph' +import type { + ComfyApiWorkflow, + ComfyWorkflowJSON +} from '@/platform/workflow/validation/schemas/workflowSchema' + +import { compressWidgetInputSlots } from './litegraphUtil' + +type ExportedWidgetValueWrapper = { + __type__?: unknown + __value__: unknown +} + +function isExportedWidgetValueWrapper( + value: unknown +): value is ExportedWidgetValueWrapper { + return ( + typeof value === 'object' && + value !== null && + !Array.isArray(value) && + '__value__' in value + ) +} + +/** + * Inverse of the wrapping applied during Export (API). Curve values carry a + * type marker and may be objects; untyped wrappers are reserved for arrays so + * ordinary objects containing a `__value__` property pass through unchanged. + */ +export function unwrapExportedWidgetValue(value: unknown): unknown { + if ( + isExportedWidgetValueWrapper(value) && + (value.__type__ === 'CURVE' || Array.isArray(value.__value__)) + ) { + return value.__value__ + } + return value +} + +/** + * Converts the current graph workflow for sending to the API. + * @note Node widgets are updated before serialization to prepare queueing. + * + * @param graph The graph to convert. + * @param options The options for the conversion. + * - `sortNodes`: Whether to sort the nodes by execution order. + * @returns The workflow and node links + */ +export const graphToPrompt = async ( + graph: LGraph, + options: { sortNodes?: boolean } = {} +): Promise<{ workflow: ComfyWorkflowJSON; output: ComfyApiWorkflow }> => { + const { sortNodes = false } = options + + for (const node of graph.computeExecutionOrder(false)) { + const innerNodes = node.getInnerNodes + ? node.getInnerNodes(new Map()) + : [node] + for (const innerNode of innerNodes) { + if (innerNode.isVirtualNode) { + innerNode.applyToGraph?.() + } + } + } + + const workflow = graph.serialize({ sortNodes }) + + // Remove localized_name from the workflow + for (const node of workflow.nodes) { + for (const slot of node.inputs ?? []) { + delete slot.localized_name + } + for (const slot of node.outputs ?? []) { + delete slot.localized_name + } + } + + compressWidgetInputSlots(workflow) + workflow.extra ??= {} + workflow.extra.frontendVersion = __COMFYUI_FRONTEND_VERSION__ + + const nodeDtoMap = new Map() + for (const node of graph.computeExecutionOrder(false)) { + const dto: ExecutableLGraphNode = new ExecutableNodeDTO( + node, + [], + nodeDtoMap + ) + + nodeDtoMap.set(dto.id, dto) + + if ( + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + for (const innerNode of dto.getInnerNodes()) { + nodeDtoMap.set(innerNode.id, innerNode) + } + } + + const output: ComfyApiWorkflow = {} + // Process nodes in order of execution + for (const node of nodeDtoMap.values()) { + // Don't serialize muted nodes + if ( + node.isVirtualNode || + node.mode === LGraphEventMode.NEVER || + node.mode === LGraphEventMode.BYPASS + ) { + continue + } + + const inputs: ComfyApiWorkflow[string]['inputs'] = {} + const { widgets } = node + + // Store all widget values in the API prompt. + // Note: widget.options.serialize controls prompt inclusion (checked here). + // widget.serialize controls workflow persistence (checked by LGraphNode). + if (widgets) { + for (const [i, widget] of widgets.entries()) { + if (!widget.name || widget.options?.serialize === false) continue + + const widgetValue = widget.serializeValue + ? await widget.serializeValue(node, i) + : widget.value + // By default, Array values are reserved to represent node connections. + // We need to wrap the array as an object to avoid the misinterpretation + // of the array as a node connection. + // The backend automatically unwraps the object to an array during + // execution. + inputs[widget.name] = + widget.type === 'curve' && widgetValue != null + ? { __type__: 'CURVE', __value__: widgetValue } + : Array.isArray(widgetValue) + ? { __value__: widgetValue } + : widgetValue + } + } + + // Store all node links + for (const [i, input] of node.inputs.entries()) { + const resolvedInput = node.resolveInput(i) + if (!resolvedInput) continue + + // Resolved to an actual widget value rather than a node connection + if (resolvedInput.widgetInfo) { + const { value } = resolvedInput.widgetInfo + inputs[input.name] = Array.isArray(value) ? { __value__: value } : value + continue + } + + inputs[input.name] = [ + String(resolvedInput.origin_id), + // @ts-expect-error link.origin_slot is already number. + parseInt(resolvedInput.origin_slot) + ] + } + + output[String(node.id)] = { + inputs, + // TODO(huchenlei): Filter out all nodes that cannot be mapped to a + // comfyClass. + class_type: node.comfyClass!, + // Ignored by the backend. + _meta: { + title: node.title + } + } + } + + // Remove inputs connected to removed nodes + for (const { inputs } of Object.values(output)) { + for (const [i, input] of Object.entries(inputs)) { + if (Array.isArray(input) && input.length === 2 && !output[input[0]]) { + delete inputs[i] + } + } + } + + return { workflow: workflow as ComfyWorkflowJSON, output } +} diff --git a/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a__AILab_QwenASR.py b/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a__AILab_QwenASR.py new file mode 100644 index 00000000..4be554ff --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a__AILab_QwenASR.py @@ -0,0 +1,1178 @@ +# ComfyUI-QwenASR +# ComfyUI custom nodes for Qwen3-ASR speech-to-text models. + +import os +import re +import shutil +import sys +import time +from pathlib import Path +from typing import Optional, Tuple, List, Dict, Any, Union + +import numpy as np +import torch +import folder_paths +import comfy.model_management as model_management +from transformers import ( + AutoProcessor, + AutoModelForMultimodalLM, + AutoModelForTokenClassification, +) + +_CURRENT_DIR = Path(__file__).parent + +# ComfyUI model folder registration +QWEN3_ASR_ROOT = os.path.join(folder_paths.models_dir, "Qwen3-ASR") +os.makedirs(QWEN3_ASR_ROOT, exist_ok=True) +folder_paths.add_model_folder_path("Qwen3-ASR", QWEN3_ASR_ROOT) + +SUPPORTED_LANGUAGES = [ + "auto", + "Chinese", "English", "Cantonese", "Arabic", "German", "French", "Spanish", + "Portuguese", "Indonesian", "Italian", "Korean", "Russian", "Thai", + "Vietnamese", "Japanese", "Turkish", "Hindi", "Malay", "Dutch", "Swedish", + "Danish", "Finnish", "Polish", "Czech", "Filipino", "Persian", "Greek", + "Hungarian", "Macedonian", "Romanian", +] + +_ASR_MODEL_CACHE = {} +_ALIGNER_CACHE = {} +_CONFIG_CACHE = {"mtime": None, "data": None} +_EXTRA_MODEL_PATHS = None + + +class WordTimestamp: + def __init__(self, text: str = "", start_time: float = 0.0, end_time: float = 0.0): + self.text = str(text) + self.start_time = float(start_time) + self.end_time = float(end_time) + + def __repr__(self): + return f"WordTimestamp({self.text!r}, {self.start_time:.3f}, {self.end_time:.3f})" + + +class ForcedAlignResult: + def __init__(self, items: List[WordTimestamp]): + self.items = items + + def __iter__(self): + return iter(self.items) + + def __len__(self): + return len(self.items) + + def __getitem__(self, idx): + return self.items[idx] + + +def _default_config(): + return { + "models": { + "Qwen/Qwen3-ASR-1.7B-hf": "Qwen3-ASR-1.7B-hf", + "Qwen/Qwen3-ASR-0.6B-hf": "Qwen3-ASR-0.6B-hf", + }, + "aligners": { + "None": None, + "Qwen/Qwen3-ForcedAligner-0.6B-hf": "Qwen3-ForcedAligner-0.6B-hf", + }, + "sources": ["HuggingFace", "ModelScope"], + "defaults": { + "repo_id": "Qwen/Qwen3-ASR-0.6B-hf", + "source": "HuggingFace", + "precision": "bf16", + "attention": "auto", + "language": "auto", + "forced_aligner": "Qwen/Qwen3-ForcedAligner-0.6B-hf", + }, + } + + +def _load_config(): + path = _CURRENT_DIR / "config.json" + try: + mtime = path.stat().st_mtime + except Exception: + mtime = None + + cache = _CONFIG_CACHE + if cache["data"] is not None and cache["mtime"] == mtime: + return cache["data"] + + data = _default_config() + if mtime is not None: + try: + import json + loaded = json.loads(path.read_text(encoding="utf-8")) + if isinstance(loaded, dict): + data.update(loaded) + except Exception as e: + print(f"[Qwen3ASR] Failed to read config.json: {e}") + + cache["mtime"] = mtime + cache["data"] = data + return data + + +def _get_model_ids(): + models = _load_config().get("models") or {} + if isinstance(models, dict) and models: + return models + return _default_config()["models"] + + +def _get_aligner_ids(): + aligners = _load_config().get("aligners") or {} + if isinstance(aligners, dict) and aligners: + return aligners + return _default_config()["aligners"] + + +def _get_sources(): + sources = _load_config().get("sources") or [] + if isinstance(sources, list) and sources: + return sources + return _default_config()["sources"] + + +def _get_defaults(): + defaults = _load_config().get("defaults") or {} + if isinstance(defaults, dict) and defaults: + return defaults + return _default_config()["defaults"] + + +def _normalize_paths(paths): + normalized = [] + for p in paths: + if not isinstance(p, str): + continue + p = p.strip() + if not p: + continue + normalized.append(os.path.normpath(os.path.expanduser(p))) + return normalized + + +def _extract_yaml_paths(data): + if not isinstance(data, dict): + return [] + + def split_paths(value): + if isinstance(value, str): + lines = [line.strip() for line in value.splitlines()] + return [line for line in lines if line] + if isinstance(value, list): + return [v for v in value if isinstance(v, str) and v.strip()] + return [] + + def is_abs(p): + if not p: + return False + if os.path.isabs(p): + return True + if len(p) > 1 and p[1] == ":": + return True + return False + + def pull(d): + found = [] + for key in ("paths", "roots", "folders", "models", "search_paths"): + value = d.get(key) + found.extend(split_paths(value)) + return found + + paths = [] + paths.extend(pull(data)) + for section in data.values(): + if not isinstance(section, dict): + continue + base_path = section.get("base_path") + if isinstance(base_path, str) and base_path.strip(): + paths.append(base_path) + for key, value in section.items(): + if key in ("base_path", "is_default"): + continue + for item in split_paths(value): + if is_abs(item) or not isinstance(base_path, str): + paths.append(item) + else: + paths.append(os.path.join(base_path, item)) + return paths + + +def _load_extra_model_paths(): + global _EXTRA_MODEL_PATHS + if _EXTRA_MODEL_PATHS is not None: + return _EXTRA_MODEL_PATHS + + candidates = [] + try: + base_path = Path(getattr(folder_paths, "base_path", "")) + if base_path: + candidates.append(base_path / "extra_model_paths.yaml") + except Exception: + pass + + collected = [] + for path in candidates: + if not path.exists(): + continue + try: + import yaml + data = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + except Exception as e: + print(f"[Qwen3ASR] Failed to read {path}: {e}") + continue + collected.extend(_extract_yaml_paths(data)) + + normalized = [] + for p in _normalize_paths(collected): + if os.path.isdir(p) and p not in normalized: + normalized.append(p) + + _EXTRA_MODEL_PATHS = tuple(normalized) + return _EXTRA_MODEL_PATHS + + +def _model_storage_path(repo_id: str) -> str: + name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.split("/")[-1] + return os.path.join(QWEN3_ASR_ROOT, name) + + +def _find_local_model(repo_id: str) -> Optional[str]: + model_name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.split("/")[-1] + candidates = [] + + default_root = _model_storage_path(repo_id) + if os.path.isdir(default_root): + candidates.append(default_root) + + try: + asr_roots = folder_paths.get_folder_paths("Qwen3-ASR") or [] + for root in asr_roots: + candidates.append(os.path.join(root, model_name)) + except Exception: + pass + + for root in _load_extra_model_paths(): + candidates.append(os.path.join(root, model_name)) + candidates.append(os.path.join(root, "Qwen3-ASR", model_name)) + candidates.append(os.path.join(root, "ASR", "Qwen3-ASR", model_name)) + + for path in candidates: + if os.path.isdir(path) and os.listdir(path): + return path + return None + + +def _try_copy_cached(repo_id: str, target_dir: str) -> bool: + if os.path.isdir(target_dir) and os.listdir(target_dir): + return True + + hf_cache = os.path.join(Path.home(), ".cache", "huggingface", "hub") + hf_dir = os.path.join(hf_cache, f"models--{repo_id.replace('/', '--')}") + snapshots = os.path.join(hf_dir, "snapshots") + if os.path.isdir(snapshots): + entries = sorted(os.listdir(snapshots)) + if entries: + source = os.path.join(snapshots, entries[-1]) + try: + shutil.copytree(source, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + ms_cache = os.path.join(Path.home(), ".cache", "modelscope", "hub") + ms_dir = os.path.join(ms_cache, repo_id.replace("/", os.sep)) + if os.path.isdir(ms_dir): + try: + shutil.copytree(ms_dir, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + return False + + +def _download_to_local(repo_id: str, source: str, target_dir: str) -> str: + os.makedirs(target_dir, exist_ok=True) + if source == "ModelScope": + try: + from modelscope import snapshot_download + except Exception as e: + raise RuntimeError("modelscope is required for ModelScope downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + else: + try: + from huggingface_hub import snapshot_download + except Exception as e: + raise RuntimeError("huggingface_hub is required for HuggingFace downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + + return target_dir + + +def _resolve_model_path(repo_id: str, source: str) -> str: + local_path = _find_local_model(repo_id) + if local_path: + return local_path + + target_dir = _model_storage_path(repo_id) + if os.path.isdir(target_dir) and os.listdir(target_dir): + return target_dir + + if _try_copy_cached(repo_id, target_dir): + return target_dir + + return _download_to_local(repo_id, source, target_dir) + + +def _normalize_audio(audio, target_sr: int = 16000) -> Optional[Tuple[np.ndarray, int]]: + if audio is None: + return None + + waveform = audio.get("waveform") + sample_rate = audio.get("sample_rate") + if waveform is None or sample_rate is None: + return None + + wave = waveform[0] + if wave.ndim == 2 and wave.shape[0] > 1: + wave = torch.mean(wave, dim=0) + elif wave.ndim == 2: + wave = wave.squeeze(0) + + if int(sample_rate) != target_sr: + import torchaudio.functional as F + wave = F.resample(wave, int(sample_rate), target_sr) + sample_rate = target_sr + + return (wave.detach().cpu().numpy().astype(np.float32), int(sample_rate)) + + +def _build_dtype(precision: str, device: torch.device) -> torch.dtype: + if precision == "fp16": + return torch.float16 + if precision == "bf16": + if device.type == "mps": + return torch.float16 + return torch.bfloat16 + return torch.float32 + + +def _is_hf_native(repo_id_or_path: str) -> bool: + s = str(repo_id_or_path).lower() + return "-hf" in s + + +# ------------------------------------------------------------------------- +# Native Transformers Engine Implementation +# ------------------------------------------------------------------------- + +class _HFASREngine: + def __init__(self, model_path: str, dtype: torch.dtype, device: torch.device, attention: str): + self.processor = AutoProcessor.from_pretrained(model_path) + kwargs = {"dtype": dtype} + if attention != "auto": + kwargs["attn_implementation"] = attention + if device.type in ("mps", "cpu"): + self.model = AutoModelForMultimodalLM.from_pretrained(model_path, **kwargs).to(device).eval() + else: + kwargs["device_map"] = str(device) + self.model = AutoModelForMultimodalLM.from_pretrained(model_path, **kwargs).eval() + self.device = device + self.dtype = dtype + + def transcribe( + self, + audio_data: Tuple[np.ndarray, int], + language: Optional[str] = None, + context: Optional[str] = None, + max_new_tokens: int = 256, + ) -> Tuple[str, str]: + wave, sr = audio_data + duration = len(wave) / float(sr) + + if duration <= 120.0: + return self._transcribe_chunk(wave, language, context, max_new_tokens) + + chunk_samples = 60 * sr + texts = [] + detected_lang = "" + for start_idx in range(0, len(wave), chunk_samples): + chunk_wave = wave[start_idx : start_idx + chunk_samples] + if len(chunk_wave) < int(0.5 * sr): + continue + sub_text, sub_lang = self._transcribe_chunk(chunk_wave, language, context, max_new_tokens) + if sub_text: + texts.append(sub_text) + if not detected_lang and sub_lang: + detected_lang = sub_lang + + full_text = " ".join(texts) + return full_text, detected_lang + + def _transcribe_chunk(self, wave: np.ndarray, language: Optional[str], context: Optional[str], max_new_tokens: int): + kwargs = {"audio": wave} + if language and language != "auto": + kwargs["language"] = language + if context: + kwargs["prompt"] = context + + inputs = self.processor.apply_transcription_request(**kwargs) + inputs = inputs.to(self.device, self.dtype) + + with torch.inference_mode(): + output_ids = self.model.generate(**inputs, max_new_tokens=max_new_tokens) + + generated_ids = output_ids[:, inputs["input_ids"].shape[1]:] + parsed = self.processor.decode(generated_ids, return_format="parsed")[0] + if isinstance(parsed, dict): + text = parsed.get("transcription", "") or "" + lang = parsed.get("language", "") or "" + else: + text = str(parsed) + lang = "" + return text.strip(), lang + + +class _HFAlignerEngine: + def __init__(self, model_path: str, dtype: torch.dtype, device: torch.device, attention: str): + self.processor = AutoProcessor.from_pretrained(model_path) + kwargs = {"dtype": dtype} + if attention != "auto": + kwargs["attn_implementation"] = attention + if device.type in ("mps", "cpu"): + self.model = AutoModelForTokenClassification.from_pretrained(model_path, **kwargs).to(device).eval() + else: + kwargs["device_map"] = str(device) + self.model = AutoModelForTokenClassification.from_pretrained(model_path, **kwargs).eval() + self.device = device + self.dtype = dtype + + def align( + self, + audio: Union[Tuple[np.ndarray, int], Any], + text: Union[str, List[str]], + language: Union[str, List[str]] = "English", + ) -> List[ForcedAlignResult]: + if isinstance(audio, tuple) and len(audio) == 2: + wave, sr = audio + else: + norm = _normalize_audio(audio) + wave, sr = norm if norm is not None else (np.zeros(16000, dtype=np.float32), 16000) + + transcript = text[0] if isinstance(text, list) else text + lang = language[0] if isinstance(language, list) else language + + aligner_inputs, word_lists = self.processor.prepare_forced_aligner_inputs( + audio=wave, + transcript=transcript, + language=lang, + ) + aligner_inputs = aligner_inputs.to(self.device, self.dtype) + + with torch.inference_mode(): + outputs = self.model(**aligner_inputs) + + timestamp_token_id = getattr(self.model.config, "timestamp_token_id", None) + timestamps = self.processor.decode_forced_alignment( + logits=outputs.logits, + input_ids=aligner_inputs["input_ids"], + word_lists=word_lists, + timestamp_token_id=timestamp_token_id, + )[0] + + items = [ + WordTimestamp( + text=item.get("text", "") if isinstance(item, dict) else getattr(item, "text", ""), + start_time=float(item.get("start_time", 0.0) if isinstance(item, dict) else getattr(item, "start_time", 0.0)), + end_time=float(item.get("end_time", 0.0) if isinstance(item, dict) else getattr(item, "end_time", 0.0)), + ) + for item in timestamps + ] + return [ForcedAlignResult(items=items)] + + +class UnifiedASRModel: + def __init__(self, asr_engine: Any, aligner_engine: Any = None): + self.asr = asr_engine + self.aligner = aligner_engine + + def transcribe( + self, + audio_data: Tuple[np.ndarray, int], + language: Optional[str] = None, + context: Optional[str] = None, + return_time_stamps: bool = False, + max_new_tokens: int = 256, + ) -> Tuple[str, str, Optional[List[WordTimestamp]]]: + text, detected_lang = self.asr.transcribe( + audio_data=audio_data, + language=language, + context=context, + max_new_tokens=max_new_tokens, + ) + + time_stamps = None + if return_time_stamps and self.aligner is not None and text.strip(): + lang_align = detected_lang or language or "English" + align_results = self.aligner.align(audio=audio_data, text=text, language=lang_align) + if align_results and len(align_results) > 0: + time_stamps = list(align_results[0]) + + return text, detected_lang, time_stamps + + +def _load_cached_aligner( + aligner_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str = "auto", +): + key = (aligner_path, str(dtype), str(device), attention) + cached = _ALIGNER_CACHE.get(key) + if cached is not None: + return cached + + if not _is_hf_native(aligner_path): + raise ValueError( + f"Model '{aligner_path}' is not supported. " + "Please use the official native model: 'Qwen/Qwen3-ForcedAligner-0.6B-hf'." + ) + + aligner = _HFAlignerEngine(aligner_path, dtype, device, attention) + _ALIGNER_CACHE[key] = aligner + return aligner + + +def _load_cached_asr( + model_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str = "auto", + forced_aligner_path: str = "", + max_inference_batch_size: int = 32, + max_new_tokens: int = 256, +) -> UnifiedASRModel: + key = ( + model_path, + str(dtype), + str(device), + attention, + forced_aligner_path or "", + int(max_inference_batch_size), + int(max_new_tokens), + ) + cached = _ASR_MODEL_CACHE.get(key) + if cached is not None: + return cached + + if not _is_hf_native(model_path): + raise ValueError( + f"Model '{model_path}' is not supported. " + "Please use official native models: 'Qwen/Qwen3-ASR-0.6B-hf' or 'Qwen/Qwen3-ASR-1.7B-hf'." + ) + + asr_engine = _HFASREngine(model_path, dtype, device, attention) + aligner_engine = None + if forced_aligner_path: + aligner_engine = _load_cached_aligner(forced_aligner_path, dtype, device, attention) + + unified = UnifiedASRModel(asr_engine=asr_engine, aligner_engine=aligner_engine) + _ASR_MODEL_CACHE[key] = unified + return unified + + +# ------------------------------------------------------------------------- +# Subtitle & Text Utilities +# ------------------------------------------------------------------------- + +def _format_srt_time(seconds: float) -> str: + total_ms = max(0, int(round(seconds * 1000))) + ms = total_ms % 1000 + total_s = total_ms // 1000 + s = total_s % 60 + total_m = total_s // 60 + m = total_m % 60 + h = total_m // 60 + return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}" + + +def _build_srt(time_stamps) -> str: + if not time_stamps: + return "" + lines = [] + for idx, item in enumerate(time_stamps, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(item.start_time)} --> {_format_srt_time(item.end_time)}") + lines.append(item.text or "") + lines.append("") + return "\n".join(lines).strip() + + +def _join_tokens(a: str, b: str) -> str: + if not a: + return b + if not b: + return a + for ch in (a[-1], b[0]): + if "\u4e00" <= ch <= "\u9fff": + return f"{a}{b}" + return f"{a} {b}" + + +def _restore_punctuation(time_stamps, full_text: str): + if not time_stamps or not full_text: + return time_stamps + + punct_set = set(".,!?:;—…~。,!?、;:”’'\"()()[]【】《》") + text_len = len(full_text) + text_pos = 0 + + restored = [] + for ts in time_stamps: + raw_word = str(ts.text or "").strip() + if not raw_word: + restored.append(ts) + continue + + pattern = re.escape(raw_word) + m = re.search(pattern, full_text[text_pos:], re.IGNORECASE) + if not m: + restored.append(ts) + continue + + word_start = text_pos + m.start() + word_end = text_pos + m.end() + matched_cased_word = full_text[word_start:word_end] + + trail_pos = word_end + trail_punct = [] + while trail_pos < text_len: + ch = full_text[trail_pos] + if ch in punct_set: + trail_punct.append(ch) + trail_pos += 1 + elif ch.isspace(): + trail_pos += 1 + else: + break + + new_text = matched_cased_word + "".join(trail_punct) + restored.append(type(ts)(text=new_text, start_time=ts.start_time, end_time=ts.end_time)) + text_pos = trail_pos + + return restored + + +_DANGLING_TAILS = { + "for", "to", "of", "in", "on", "at", "with", "by", "from", "about", "into", "through", + "the", "a", "an", + "and", "or", "but", "nor", "so", "yet", + "that", "which", "who", "whom", "whose", + "as", "if", "when", "than", "because", "while", "where" +} + + +def _group_time_stamps(time_stamps, max_gap_sec: float, max_chars: int, split_mode: str): + if not time_stamps: + return [] + groups = [] + cur = None + sentence_punct = ("。", "!", "?", ".", "!", "?") + clause_punct = (",", ";", ":", ",", ";", ":", "、") + all_punct = sentence_punct + clause_punct + + n_items = len(time_stamps) + for idx, item in enumerate(time_stamps): + text = (item.text or "").strip() + if not text: + continue + if cur is None: + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + continue + + gap = float(item.start_time) - float(cur["end"]) + too_far = gap > max_gap_sec + end_sentence = any(cur["text"].endswith(p) for p in sentence_punct) + end_clause = any(cur["text"].endswith(p) for p in clause_punct) + this_word_ends_sentence = any(text.endswith(p) for p in sentence_punct) + this_word_ends_clause = any(text.endswith(p) for p in all_punct) + + # Lookahead: check if the sentence ends in the next 1-3 words (Orphan Protection) + sentence_ends_soon = this_word_ends_sentence + if not sentence_ends_soon: + for lookahead in range(1, 4): + if idx + lookahead < n_items: + next_t = (time_stamps[idx + lookahead].text or "").strip() + if any(next_t.endswith(p) for p in sentence_punct): + sentence_ends_soon = True + break + + # Lookahead: check if a clause punct (comma, etc.) ends on this word or next 1-2 words + clause_ends_soon = this_word_ends_clause + if not clause_ends_soon: + for lookahead in range(1, 3): + if idx + lookahead < n_items: + next_t = (time_stamps[idx + lookahead].text or "").strip() + if any(next_t.endswith(p) for p in all_punct): + clause_ends_soon = True + break + + # Dangling check: does current accumulated text end with a dangling preposition/article/conjunction? + last_word = cur["text"].split()[-1].lower().rstrip(",.?!;:,。!?;:") if cur["text"].split() else "" + is_dangling = last_word in _DANGLING_TAILS + + too_long = False + if max_chars > 0: + projected_len = len(cur["text"]) + 1 + len(text) + # Soft tolerance: if a clause/sentence ends soon or last word is dangling, allow up to 25% overshoot + effective_max = int(max_chars * 1.25) if (sentence_ends_soon or clause_ends_soon or is_dangling) else max_chars + if projected_len > effective_max: + if not sentence_ends_soon: + too_long = True + + split_by_punct = "punctuation" in split_mode + split_by_length = "length" in split_mode + split_by_pause = "pause" in split_mode + + min_clause_len = 10 if any('\u4e00' <= c <= '\u9fff' for c in cur["text"]) else 20 + + should_split = False + if split_by_punct: + if end_sentence: + should_split = True + elif end_clause and (len(cur["text"]) >= min_clause_len or too_long): + should_split = True + if split_by_pause and too_far and not should_split: + should_split = True + if split_by_length and too_long and not should_split: + should_split = True + + if should_split: + groups.append(cur) + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + else: + cur["text"] = _join_tokens(cur["text"], text).strip() + cur["end"] = item.end_time + + if cur is not None: + groups.append(cur) + return groups + + +def _build_srt_from_groups(groups) -> str: + if not groups: + return "" + lines = [] + for idx, g in enumerate(groups, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(g['start'])} --> {_format_srt_time(g['end'])}") + lines.append(g["text"]) + lines.append("") + return "\n".join(lines).strip() + + +def _default_output_dir() -> str: + base = folder_paths.get_output_directory() + return os.path.join(base, "ComfyUI-QwenASR") + + +def _is_dir_path(path: str) -> bool: + if not path: + return False + if path.endswith(("/", "\\")): + return True + return os.path.isdir(path) + + +def _make_default_filename(ext: str) -> str: + stamp = time.strftime("%Y%m%d_%H%M%S") + return f"qwenasr_subtitle_{stamp}{ext}" + + +# ------------------------------------------------------------------------- +# Inverse Text Normalization (ITN) & Text Formatting +# ------------------------------------------------------------------------- + +_CN_NUM = { + '零': 0, '一': 1, '二': 2, '两': 2, '三': 3, '四': 4, + '五': 5, '六': 6, '七': 7, '八': 8, '九': 9, +} +_CN_UNIT = { + '十': 10, '百': 100, '千': 1000, '万': 10000, '亿': 100000000 +} +_ITN_CACHE = {"mtime": None, "data": None} + + +def _default_itn_rules(): + return { + "protected_words": [], + "custom_replacements": {}, + "enable_number_conversion": True, + "enable_acronym_cleanup": True, + } + + +def _load_itn_rules(): + path = _CURRENT_DIR / "itn_rules.json" + try: + mtime = path.stat().st_mtime + except Exception: + mtime = None + + cache = _ITN_CACHE + if cache["data"] is not None and cache["mtime"] == mtime: + return cache["data"] + + data = _default_itn_rules() + if mtime is not None: + try: + import json + loaded = json.loads(path.read_text(encoding="utf-8")) + if isinstance(loaded, dict): + data = { + "protected_words": list(loaded.get("protected_words", [])), + "custom_replacements": dict(loaded.get("custom_replacements", {})), + "enable_number_conversion": bool(loaded.get("enable_number_conversion", True)), + "enable_acronym_cleanup": bool(loaded.get("enable_acronym_cleanup", True)), + } + except Exception as e: + print(f"[Qwen3ASR] Failed to read itn_rules.json: {e}") + + cache["mtime"] = mtime + cache["data"] = data + return data + + +def _parse_cn_int(s: str) -> int: + if not s: + return 0 + if all(c in _CN_NUM for c in s) and not any(u in _CN_UNIT for u in s): + return int(''.join(str(_CN_NUM[c]) for c in s)) + total = 0 + r = 0 + for c in s: + if c in _CN_NUM: + r = _CN_NUM[c] + elif c in _CN_UNIT: + unit = _CN_UNIT[c] + if unit >= 10000: + total = (total + (r if r else 1)) * unit + r = 0 + else: + total += (r if r else 1) * unit + r = 0 + total += r + return total + + +def _convert_cn_number(match): + s = match.group(0) + if s.startswith('百分之'): + val = s[3:] + if '点' in val: + p = val.split('点') + int_p = _parse_cn_int(p[0]) if p[0] else 0 + dec_p = ''.join(str(_CN_NUM.get(c, c)) for c in p[1]) + return f'{int_p}.{dec_p}%' + return f'{_parse_cn_int(val)}%' + + if '点' in s: + parts = s.split('点') + int_part = _parse_cn_int(parts[0]) if parts[0] else 0 + dec_part = ''.join(str(_CN_NUM.get(c, c)) for c in parts[1]) + return f'{int_part}.{dec_part}' + + return str(_parse_cn_int(s)) + + +def _normalize_text(text: str) -> str: + if not text: + return "" + + cfg = _load_itn_rules() + + # 1. Custom user replacements (handles any language or special jargon) + custom_replacements = cfg.get("custom_replacements") or {} + for k, v in custom_replacements.items(): + if k.startswith("_"): + continue + if re.search(r'[a-zA-Z]', k): + text = re.sub(re.escape(k), v, text, flags=re.IGNORECASE) + elif k in text: + text = text.replace(k, v) + + # 2. Mask protected words from conversion + protected = cfg.get("protected_words") or [] + placeholders = {} + for idx, word in enumerate(protected): + if word in text: + key = f"__PROT_{idx}__" + placeholders[key] = word + text = text.replace(word, key) + + # 3. Chinese number conversion + if cfg.get("enable_number_conversion", True): + text = re.sub(r'百分之[零一二两三四五六七八九十百]+(?:点[零一二两三四五六七八九]+)?', _convert_cn_number, text) + text = re.sub(r'[零一二两三四五六七八九十百千万亿]+点[零一二两三四五六七八九]+', _convert_cn_number, text) + text = re.sub(r'[零一二两三四五六七八九十百千万亿]{2,}', _convert_cn_number, text) + + # 4. Spaced Latin acronym cleanup (e.g. 'A S R' -> 'ASR', 'U S B' -> 'USB') + if cfg.get("enable_acronym_cleanup", True): + text = re.sub(r'(?:(?<=[^a-zA-Z])|^)([a-zA-Z])(?:\s+([a-zA-Z]))+(?=[^a-zA-Z]|$)', + lambda m: m.group(0).replace(' ', ''), text) + + # 5. Restore protected words + for key, word in placeholders.items(): + text = text.replace(key, word) + + return text + + +# ------------------------------------------------------------------------- +# ComfyUI Nodes +# ------------------------------------------------------------------------- + +class AILab_Qwen3ASR: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B-hf"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "placeholder": "Optional: Context hotwords, names, or terminology (e.g. Qwen3-ASR)...", "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "normalize_text": ("BOOLEAN", {"default": True, "tooltip": "Normalize spoken numbers ('一百二十八' -> '128') and acronym spacing ('A S R' -> 'ASR')."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("TEXT",) + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B-hf", + precision="bf16", + language="auto", + hints="", + normalize_text=True, + unload_models=True, + ): + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + attention = _get_defaults().get("attention", "auto") + + print(f"[QwenASR] [ASR] Resolving model '{model}' from {source}...") + model_path = _resolve_model_path(model, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + print("[QwenASR] [ASR] Error: Invalid or missing audio input.") + return ("",) + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + print(f"[QwenASR] [ASR] Transcribing audio ({len(audio_data[0]) / float(audio_data[1]):.1f}s, language: {language})...") + model_runner = _load_cached_asr(model_path, dtype, device, attention, "") + text, detected_lang, _ = model_runner.transcribe( + audio_data=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=False, + ) + + if normalize_text: + text = _normalize_text(text) + + print(f"[QwenASR] [ASR] Transcription complete: {len(text)} characters (detected: {detected_lang or 'N/A'}).") + + if unload_models: + _ASR_MODEL_CACHE.clear() + _ALIGNER_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text,) + + +class AILab_Qwen3ASRSubtitle: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B-hf"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "attention": (["auto", "flash_attention_2", "sdpa", "eager"], {"default": defaults.get("attention", "auto"), "tooltip": "Attention backend override."}), + "forced_aligner": (list(_get_aligner_ids().keys()), {"default": defaults.get("forced_aligner", "Qwen/Qwen3-ForcedAligner-0.6B-hf"), "tooltip": "Forced aligner for timestamped subtitles."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "placeholder": "Optional: Context hotwords, names, or terminology (e.g. Qwen3-ASR)...", "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "output_format": (["none", "txt", "srt"], {"default": "none", "tooltip": "File save format only (does not change subtitle output)."}), + "output_path": ("STRING", {"default": "", "multiline": False, "tooltip": "Optional output file path (relative goes to ComfyUI output)."}), + "split_mode": (["split_by_punctuation_or_pause", "split_by_punctuation_or_pause_or_length", "split_by_punctuation_or_length", "split_by_punctuation", "split_by_pause", "split_by_length"], {"default": "split_by_punctuation_or_pause", "tooltip": "Sentence splitting strategy. 'split_by_punctuation_or_pause' is recommended for natural, readable subtitle clauses without arbitrary character slicing."}), + "max_gap_sec": ("FLOAT", {"default": 0.6, "min": 0.0, "max": 8.0, "step": 0.1, "tooltip": "Max silence gap to keep the same sentence."}), + "max_chars": ("INT", {"default": 40, "min": 0, "max": 200, "tooltip": "Optional max characters per line (0 = no limit, 80 recommended if length splitting is enabled)."}), + "max_inference_batch_size": ("INT", {"default": 32, "min": 1, "max": 256, "tooltip": "Batch size for inference/alignment to avoid OOM."}), + "max_new_tokens": ("INT", {"default": 256, "min": 1, "max": 2048, "tooltip": "Max new tokens per chunk."}), + "normalize_text": ("BOOLEAN", {"default": True, "tooltip": "Normalize spoken numbers ('一百二十八' -> '128') and acronym spacing ('A S R' -> 'ASR')."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING") + RETURN_NAMES = ("TEXT", "SUBTITLES", "LANGUAGE", "OUTPUT_PATH") + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B-hf", + precision="bf16", + attention="auto", + forced_aligner="Qwen/Qwen3-ForcedAligner-0.6B-hf", + language="auto", + hints="", + output_format="none", + output_path="", + split_mode="split_by_punctuation_or_pause", + max_gap_sec=0.6, + max_chars=80, + max_inference_batch_size=32, + max_new_tokens=256, + normalize_text=True, + unload_models=True, + ): + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + + print(f"[QwenASR] [Subtitle] Resolving models (ASR: {model}, Aligner: {forced_aligner}) from {source}...") + model_path = _resolve_model_path(model, source) + + forced_aligner_path = "" + if forced_aligner and forced_aligner != "None": + forced_aligner_path = _resolve_model_path(forced_aligner, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + print("[QwenASR] [Subtitle] Error: Invalid or missing audio input.") + return ("", "", "", "") + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + duration = len(audio_data[0]) / float(audio_data[1]) + print(f"[QwenASR] [Subtitle] Transcribing audio ({duration:.1f}s, language: {language})...") + model_runner = _load_cached_asr( + model_path, + dtype, + device, + attention, + forced_aligner_path, + max_inference_batch_size=max_inference_batch_size, + max_new_tokens=max_new_tokens, + ) + text, detected_lang, time_stamps = model_runner.transcribe( + audio_data=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=bool(forced_aligner_path), + max_new_tokens=max_new_tokens, + ) + + if time_stamps and text: + time_stamps = _restore_punctuation(time_stamps, text) + + if normalize_text: + text = _normalize_text(text) + + subtitles = "" + file_path = "" + groups = _group_time_stamps(time_stamps, max_gap_sec=max_gap_sec, max_chars=max_chars, split_mode=split_mode) + + if normalize_text: + for g in groups: + g["text"] = _normalize_text(g["text"]) + + lines = [f"{g['start']:.2f}-{g['end']:.2f}: {g['text']}" for g in groups] + subtitles = "\n".join(lines) if lines else text + + if forced_aligner_path and time_stamps: + print(f"[QwenASR] [Subtitle] Forced alignment generated {len(time_stamps)} word timestamps -> {len(groups)} subtitle lines.") + elif forced_aligner_path: + print("[QwenASR] [Subtitle] Notice: Aligner active but no word timestamps were generated (silence or unaligned speech).") + else: + print("[QwenASR] [Subtitle] Notice: Forced aligner set to 'None'. Outputting plain text.") + + if output_format != "none": + out_path = (output_path or "").strip() + if not os.path.isabs(out_path): + if out_path == "": + out_path = _default_output_dir() + out_path = os.path.join(folder_paths.get_output_directory(), out_path) + + if _is_dir_path(out_path): + ext = ".srt" if output_format == "srt" else ".txt" + out_path = os.path.join(out_path, _make_default_filename(ext)) + else: + root, ext = os.path.splitext(out_path) + if not ext: + ext = ".srt" if output_format == "srt" else ".txt" + out_path = root + ext + os.makedirs(os.path.dirname(out_path), exist_ok=True) + if output_format == "srt": + file_content = _build_srt_from_groups(groups) if groups else text + else: + file_content = subtitles + with open(out_path, "w", encoding="utf-8") as f: + f.write(file_content) + file_path = out_path + + if unload_models: + _ASR_MODEL_CACHE.clear() + _ALIGNER_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text, subtitles, detected_lang, file_path) + + +NODE_CLASS_MAPPINGS = { + "AILab_Qwen3ASR": AILab_Qwen3ASR, + "AILab_Qwen3ASRSubtitle": AILab_Qwen3ASRSubtitle, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "AILab_Qwen3ASR": "ASR (QwenASR)", + "AILab_Qwen3ASRSubtitle": "Subtitle (QwenASR)", +} diff --git a/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a____init__.py b/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a____init__.py new file mode 100644 index 00000000..a575ddaa --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI-QwenASR__3f9a652a____init__.py @@ -0,0 +1,46 @@ +import importlib +import pkgutil +import sys +from pathlib import Path + +__repo_name__ = "ComfyUI-QwenASR" +__version__ = "1.1.0" + +# Locate current directory +current_dir = Path(__file__).parent + +# Ensure current directory is in sys.path +if str(current_dir) not in sys.path: + sys.path.insert(0, str(current_dir)) + +# Initialize node mappings +NODE_CLASS_MAPPINGS = {} +NODE_DISPLAY_NAME_MAPPINGS = {} +WEB_DIRECTORY = "./web" + + +def load_nodes(): + """Automatically discover and load node definitions.""" + for (_, module_name, _) in pkgutil.iter_modules([str(current_dir)]): + if not module_name.startswith("AILab_"): + continue + try: + rel_import = f".{module_name}" if __package__ else module_name + module = importlib.import_module(rel_import, package=__package__) + if hasattr(module, "NODE_CLASS_MAPPINGS"): + NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) + if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"): + NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) + except Exception as e: + print(f"[{__repo_name__}] Error loading {module_name}: {e}") + + +# Load all nodes +load_nodes() + +__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] + +print(f'\033[36m[{__repo_name__}]\033[0m v' + f'\033[93m{__version__}\033[0m | ' + f'\033[37m{len(NODE_CLASS_MAPPINGS)} nodes\033[0m ' + f'\033[92mLoaded\033[0m') diff --git a/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be__LICENSE b/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be____init__.py b/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be____init__.py new file mode 100644 index 00000000..5503298e --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI-QwenASR__b037d7be____init__.py @@ -0,0 +1,42 @@ +from pathlib import Path +import importlib.util +import os +import sys + +_current_dir = Path(__file__).parent +if str(_current_dir) not in sys.path: + sys.path.insert(0, str(_current_dir)) + +NODE_CLASS_MAPPINGS = {} +NODE_DISPLAY_NAME_MAPPINGS = {} +WEB_DIRECTORY = "./web" + + +def _load_module(path: Path): + spec = importlib.util.spec_from_file_location(path.stem, path) + if not spec or not spec.loader: + return None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def _discover_nodes(): + for py in _current_dir.glob("*.py"): + if py.name == "__init__.py": + continue + try: + module = _load_module(py) + if not module: + continue + if hasattr(module, "NODE_CLASS_MAPPINGS"): + NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) + if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"): + NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) + except Exception as e: + print(f"[Qwen3TTS] Failed to load {py.name}: {e}") + + +_discover_nodes() + +__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] diff --git a/docs/hel-892/structure-reference/ComfyUI__09725967__LICENSE b/docs/hel-892/structure-reference/ComfyUI__09725967__LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI__09725967__LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_audio.py b/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_audio.py new file mode 100644 index 00000000..271b75fb --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_audio.py @@ -0,0 +1,693 @@ +from __future__ import annotations + +import av +import torchaudio +import torch +import comfy.model_management +import folder_paths +import os +import hashlib +import node_helpers +import logging +from typing_extensions import override +from comfy_api.latest import ComfyExtension, IO, UI + +class EmptyLatentAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="EmptyLatentAudio", + display_name="Empty Latent Audio", + category="latent/audio", + inputs=[ + IO.Float.Input("seconds", default=47.6, min=1.0, max=1000.0, step=0.1), + IO.Int.Input( + "batch_size", default=1, min=1, max=4096, tooltip="The number of latent images in the batch." + ), + ], + outputs=[IO.Latent.Output()], + ) + + @classmethod + def execute(cls, seconds, batch_size) -> IO.NodeOutput: + length = round((seconds * 44100 / 2048) / 2) * 2 + latent = torch.zeros([batch_size, 64, length], device=comfy.model_management.intermediate_device()) + return IO.NodeOutput({"samples":latent, "type": "audio"}) + + generate = execute # TODO: remove + + +class ConditioningStableAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="ConditioningStableAudio", + category="conditioning", + inputs=[ + IO.Conditioning.Input("positive"), + IO.Conditioning.Input("negative"), + IO.Float.Input("seconds_start", default=0.0, min=0.0, max=1000.0, step=0.1), + IO.Float.Input("seconds_total", default=47.0, min=0.0, max=1000.0, step=0.1), + ], + outputs=[ + IO.Conditioning.Output(display_name="positive"), + IO.Conditioning.Output(display_name="negative"), + ], + ) + + @classmethod + def execute(cls, positive, negative, seconds_start, seconds_total) -> IO.NodeOutput: + positive = node_helpers.conditioning_set_values(positive, {"seconds_start": seconds_start, "seconds_total": seconds_total}) + negative = node_helpers.conditioning_set_values(negative, {"seconds_start": seconds_start, "seconds_total": seconds_total}) + return IO.NodeOutput(positive, negative) + + append = execute # TODO: remove + + +class VAEEncodeAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="VAEEncodeAudio", + search_aliases=["audio to latent"], + display_name="VAE Encode Audio", + category="latent/audio", + inputs=[ + IO.Audio.Input("audio"), + IO.Vae.Input("vae"), + ], + outputs=[IO.Latent.Output()], + ) + + @classmethod + def execute(cls, vae, audio) -> IO.NodeOutput: + sample_rate = audio["sample_rate"] + if 44100 != sample_rate: + waveform = torchaudio.functional.resample(audio["waveform"], sample_rate, 44100) + else: + waveform = audio["waveform"] + + t = vae.encode(waveform.movedim(1, -1)) + return IO.NodeOutput({"samples":t}) + + encode = execute # TODO: remove + + +class VAEDecodeAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="VAEDecodeAudio", + search_aliases=["latent to audio"], + display_name="VAE Decode Audio", + category="latent/audio", + inputs=[ + IO.Latent.Input("samples"), + IO.Vae.Input("vae"), + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, vae, samples) -> IO.NodeOutput: + audio = vae.decode(samples["samples"]).movedim(-1, 1) + std = torch.std(audio, dim=[1,2], keepdim=True) * 5.0 + std[std < 1.0] = 1.0 + audio /= std + return IO.NodeOutput({"waveform": audio, "sample_rate": 44100 if "sample_rate" not in samples else samples["sample_rate"]}) + + decode = execute # TODO: remove + + +class SaveAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="SaveAudio", + search_aliases=["export flac"], + display_name="Save Audio (FLAC)", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + IO.String.Input("filename_prefix", default="audio/ComfyUI"), + ], + hidden=[IO.Hidden.prompt, IO.Hidden.extra_pnginfo], + is_output_node=True, + ) + + @classmethod + def execute(cls, audio, filename_prefix="ComfyUI", format="flac") -> IO.NodeOutput: + return IO.NodeOutput( + ui=UI.AudioSaveHelper.get_save_audio_ui(audio, filename_prefix=filename_prefix, cls=cls, format=format) + ) + + save_flac = execute # TODO: remove + + +class SaveAudioMP3(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="SaveAudioMP3", + search_aliases=["export mp3"], + display_name="Save Audio (MP3)", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + IO.String.Input("filename_prefix", default="audio/ComfyUI"), + IO.Combo.Input("quality", options=["V0", "128k", "320k"], default="V0"), + ], + hidden=[IO.Hidden.prompt, IO.Hidden.extra_pnginfo], + is_output_node=True, + ) + + @classmethod + def execute(cls, audio, filename_prefix="ComfyUI", format="mp3", quality="128k") -> IO.NodeOutput: + return IO.NodeOutput( + ui=UI.AudioSaveHelper.get_save_audio_ui( + audio, filename_prefix=filename_prefix, cls=cls, format=format, quality=quality + ) + ) + + save_mp3 = execute # TODO: remove + + +class SaveAudioOpus(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="SaveAudioOpus", + search_aliases=["export opus"], + display_name="Save Audio (Opus)", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + IO.String.Input("filename_prefix", default="audio/ComfyUI"), + IO.Combo.Input("quality", options=["64k", "96k", "128k", "192k", "320k"], default="128k"), + ], + hidden=[IO.Hidden.prompt, IO.Hidden.extra_pnginfo], + is_output_node=True, + ) + + @classmethod + def execute(cls, audio, filename_prefix="ComfyUI", format="opus", quality="V3") -> IO.NodeOutput: + return IO.NodeOutput( + ui=UI.AudioSaveHelper.get_save_audio_ui( + audio, filename_prefix=filename_prefix, cls=cls, format=format, quality=quality + ) + ) + + save_opus = execute # TODO: remove + + +class PreviewAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="PreviewAudio", + search_aliases=["play audio"], + display_name="Preview Audio", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + ], + hidden=[IO.Hidden.prompt, IO.Hidden.extra_pnginfo], + is_output_node=True, + ) + + @classmethod + def execute(cls, audio) -> IO.NodeOutput: + return IO.NodeOutput(ui=UI.PreviewAudio(audio, cls=cls)) + + save_flac = execute # TODO: remove + + +def f32_pcm(wav: torch.Tensor) -> torch.Tensor: + """Convert audio to float 32 bits PCM format.""" + if wav.dtype.is_floating_point: + return wav + elif wav.dtype == torch.int16: + return wav.float() / (2 ** 15) + elif wav.dtype == torch.int32: + return wav.float() / (2 ** 31) + raise ValueError(f"Unsupported wav dtype: {wav.dtype}") + +def load(filepath: str) -> tuple[torch.Tensor, int]: + with av.open(filepath) as af: + if not af.streams.audio: + raise ValueError("No audio stream found in the file.") + + stream = af.streams.audio[0] + sr = stream.codec_context.sample_rate + n_channels = stream.channels + + frames = [] + length = 0 + for frame in af.decode(streams=stream.index): + buf = torch.from_numpy(frame.to_ndarray()) + if buf.shape[0] != n_channels: + buf = buf.view(-1, n_channels).t() + + frames.append(buf) + length += buf.shape[1] + + if not frames: + raise ValueError("No audio frames decoded.") + + wav = torch.cat(frames, dim=1) + wav = f32_pcm(wav) + return wav, sr + +class LoadAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + input_dir = folder_paths.get_input_directory() + files = folder_paths.filter_files_content_types(os.listdir(input_dir), ["audio", "video"]) + return IO.Schema( + node_id="LoadAudio", + search_aliases=["import audio", "open audio", "audio file"], + display_name="Load Audio", + category="audio", + inputs=[ + IO.Combo.Input("audio", upload=IO.UploadType.audio, options=sorted(files)), + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio) -> IO.NodeOutput: + audio_path = folder_paths.get_annotated_filepath(audio) + waveform, sample_rate = load(audio_path) + audio = {"waveform": waveform.unsqueeze(0), "sample_rate": sample_rate} + return IO.NodeOutput(audio) + + @classmethod + def fingerprint_inputs(cls, audio): + image_path = folder_paths.get_annotated_filepath(audio) + m = hashlib.sha256() + with open(image_path, 'rb') as f: + m.update(f.read()) + return m.digest().hex() + + @classmethod + def validate_inputs(cls, audio): + if not folder_paths.exists_annotated_filepath(audio): + return "Invalid audio file: {}".format(audio) + return True + + load = execute # TODO: remove + + +class RecordAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="RecordAudio", + search_aliases=["microphone input", "audio capture", "voice input"], + display_name="Record Audio", + category="audio", + inputs=[ + IO.Custom("AUDIO_RECORD").Input("audio"), + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio) -> IO.NodeOutput: + audio_path = folder_paths.get_annotated_filepath(audio) + + waveform, sample_rate = load(audio_path) + audio = {"waveform": waveform.unsqueeze(0), "sample_rate": sample_rate} + return IO.NodeOutput(audio) + + load = execute # TODO: remove + + +class TrimAudioDuration(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="TrimAudioDuration", + search_aliases=["cut audio", "audio clip", "shorten audio"], + display_name="Trim Audio Duration", + description="Trim audio tensor into chosen time range.", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + IO.Float.Input( + "start_index", + default=0.0, + min=-0xffffffffffffffff, + max=0xffffffffffffffff, + step=0.01, + tooltip="Start time in seconds, can be negative to count from the end (supports sub-seconds).", + ), + IO.Float.Input( + "duration", + default=60.0, + min=0.0, + step=0.01, + tooltip="Duration in seconds", + ), + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio, start_index, duration) -> IO.NodeOutput: + waveform = audio["waveform"] + sample_rate = audio["sample_rate"] + audio_length = waveform.shape[-1] + + if start_index < 0: + start_frame = audio_length + int(round(start_index * sample_rate)) + else: + start_frame = int(round(start_index * sample_rate)) + start_frame = max(0, min(start_frame, audio_length - 1)) + + end_frame = start_frame + int(round(duration * sample_rate)) + end_frame = max(0, min(end_frame, audio_length)) + + if start_frame >= end_frame: + raise ValueError("AudioTrim: Start time must be less than end time and be within the audio length.") + + return IO.NodeOutput({"waveform": waveform[..., start_frame:end_frame], "sample_rate": sample_rate}) + + trim = execute # TODO: remove + + +class SplitAudioChannels(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="SplitAudioChannels", + search_aliases=["stereo to mono"], + display_name="Split Audio Channels", + description="Separates the audio into left and right channels.", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + ], + outputs=[ + IO.Audio.Output(display_name="left"), + IO.Audio.Output(display_name="right"), + ], + ) + + @classmethod + def execute(cls, audio) -> IO.NodeOutput: + waveform = audio["waveform"] + sample_rate = audio["sample_rate"] + + if waveform.shape[1] != 2: + raise ValueError("AudioSplit: Input audio has only one channel.") + + left_channel = waveform[..., 0:1, :] + right_channel = waveform[..., 1:2, :] + + return IO.NodeOutput({"waveform": left_channel, "sample_rate": sample_rate}, {"waveform": right_channel, "sample_rate": sample_rate}) + + separate = execute # TODO: remove + +class JoinAudioChannels(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="JoinAudioChannels", + display_name="Join Audio Channels", + description="Joins left and right mono audio channels into a stereo audio.", + category="audio", + inputs=[ + IO.Audio.Input("audio_left"), + IO.Audio.Input("audio_right"), + ], + outputs=[ + IO.Audio.Output(display_name="audio"), + ], + ) + + @classmethod + def execute(cls, audio_left, audio_right) -> IO.NodeOutput: + waveform_left = audio_left["waveform"] + sample_rate_left = audio_left["sample_rate"] + waveform_right = audio_right["waveform"] + sample_rate_right = audio_right["sample_rate"] + + if waveform_left.shape[1] != 1 or waveform_right.shape[1] != 1: + raise ValueError("AudioJoin: Both input audios must be mono.") + + # Handle different sample rates by resampling to the higher rate + waveform_left, waveform_right, output_sample_rate = match_audio_sample_rates( + waveform_left, sample_rate_left, waveform_right, sample_rate_right + ) + + # Handle different lengths by trimming to the shorter length + length_left = waveform_left.shape[-1] + length_right = waveform_right.shape[-1] + + if length_left != length_right: + min_length = min(length_left, length_right) + if length_left > min_length: + logging.info(f"JoinAudioChannels: Trimming left channel from {length_left} to {min_length} samples.") + waveform_left = waveform_left[..., :min_length] + if length_right > min_length: + logging.info(f"JoinAudioChannels: Trimming right channel from {length_right} to {min_length} samples.") + waveform_right = waveform_right[..., :min_length] + + # Join the channels into stereo + left_channel = waveform_left[..., 0:1, :] + right_channel = waveform_right[..., 0:1, :] + stereo_waveform = torch.cat([left_channel, right_channel], dim=1) + + return IO.NodeOutput({"waveform": stereo_waveform, "sample_rate": output_sample_rate}) + + +def match_audio_sample_rates(waveform_1, sample_rate_1, waveform_2, sample_rate_2): + if sample_rate_1 != sample_rate_2: + if sample_rate_1 > sample_rate_2: + waveform_2 = torchaudio.functional.resample(waveform_2, sample_rate_2, sample_rate_1) + output_sample_rate = sample_rate_1 + logging.info(f"Resampling audio2 from {sample_rate_2}Hz to {sample_rate_1}Hz for merging.") + else: + waveform_1 = torchaudio.functional.resample(waveform_1, sample_rate_1, sample_rate_2) + output_sample_rate = sample_rate_2 + logging.info(f"Resampling audio1 from {sample_rate_1}Hz to {sample_rate_2}Hz for merging.") + else: + output_sample_rate = sample_rate_1 + return waveform_1, waveform_2, output_sample_rate + + +class AudioConcat(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="AudioConcat", + search_aliases=["join audio", "combine audio", "append audio"], + display_name="Audio Concat", + description="Concatenates the audio1 to audio2 in the specified direction.", + category="audio", + inputs=[ + IO.Audio.Input("audio1"), + IO.Audio.Input("audio2"), + IO.Combo.Input( + "direction", + options=['after', 'before'], + default="after", + tooltip="Whether to append audio2 after or before audio1.", + ) + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio1, audio2, direction) -> IO.NodeOutput: + waveform_1 = audio1["waveform"] + waveform_2 = audio2["waveform"] + sample_rate_1 = audio1["sample_rate"] + sample_rate_2 = audio2["sample_rate"] + + if waveform_1.shape[1] == 1: + waveform_1 = waveform_1.repeat(1, 2, 1) + logging.info("AudioConcat: Converted mono audio1 to stereo by duplicating the channel.") + if waveform_2.shape[1] == 1: + waveform_2 = waveform_2.repeat(1, 2, 1) + logging.info("AudioConcat: Converted mono audio2 to stereo by duplicating the channel.") + + waveform_1, waveform_2, output_sample_rate = match_audio_sample_rates(waveform_1, sample_rate_1, waveform_2, sample_rate_2) + + if direction == 'after': + concatenated_audio = torch.cat((waveform_1, waveform_2), dim=2) + elif direction == 'before': + concatenated_audio = torch.cat((waveform_2, waveform_1), dim=2) + + return IO.NodeOutput({"waveform": concatenated_audio, "sample_rate": output_sample_rate}) + + concat = execute # TODO: remove + + +class AudioMerge(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="AudioMerge", + search_aliases=["mix audio", "overlay audio", "layer audio"], + display_name="Audio Merge", + description="Combine two audio tracks by overlaying their waveforms.", + category="audio", + inputs=[ + IO.Audio.Input("audio1"), + IO.Audio.Input("audio2"), + IO.Combo.Input( + "merge_method", + options=["add", "mean", "subtract", "multiply"], + tooltip="The method used to combine the audio waveforms.", + ) + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio1, audio2, merge_method) -> IO.NodeOutput: + waveform_1 = audio1["waveform"] + waveform_2 = audio2["waveform"] + sample_rate_1 = audio1["sample_rate"] + sample_rate_2 = audio2["sample_rate"] + + waveform_1, waveform_2, output_sample_rate = match_audio_sample_rates(waveform_1, sample_rate_1, waveform_2, sample_rate_2) + + length_1 = waveform_1.shape[-1] + length_2 = waveform_2.shape[-1] + + if length_2 > length_1: + logging.info(f"AudioMerge: Trimming audio2 from {length_2} to {length_1} samples to match audio1 length.") + waveform_2 = waveform_2[..., :length_1] + elif length_2 < length_1: + logging.info(f"AudioMerge: Padding audio2 from {length_2} to {length_1} samples to match audio1 length.") + pad_shape = list(waveform_2.shape) + pad_shape[-1] = length_1 - length_2 + pad_tensor = torch.zeros(pad_shape, dtype=waveform_2.dtype, device=waveform_2.device) + waveform_2 = torch.cat((waveform_2, pad_tensor), dim=-1) + + if merge_method == "add": + waveform = waveform_1 + waveform_2 + elif merge_method == "subtract": + waveform = waveform_1 - waveform_2 + elif merge_method == "multiply": + waveform = waveform_1 * waveform_2 + elif merge_method == "mean": + waveform = (waveform_1 + waveform_2) / 2 + + max_val = waveform.abs().max() + if max_val > 1.0: + waveform = waveform / max_val + + return IO.NodeOutput({"waveform": waveform, "sample_rate": output_sample_rate}) + + merge = execute # TODO: remove + + +class AudioAdjustVolume(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="AudioAdjustVolume", + search_aliases=["audio gain", "loudness", "audio level"], + display_name="Audio Adjust Volume", + category="audio", + inputs=[ + IO.Audio.Input("audio"), + IO.Int.Input( + "volume", + default=1, + min=-100, + max=100, + tooltip="Volume adjustment in decibels (dB). 0 = no change, +6 = double, -6 = half, etc", + ) + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, audio, volume) -> IO.NodeOutput: + if volume == 0: + return IO.NodeOutput(audio) + waveform = audio["waveform"] + sample_rate = audio["sample_rate"] + + gain = 10 ** (volume / 20) + waveform = waveform * gain + + return IO.NodeOutput({"waveform": waveform, "sample_rate": sample_rate}) + + adjust_volume = execute # TODO: remove + + +class EmptyAudio(IO.ComfyNode): + @classmethod + def define_schema(cls): + return IO.Schema( + node_id="EmptyAudio", + search_aliases=["blank audio"], + display_name="Empty Audio", + category="audio", + inputs=[ + IO.Float.Input( + "duration", + default=60.0, + min=0.0, + max=0xffffffffffffffff, + step=0.01, + tooltip="Duration of the empty audio clip in seconds", + ), + IO.Int.Input( + "sample_rate", + default=44100, + tooltip="Sample rate of the empty audio clip.", + min=1, + max=192000, + ), + IO.Int.Input( + "channels", + default=2, + min=1, + max=2, + tooltip="Number of audio channels (1 for mono, 2 for stereo).", + ), + ], + outputs=[IO.Audio.Output()], + ) + + @classmethod + def execute(cls, duration, sample_rate, channels) -> IO.NodeOutput: + num_samples = int(round(duration * sample_rate)) + waveform = torch.zeros((1, channels, num_samples), dtype=torch.float32) + return IO.NodeOutput({"waveform": waveform, "sample_rate": sample_rate}) + + create_empty_audio = execute # TODO: remove + + +class AudioExtension(ComfyExtension): + @override + async def get_node_list(self) -> list[type[IO.ComfyNode]]: + return [ + EmptyLatentAudio, + VAEEncodeAudio, + VAEDecodeAudio, + SaveAudio, + SaveAudioMP3, + SaveAudioOpus, + LoadAudio, + PreviewAudio, + ConditioningStableAudio, + RecordAudio, + TrimAudioDuration, + SplitAudioChannels, + JoinAudioChannels, + AudioConcat, + AudioMerge, + AudioAdjustVolume, + EmptyAudio, + ] + +async def comfy_entrypoint() -> AudioExtension: + return AudioExtension() diff --git a/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_preview_any.py b/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_preview_any.py new file mode 100644 index 00000000..b0a6f279 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI__09725967__comfy_extras__nodes_preview_any.py @@ -0,0 +1,44 @@ +import json +from comfy.comfy_types.node_typing import IO + +# Preview Any - original implement from +# https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py +# upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes +class PreviewAny(): + @classmethod + def INPUT_TYPES(cls): + return { + "required": {"source": (IO.ANY, {})}, + } + + RETURN_TYPES = () + FUNCTION = "main" + OUTPUT_NODE = True + + CATEGORY = "utils" + SEARCH_ALIASES = ["show output", "inspect", "debug", "print value", "show text"] + + def main(self, source=None): + value = 'None' + if isinstance(source, str): + value = source + elif isinstance(source, (int, float, bool)): + value = str(source) + elif source is not None: + try: + value = json.dumps(source, indent=4) + except Exception: + try: + value = str(source) + except Exception: + value = 'source exists, but could not be serialized.' + + return {"ui": {"text": (value,)}} + +NODE_CLASS_MAPPINGS = { + "PreviewAny": PreviewAny, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "PreviewAny": "Preview as Text", +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__packages__shared-frontend-utils__src__formatUtil.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__packages__shared-frontend-utils__src__formatUtil.ts new file mode 100644 index 00000000..032d1c9e --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__packages__shared-frontend-utils__src__formatUtil.ts @@ -0,0 +1,552 @@ +import type { operations } from '@comfyorg/registry-types' + +export function formatCamelCase(str: string): string { + // Check if the string is camel case + const isCamelCase = /^([A-Z][a-z]*)+$/.test(str) + + if (!isCamelCase) { + return str // Return original string if not camel case + } + + // Split the string into words, keeping acronyms together + const words = str.split(/(?=[A-Z][a-z])|\d+/) + + // Process each word + const processedWords = words.map((word) => { + // If the word is all uppercase and longer than one character, it's likely an acronym + if (word.length > 1 && word === word.toUpperCase()) { + return word // Keep acronyms as is + } + // For other words, ensure the first letter is capitalized + return word.charAt(0).toUpperCase() + word.slice(1) + }) + + // Join the words with spaces + return processedWords.join(' ') +} + +export function appendJsonExt(path: string) { + if (!path.toLowerCase().endsWith('.json')) { + path += '.json' + } + return path +} + +export function highlightQuery(text: string, query: string) { + if (!query) return text + + // Escape special regex characters in the query string + const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + + const regex = new RegExp(`(${escapedQuery})`, 'gi') + return text.replace(regex, '$1') +} + +export function formatNumberWithSuffix( + num: number, + { + precision = 1, + roundToInt = false + }: { precision?: number; roundToInt?: boolean } = {} +): string { + const suffixes = ['', 'k', 'm', 'b', 't'] + const absNum = Math.abs(num) + + if (absNum < 1000) { + return roundToInt ? Math.round(num).toString() : num.toFixed(precision) + } + + const exp = Math.min(Math.floor(Math.log10(absNum) / 3), suffixes.length - 1) + const formattedNum = (num / Math.pow(1000, exp)).toFixed(precision) + + return `${formattedNum}${suffixes[exp]}` +} + +export function formatSize(value?: number) { + if (value === null || value === undefined) { + return '-' + } + + const bytes = value + if (bytes === 0) return '0 B' + const k = 1024 + const sizes = ['B', 'KB', 'MB', 'GB'] + const i = Math.floor(Math.log(bytes) / Math.log(k)) + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}` +} + +/** + * Formats a commit hash by truncating long (40-char) hashes to 7 chars. + * Returns the original string if not a valid full commit hash. + */ +export function formatCommitHash(value: string): string { + if (/^[a-f0-9]{40}$/i.test(value)) { + return value.slice(0, 7) + } + return value +} + +/** + * Returns various filename components. + * Example: + * - fullFilename: 'file.txt' + * - filename: 'file' + * - suffix: 'txt' + */ +export function getFilenameDetails(fullFilename: string) { + if (fullFilename.includes('.')) { + return { + filename: fullFilename.split('.').slice(0, -1).join('.'), + suffix: fullFilename.split('.').pop() ?? null + } + } else { + return { filename: fullFilename, suffix: null } + } +} + +/** + * Returns various path components. + * Example: + * - path: 'dir/file.txt' + * - directory: 'dir' + * - fullFilename: 'file.txt' + * - filename: 'file' + * - suffix: 'txt' + */ +export function getPathDetails(path: string) { + const directory = path.split('/').slice(0, -1).join('/') + const fullFilename = path.split('/').pop() ?? path + return { directory, fullFilename, ...getFilenameDetails(fullFilename) } +} + +/** + * Normalizes a string to be used as an i18n key. + * Replaces dots with underscores. + */ +export function normalizeI18nKey(key: string) { + return typeof key === 'string' ? key.replace(/\./g, '_') : '' +} + +/** + * Takes a dynamic prompt in the format {opt1|opt2|{optA|optB}|} and randomly replaces groups. Supports C style comments. + * @param input The dynamic prompt to process + * @returns + */ +export function processDynamicPrompt(input: string): string { + /* + * Strips C-style line and block comments from a string + */ + function stripComments(str: string) { + return str.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '') + } + + let i = 0 + let result = '' + input = stripComments(input) + + const handleEscape = () => { + const nextChar = input[i++] + return '\\' + nextChar + } + + function parseChoiceBlock() { + // Parse the content inside {} + const options: string[] = [] + let choice = '' + let depth = 0 + + while (i < input.length) { + const char = input[i++] + + if (char === '\\') { + choice += handleEscape() + continue + } else if (char === '{') { + depth++ + } else if (char === '}') { + if (!depth) break + depth-- + } else if (char === '|') { + if (!depth) { + options.push(choice) + choice = '' + continue + } + } + choice += char + } + + options.push(choice) + + const chosenOption = options[Math.floor(Math.random() * options.length)] + return processDynamicPrompt(chosenOption) + } + + while (i < input.length) { + const char = input[i++] + if (char === '\\') { + result += handleEscape() + } else if (char === '{') { + result += parseChoiceBlock() + } else { + result += char + } + } + + return result.replace(/\\([{}|])/g, '$1') +} + +export function isValidUrl(url: string): boolean { + try { + new URL(url) + return true + } catch { + return false + } +} + +/** + * Parses a filepath into its filename and subfolder components. + * + * @example + * parseFilePath('folder/file.txt') // → { filename: 'file.txt', subfolder: 'folder' } + * parseFilePath('/folder/file.txt') // → { filename: 'file.txt', subfolder: 'folder' } + * parseFilePath('file.txt') // → { filename: 'file.txt', subfolder: '' } + * parseFilePath('folder//file.txt') // → { filename: 'file.txt', subfolder: 'folder' } + * + * @param filepath The filepath to parse + * @returns Object containing filename and subfolder + */ +export function parseFilePath(filepath: string): { + filename: string + subfolder: string +} { + if (!filepath?.trim()) return { filename: '', subfolder: '' } + + const normalizedPath = filepath + .replace(/[\\/]+/g, '/') // Normalize path separators + .replace(/^\//, '') // Remove leading slash + .replace(/\/$/, '') // Remove trailing slash + + const lastSlashIndex = normalizedPath.lastIndexOf('/') + + if (lastSlashIndex === -1) { + return { + filename: normalizedPath, + subfolder: '' + } + } + + return { + filename: normalizedPath.slice(lastSlashIndex + 1), + subfolder: normalizedPath.slice(0, lastSlashIndex) + } +} + +// Simple date formatter +const parts = { + d: (d: Date) => d.getDate(), + M: (d: Date) => d.getMonth() + 1, + h: (d: Date) => d.getHours(), + m: (d: Date) => d.getMinutes(), + s: (d: Date) => d.getSeconds() +} +const format = + Object.keys(parts) + .map((k) => k + k + '?') + .join('|') + '|yyy?y?' + +export function formatDate(text: string, date: Date) { + return text.replace(new RegExp(format, 'g'), (text: string): string => { + if (text === 'yy') return (date.getFullYear() + '').substring(2) + if (text === 'yyyy') return date.getFullYear().toString() + if (text[0] in parts) { + const p = parts[text[0] as keyof typeof parts](date) + return (p + '').padStart(text.length, '0') + } + return text + }) +} + +/** + * Generate a cache key from parameters + * Sorts the parameters to ensure consistent keys regardless of parameter order + */ +export const paramsToCacheKey = (params: unknown): string => { + if (typeof params === 'string') return params + if (typeof params === 'object' && params !== null) + return Object.keys(params) + .sort((a, b) => a.localeCompare(b)) + .map((key) => `${key}:${params[key as keyof typeof params]}`) + .join('&') + + return String(params) +} + +/** + * Generates a RFC4122 compliant UUID v4 using the native crypto API when available + * @returns A properly formatted UUID string + */ +export const generateUUID = (): string => { + // Use native crypto.randomUUID() if available (modern browsers) + if ( + typeof crypto !== 'undefined' && + typeof crypto.randomUUID === 'function' + ) { + return crypto.randomUUID() + } + + // Fallback implementation for older browsers + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0 + const v = c === 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) +} + +/** + * Checks if a URL is a Civitai model URL + * @example + * isCivitaiModelUrl('https://civitai.com/api/download/models/1234567890') // true + * isCivitaiModelUrl('https://civitai.com/api/v1/models/1234567890') // true + * isCivitaiModelUrl('https://civitai.com/api/v1/models-versions/15342') // true + * isCivitaiModelUrl('https://example.com/model.safetensors') // false + */ +export const isCivitaiModelUrl = (url: string): boolean => { + if (!isValidUrl(url)) return false + if (!url.includes('civitai.com')) return false + + const urlObj = new URL(url) + const pathname = urlObj.pathname + + return ( + /^\/api\/download\/models\/(\d+)$/.test(pathname) || + /^\/api\/v1\/models\/(\d+)$/.test(pathname) || + /^\/api\/v1\/models-versions\/(\d+)$/.test(pathname) + ) +} + +/** + * Converts a Hugging Face download URL to a repository page URL + * @param url The download URL to convert + * @returns The repository page URL or the original URL if conversion fails + * @example + * downloadUrlToHfRepoUrl( + * 'https://huggingface.co/bfl/FLUX.1/resolve/main/flux1-canny-dev.safetensors?download=true' + * ) // https://huggingface.co/bfl/FLUX.1 + */ +export const downloadUrlToHfRepoUrl = (url: string): string => { + try { + const urlObj = new URL(url) + const pathname = urlObj.pathname + + // Use regex to match everything before /resolve/ or /blob/ + const regex = /^(.*?)(?:\/resolve\/|\/blob\/|$)/ + const repoPathMatch = regex.exec(pathname) + + // Extract the repository path and remove leading slash if present + const repoPath = repoPathMatch?.[1]?.replace(/^\//, '') || '' + + return `https://huggingface.co/${repoPath}` + } catch (error) { + return url + } +} + +/** + * Converts Metronome's integer amount back to a formatted currency string. + * For USD, converts from cents to dollars. + * For all other currencies (including custom pricing units), returns the amount as is. + * This is specific to Metronome's API requirements. + * + * @param amount - The amount in Metronome's integer format (cents for USD, base units for others) + * @param currency - The currency to convert + * @returns The formatted amount in currency with 2 decimal places for USD + * @example + * formatMetronomeCurrency(123, 'usd') // returns "1.23" (cents to USD) + * formatMetronomeCurrency(1000, 'jpy') // returns "1000" (yen) + */ +export function formatMetronomeCurrency( + amount: number, + currency: string +): string { + if (currency === 'usd') { + return (amount / 100).toFixed(2) + } + return amount.toString() +} + +/** + * Converts a USD amount to microdollars (1/1,000,000 of a dollar). + * This conversion is commonly used in financial systems to avoid floating-point precision issues + * by representing monetary values as integers. + * + * @param usd - The amount in US dollars to convert + * @returns The amount in microdollars (multiplied by 1,000,000) + * @example + * usdToMicros(1.23) // returns 1230000 + */ +export function usdToMicros(usd: number): number { + return Math.round(usd * 1_000_000) +} + +/** + * Converts URLs in a string to HTML links. + * @param text - The string to convert + * @returns The string with URLs converted to HTML links + * @example + * linkifyHtml('Visit https://example.com for more info') // returns 'Visit https://example.com for more info' + */ +export function linkifyHtml(text: string): string { + if (!text) return '' + const urlRegex = + /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%?=~_|])|(\bwww\.[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%?=~_|])/gi + return text.replace(urlRegex, (_match, p1, _p2, p3) => { + const url = p1 || p3 + const href = p3 ? `http://${url}` : url + return `${url}` + }) +} + +/** + * Converts newline characters to HTML
tags. + * @param text - The string to convert + * @returns The string with newline characters converted to
tags + * @example + * nl2br('Hello\nWorld') // returns 'Hello
World' + */ +export function nl2br(text: string): string { + if (!text) return '' + return text.replace(/\n/g, '
') +} + +/** + * Converts a version string to an anchor-safe format by replacing dots with dashes. + * @param version The version string (e.g., "1.0.0", "2.1.3-beta.1") + * @returns The anchor-safe version string (e.g., "v1-0-0", "v2-1-3-beta-1") + * @example + * formatVersionAnchor("1.0.0") // returns "v1-0-0" + * formatVersionAnchor("2.1.3-beta.1") // returns "v2-1-3-beta-1" + */ +export function formatVersionAnchor(version: string): string { + return `v${version.replace(/\./g, '-')}` +} + +/** + * Supported locale types for the application (from OpenAPI schema) + */ +type SupportedLocale = NonNullable< + operations['getReleaseNotes']['parameters']['query']['locale'] +> + +/** + * Converts a string to a valid locale type with 'en' as default + * @param locale - The locale string to validate and convert + * @returns A valid SupportedLocale type, defaults to 'en' if invalid + * @example + * stringToLocale('fr') // returns 'fr' + * stringToLocale('invalid') // returns 'en' + * stringToLocale('') // returns 'en' + */ +export function stringToLocale(locale: string): SupportedLocale { + const supportedLocales: SupportedLocale[] = [ + 'en', + 'es', + 'fr', + 'ja', + 'ko', + 'ru', + 'zh' + ] + return supportedLocales.includes(locale as SupportedLocale) + ? (locale as SupportedLocale) + : 'en' +} + +export function formatDuration(milliseconds: number): string { + if (!milliseconds || milliseconds < 0) return '0s' + + const totalSeconds = Math.floor(milliseconds / 1000) + const hours = Math.floor(totalSeconds / 3600) + const minutes = Math.floor((totalSeconds % 3600) / 60) + const remainingSeconds = Math.floor(totalSeconds % 60) + + const parts: string[] = [] + + if (hours > 0) { + parts.push(`${hours}h`) + } + if (minutes > 0) { + parts.push(`${minutes}m`) + } + if (remainingSeconds > 0 || parts.length === 0) { + parts.push(`${remainingSeconds}s`) + } + + return parts.join(' ') +} + +const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'] as const +const VIDEO_EXTENSIONS = ['mp4', 'webm', 'mov', 'avi'] as const +const AUDIO_EXTENSIONS = ['mp3', 'wav', 'ogg', 'flac'] as const +const THREE_D_EXTENSIONS = ['obj', 'fbx', 'gltf', 'glb'] as const + +const MEDIA_TYPES = ['image', 'video', 'audio', '3D'] as const +type MediaType = (typeof MEDIA_TYPES)[number] + +// Type guard helper for checking array membership +type ImageExtension = (typeof IMAGE_EXTENSIONS)[number] +type VideoExtension = (typeof VIDEO_EXTENSIONS)[number] +type AudioExtension = (typeof AUDIO_EXTENSIONS)[number] +type ThreeDExtension = (typeof THREE_D_EXTENSIONS)[number] + +/** + * Truncates a filename while preserving the extension + * @param filename The filename to truncate + * @param maxLength Maximum length for the filename without extension + * @returns Truncated filename with extension preserved + */ +export function truncateFilename( + filename: string, + maxLength: number = 20 +): string { + if (!filename || filename.length <= maxLength) { + return filename + } + + const lastDotIndex = filename.lastIndexOf('.') + const nameWithoutExt = + lastDotIndex > -1 ? filename.substring(0, lastDotIndex) : filename + const extension = lastDotIndex > -1 ? filename.substring(lastDotIndex) : '' + + // If the name without extension is short enough, return as is + if (nameWithoutExt.length <= maxLength) { + return filename + } + + // Calculate how to split the truncation + const halfLength = Math.floor((maxLength - 3) / 2) // -3 for '...' + const start = nameWithoutExt.substring(0, halfLength) + const end = nameWithoutExt.substring(nameWithoutExt.length - halfLength) + + return `${start}...${end}${extension}` +} + +/** + * Determines the media type from a filename's extension (singular form) + * @param filename The filename to analyze + * @returns The media type: 'image', 'video', 'audio', or '3D' + */ +export function getMediaTypeFromFilename(filename: string): MediaType { + if (!filename) return 'image' + const ext = filename.split('.').pop()?.toLowerCase() + if (!ext) return 'image' + + // Type-safe array includes check using type assertion + if (IMAGE_EXTENSIONS.includes(ext as ImageExtension)) return 'image' + if (VIDEO_EXTENSIONS.includes(ext as VideoExtension)) return 'video' + if (AUDIO_EXTENSIONS.includes(ext as AudioExtension)) return 'audio' + if (THREE_D_EXTENSIONS.includes(ext as ThreeDExtension)) return '3D' + + return 'image' +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__previewAny.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__previewAny.ts new file mode 100644 index 00000000..d9d09370 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__previewAny.ts @@ -0,0 +1,83 @@ +/* +Preview Any - original implement from +https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py +upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes + */ +import { app } from '@/scripts/app' +import { type DOMWidget } from '@/scripts/domWidget' +import { ComfyWidgets } from '@/scripts/widgets' +import { useExtensionService } from '@/services/extensionService' + +useExtensionService().registerExtension({ + name: 'Comfy.PreviewAny', + async beforeRegisterNodeDef(nodeType, nodeData) { + if (nodeData.name === 'PreviewAny') { + const onNodeCreated = nodeType.prototype.onNodeCreated + + nodeType.prototype.onNodeCreated = function () { + onNodeCreated ? onNodeCreated.apply(this, []) : undefined + + const showValueWidget = ComfyWidgets['MARKDOWN']( + this, + 'preview', + ['MARKDOWN', {}], + app + ).widget as DOMWidget + + const showValueWidgetPlain = ComfyWidgets['STRING']( + this, + 'preview', + ['STRING', { multiline: true }], + app + ).widget as DOMWidget + + const showAsPlaintextWidget = ComfyWidgets['BOOLEAN']( + this, + 'previewMode', + [ + 'BOOLEAN', + { label_on: 'Markdown', label_off: 'Plaintext', default: false } + ], + app + ) + + showAsPlaintextWidget.widget.callback = (value: boolean) => { + showValueWidget.hidden = !value + showValueWidget.options.hidden = !value + showValueWidgetPlain.hidden = value + showValueWidgetPlain.options.hidden = value + } + + showValueWidget.hidden = true + showValueWidget.options.hidden = true + showValueWidget.options.read_only = true + showValueWidget.element.readOnly = true + showValueWidget.element.disabled = true + showValueWidget.serialize = false + + showValueWidgetPlain.hidden = false + showValueWidgetPlain.options.hidden = false + showValueWidgetPlain.options.read_only = true + showValueWidgetPlain.element.readOnly = true + showValueWidgetPlain.element.disabled = true + showValueWidgetPlain.serialize = false + } + + const onExecuted = nodeType.prototype.onExecuted + + nodeType.prototype.onExecuted = function (message) { + onExecuted === null || onExecuted === void 0 + ? void 0 + : onExecuted.apply(this, [message]) + + const previewWidgets = + this.widgets?.filter((w) => w.name === 'preview') ?? [] + + for (const previewWidget of previewWidgets) { + const text = message.text ?? '' + previewWidget.value = Array.isArray(text) ? (text[0] ?? '') : text + } + } + } + } +}) diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__uploadAudio.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__uploadAudio.ts new file mode 100644 index 00000000..71c2295d --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__extensions__core__uploadAudio.ts @@ -0,0 +1,411 @@ +import { MediaRecorder as ExtendableMediaRecorder } from 'extendable-media-recorder' + +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop' +import { useNodeFileInput } from '@/composables/node/useNodeFileInput' +import { useNodePaste } from '@/composables/node/useNodePaste' +import { t } from '@/i18n' +import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import type { + IBaseWidget, + IStringWidget +} from '@/lib/litegraph/src/types/widgets' +import { useToastStore } from '@/platform/updates/common/toastStore' +import { + getResourceURL, + splitFilePath +} from '@/renderer/extensions/vueNodes/widgets/utils/audioUtils' +import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' +import type { DOMWidget } from '@/scripts/domWidget' +import { useAudioService } from '@/services/audioService' +import { type NodeLocatorId } from '@/types' +import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' + +import { api } from '../../scripts/api' +import { app } from '../../scripts/app' + +async function uploadFile( + audioWidget: IStringWidget, + audioUIWidget: DOMWidget, + file: File, + updateNode: boolean, + pasted: boolean = false +) { + try { + // Wrap file in formdata so it includes filename + const body = new FormData() + body.append('image', file) + if (pasted) body.append('subfolder', 'pasted') + const resp = await api.fetchApi('/upload/image', { + method: 'POST', + body + }) + + if (resp.status === 200) { + const data = await resp.json() + // Add the file to the dropdown list and update the widget value + let path = data.name + if (data.subfolder) path = data.subfolder + '/' + path + + // @ts-expect-error fixme ts strict error + if (!audioWidget.options.values.includes(path)) { + // @ts-expect-error fixme ts strict error + audioWidget.options.values.push(path) + } + + if (updateNode) { + audioUIWidget.element.src = api.apiURL( + getResourceURL(...splitFilePath(path)) + ) + audioWidget.value = path + + // Manually trigger the callback to update VueNodes + audioWidget.callback?.(path) + } + } else { + useToastStore().addAlert(resp.status + ' - ' + resp.statusText) + } + } catch (error) { + // @ts-expect-error fixme ts strict error + useToastStore().addAlert(error) + } +} + +// AudioWidget MUST be registered first, as AUDIOUPLOAD depends on AUDIO_UI to be +// present. +app.registerExtension({ + name: 'Comfy.AudioWidget', + async beforeRegisterNodeDef(nodeType, nodeData) { + if ( + [ + 'LoadAudio', + 'SaveAudio', + 'PreviewAudio', + 'SaveAudioMP3', + 'SaveAudioOpus' + ].includes( + // @ts-expect-error fixme ts strict error + nodeType.prototype.comfyClass + ) + ) { + // @ts-expect-error fixme ts strict error + nodeData.input.required.audioUI = ['AUDIO_UI', {}] + } + }, + getCustomWidgets() { + return { + AUDIO_UI(node: LGraphNode, inputName: string) { + const audio = document.createElement('audio') + audio.controls = true + audio.classList.add('comfy-audio') + audio.setAttribute('name', 'media') + + const audioUIWidget: DOMWidget = + node.addDOMWidget(inputName, /* name=*/ 'audioUI', audio) + audioUIWidget.serialize = false + const { nodeData } = node.constructor + if (nodeData == null) throw new TypeError('nodeData is null') + + const isOutputNode = nodeData.output_node + if (isOutputNode) { + // Hide the audio widget when there is no audio initially. + audioUIWidget.element.classList.add('empty-audio-widget') + // Populate the audio widget UI on node execution. + const onExecuted = node.onExecuted + node.onExecuted = function (message: any) { + // @ts-expect-error fixme ts strict error + onExecuted?.apply(this, arguments) + const audios = message.audio + if (!audios) return + const audio = audios[0] + audioUIWidget.element.src = api.apiURL( + getResourceURL(audio.subfolder, audio.filename, audio.type) + ) + audioUIWidget.element.classList.remove('empty-audio-widget') + } + } + + audioUIWidget.onRemove = useChainCallback( + audioUIWidget.onRemove, + () => { + if (!audioUIWidget.element) return + audioUIWidget.element.pause() + audioUIWidget.element.src = '' + audioUIWidget.element.remove() + } + ) + + return { widget: audioUIWidget } + } + } + }, + onNodeOutputsUpdated(nodeOutputs: Record) { + for (const [nodeLocatorId, output] of Object.entries(nodeOutputs)) { + if ('audio' in output) { + const node = getNodeByLocatorId(app.rootGraph, nodeLocatorId) + if (!node) continue + + // @ts-expect-error fixme ts strict error + const audioUIWidget = node.widgets.find( + (w) => w.name === 'audioUI' + ) as unknown as DOMWidget + const audio = output.audio[0] + audioUIWidget.element.src = api.apiURL( + getResourceURL(audio.subfolder, audio.filename, audio.type) + ) + audioUIWidget.element.classList.remove('empty-audio-widget') + } + } + } +}) + +app.registerExtension({ + name: 'Comfy.UploadAudio', + async beforeRegisterNodeDef(_nodeType, nodeData: ComfyNodeDef) { + if (nodeData?.input?.required?.audio?.[1]?.audio_upload === true) { + nodeData.input.required.upload = ['AUDIOUPLOAD', {}] + } + }, + getCustomWidgets() { + return { + AUDIOUPLOAD(node, inputName: string) { + // The widget that allows user to select file. + // @ts-expect-error fixme ts strict error + const audioWidget = node.widgets.find( + (w) => w.name === 'audio' + ) as IStringWidget + // @ts-expect-error fixme ts strict error + const audioUIWidget = node.widgets.find( + (w) => w.name === 'audioUI' + ) as unknown as DOMWidget + audioUIWidget.options.canvasOnly = true + + const onAudioWidgetUpdate = () => { + if (typeof audioWidget.value !== 'string') return + audioUIWidget.element.src = api.apiURL( + getResourceURL(...splitFilePath(audioWidget.value)) + ) + } + // Initially load default audio file to audioUIWidget. + if (audioWidget.value) { + onAudioWidgetUpdate() + } + audioWidget.callback = onAudioWidgetUpdate + + // Load saved audio file widget values if restoring from workflow + const onGraphConfigured = node.onGraphConfigured + node.onGraphConfigured = function () { + // @ts-expect-error fixme ts strict error + onGraphConfigured?.apply(this, arguments) + if (audioWidget.value) { + onAudioWidgetUpdate() + } + } + + const handleUpload = async (files: File[]) => { + if (files?.length) { + uploadFile(audioWidget, audioUIWidget, files[0], true) + } + return files + } + + const isAudioFile = (file: File) => file.type.startsWith('audio/') + + const { openFileSelection } = useNodeFileInput(node, { + accept: 'audio/*', + onSelect: handleUpload + }) + + // The widget to pop up the upload dialog. + const uploadWidget = node.addWidget( + 'button', + inputName, + '', + openFileSelection, + { serialize: false, canvasOnly: true } + ) + uploadWidget.label = t('g.choose_file_to_upload') + + useNodeDragAndDrop(node, { + fileFilter: isAudioFile, + onDrop: handleUpload + }) + + useNodePaste(node, { + fileFilter: isAudioFile, + onPaste: handleUpload + }) + + node.previewMediaType = 'audio' + + return { widget: uploadWidget } + } + } + } +}) + +app.registerExtension({ + name: 'Comfy.RecordAudio', + + getCustomWidgets() { + return { + AUDIO_RECORD(node, inputName: string) { + const audio = document.createElement('audio') + audio.controls = true + audio.classList.add('comfy-audio') + audio.setAttribute('name', 'media') + const audioUIWidget: DOMWidget = + node.addDOMWidget(inputName, /* name=*/ 'audioUI', audio) + audioUIWidget.options.canvasOnly = false + + let mediaRecorder: MediaRecorder | null = null + let isRecording = false + let audioChunks: Blob[] = [] + let currentStream: MediaStream | null = null + let recordWidget: IBaseWidget | null = null + + let stopPromise: Promise | null = null + let stopResolve: (() => void) | null = null + + audioUIWidget.serializeValue = async () => { + if (isRecording && mediaRecorder) { + stopPromise = new Promise((resolve) => { + stopResolve = resolve + }) + + mediaRecorder.stop() + + await stopPromise + } + + const audioSrc = audioUIWidget.element.src + + if (!audioSrc) { + useToastStore().addAlert(t('g.noAudioRecorded')) + return '' + } + + const blob = await fetch(audioSrc).then((r) => r.blob()) + + return await useAudioService().convertBlobToFileAndSubmit(blob) + } + + recordWidget = node.addWidget( + 'button', + inputName, + '', + async () => { + if (!isRecording) { + try { + currentStream = await navigator.mediaDevices.getUserMedia({ + audio: true + }) + + mediaRecorder = new ExtendableMediaRecorder(currentStream, { + mimeType: 'audio/wav' + }) as unknown as MediaRecorder + + audioChunks = [] + + mediaRecorder.ondataavailable = (event) => { + audioChunks.push(event.data) + } + + mediaRecorder.onstop = async () => { + const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }) + + useAudioService().stopAllTracks(currentStream) + + if ( + audioUIWidget.element.src && + audioUIWidget.element.src.startsWith('blob:') + ) { + URL.revokeObjectURL(audioUIWidget.element.src) + } + + audioUIWidget.element.src = URL.createObjectURL(audioBlob) + + isRecording = false + + if (recordWidget) { + recordWidget.label = t('g.startRecording') + } + + if (stopResolve) { + stopResolve() + stopResolve = null + stopPromise = null + } + } + + mediaRecorder.onerror = (event) => { + console.error('MediaRecorder error:', event) + useAudioService().stopAllTracks(currentStream) + isRecording = false + + if (recordWidget) { + recordWidget.label = t('g.startRecording') + } + + if (stopResolve) { + stopResolve() + stopResolve = null + stopPromise = null + } + } + + mediaRecorder.start() + isRecording = true + if (recordWidget) { + recordWidget.label = t('g.stopRecording') + } + } catch (err) { + console.error('Error accessing microphone:', err) + useToastStore().addAlert(t('g.micPermissionDenied')) + + if (mediaRecorder) { + try { + mediaRecorder.stop() + } catch {} + } + useAudioService().stopAllTracks(currentStream) + currentStream = null + isRecording = false + if (recordWidget) { + recordWidget.label = t('g.startRecording') + } + } + } else if (mediaRecorder && isRecording) { + mediaRecorder.stop() + } + }, + { serialize: false, canvasOnly: false } + ) + + recordWidget.label = t('g.startRecording') + // Override the type for Vue rendering while keeping 'button' for LiteGraph + recordWidget.type = 'audiorecord' + + const originalOnRemoved = node.onRemoved + node.onRemoved = function () { + if (isRecording && mediaRecorder) { + mediaRecorder.stop() + } + useAudioService().stopAllTracks(currentStream) + if (audioUIWidget.element.src?.startsWith('blob:')) { + URL.revokeObjectURL(audioUIWidget.element.src) + } + originalOnRemoved?.call(this) + } + + return { widget: recordWidget } + } + } + }, + + async nodeCreated(node) { + if (node.constructor.comfyClass !== 'RecordAudio') return + + await useAudioService().registerWavEncoder() + } +}) diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__LGraphNode.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__LGraphNode.ts new file mode 100644 index 00000000..0ca41a73 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__LGraphNode.ts @@ -0,0 +1,4198 @@ +import { LGraphNodeProperties } from '@/lib/litegraph/src/LGraphNodeProperties' +import { + calculateInputSlotPos, + calculateInputSlotPosFromSlot, + calculateOutputSlotPos, + getSlotPosition +} from '@/renderer/core/canvas/litegraph/slotCalculations' +import type { SlotPositionContext } from '@/renderer/core/canvas/litegraph/slotCalculations' +import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations' +import { LayoutSource } from '@/renderer/core/layout/types' +import { adjustColor } from '@/utils/colorUtil' +import type { ColorAdjustOptions } from '@/utils/colorUtil' +import { commonType, toClass } from '@/lib/litegraph/src/utils/type' + +import { SUBGRAPH_OUTPUT_ID } from '@/lib/litegraph/src/constants' +import type { DragAndScale } from './DragAndScale' +import type { LGraph } from './LGraph' +import { BadgePosition, LGraphBadge } from './LGraphBadge' +import { LGraphButton } from './LGraphButton' +import type { LGraphButtonOptions } from './LGraphButton' +import { LGraphCanvas } from './LGraphCanvas' +import { LLink } from './LLink' +import type { Reroute, RerouteId } from './Reroute' +import { getNodeInputOnPos, getNodeOutputOnPos } from './canvas/measureSlots' +import type { IDrawBoundingOptions } from './draw' +import { NullGraphError } from './infrastructure/NullGraphError' +import type { ReadOnlyRectangle } from './infrastructure/Rectangle' +import { Rectangle } from './infrastructure/Rectangle' +import type { + ColorOption, + CompassCorners, + DefaultConnectionColors, + Dictionary, + IColorable, + IContextMenuValue, + IFoundSlot, + INodeFlags, + INodeInputSlot, + INodeOutputSlot, + INodeSlot, + INodeSlotContextItem, + IPinnable, + ISlotType, + Point, + Positionable, + ReadOnlyRect, + Rect, + Size +} from './interfaces' +import { LiteGraph, Subgraph } from './litegraph' +import type { LGraphNodeConstructor, SubgraphNode } from './litegraph' +import { + createBounds, + isInRect, + isInRectangle, + isPointInRect, + snapPoint +} from './measure' +import { NodeInputSlot } from './node/NodeInputSlot' +import { NodeOutputSlot } from './node/NodeOutputSlot' +import { + inputAsSerialisable, + isINodeInputSlot, + isWidgetInputSlot, + outputAsSerialisable +} from './node/slotUtils' +import type { SubgraphInputNode } from './subgraph/SubgraphInputNode' +import type { SubgraphOutputNode } from './subgraph/SubgraphOutputNode' +import type { NodeLike } from './types/NodeLike' +import type { CanvasPointerEvent } from './types/events' +import { + LGraphEventMode, + NodeSlotType, + RenderShape, + TitleMode +} from './types/globalEnums' +import type { ISerialisedNode, SubgraphIO } from './types/serialisation' +import type { + IBaseWidget, + IWidgetOptions, + TWidgetType, + TWidgetValue +} from './types/widgets' +import { findFreeSlotOfType } from './utils/collections' +import { warnDeprecated } from './utils/feedback' +import { distributeSpace } from './utils/spaceDistribution' +import { truncateText } from './utils/textUtils' +import { BaseWidget } from './widgets/BaseWidget' +import { toConcreteWidget } from './widgets/widgetMap' +import type { WidgetTypeMap } from './widgets/widgetMap' + +// #region Types + +export type NodeId = number | string + +export type NodeProperty = string | number | boolean | object + +interface INodePropertyInfo { + name: string + type?: string + default_value: NodeProperty | undefined +} + +interface IMouseOverData { + inputId?: number + outputId?: number + overWidget?: IBaseWidget +} + +interface ConnectByTypeOptions { + /** @deprecated Events */ + createEventInCase?: boolean + /** Allow our wildcard slot to connect to typed slots on remote node. Default: true */ + wildcardToTyped?: boolean + /** Allow our typed slot to connect to wildcard slots on remote node. Default: true */ + typedToWildcard?: boolean + /** The {@link Reroute.id} that the connection is being dragged from. */ + afterRerouteId?: RerouteId +} + +/** Internal type used for type safety when implementing generic checks for inputs & outputs */ +interface IGenericLinkOrLinks { + links?: INodeOutputSlot['links'] + link?: INodeInputSlot['link'] +} + +interface FindFreeSlotOptions { + /** Slots matching these types will be ignored. Default: [] */ + typesNotAccepted?: ISlotType[] + /** If true, the slot itself is returned instead of the index. Default: false */ + returnObj?: boolean +} + +interface DrawSlotsOptions { + fromSlot?: INodeInputSlot | INodeOutputSlot + colorContext: DefaultConnectionColors + editorAlpha: number + lowQuality: boolean +} + +interface DrawWidgetsOptions { + lowQuality?: boolean + editorAlpha?: number +} + +interface DrawTitleOptions { + scale: number + title_height?: number + low_quality?: boolean +} + +interface DrawTitleTextOptions extends DrawTitleOptions { + default_title_color: string +} + +export interface DrawTitleBoxOptions extends DrawTitleOptions { + box_size?: number +} + +/* +title: string +pos: [x,y] +size: [x,y] + +input|output: every connection + + { name:string, type:string, pos: [x,y]=Optional, direction: "input"|"output", links: Array }); + +general properties: + + clip_area: if you render outside the node, it will be clipped + + unsafe_execution: not allowed for safe execution + + skip_repeated_outputs: when adding new outputs, it won't show if there is one already connected + + resizable: if set to false it won't be resizable with the mouse + + widgets_start_y: widgets start at y distance from the top of the node + +flags object: + + collapsed: if it is collapsed + +supported callbacks: + + onAdded: when added to graph (warning: this is called BEFORE the node is configured when loading) + + onRemoved: when removed from graph + + onStart: when the graph starts playing + + onStop: when the graph stops playing + + onDrawForeground: render the inside widgets inside the node + + onDrawBackground: render the background area inside the node (only in edit mode) + + onMouseDown + + onMouseMove + + onMouseUp + + onMouseEnter + + onMouseLeave + + onExecute: execute the node + + onPropertyChanged: when a property is changed in the panel (return true to skip default behaviour) + + onGetInputs: returns an array of possible inputs + + onGetOutputs: returns an array of possible outputs + + onBounding: in case this node has a bigger bounding than the node itself (the callback receives the bounding as [x,y,w,h]) + + onDblClick: double clicked in the node + + onNodeTitleDblClick: double clicked in the node title + + onInputDblClick: input slot double clicked (can be used to automatically create a node connected) + + onOutputDblClick: output slot double clicked (can be used to automatically create a node connected) + + onConfigure: called after the node has been configured + + onSerialize: to add extra info when serializing (the callback receives the object that should be filled with the data) + + onSelected + + onDeselected + + onDropItem : DOM item dropped over the node + + onDropFile : file dropped over the node + + onConnectInput : if returns false the incoming connection will be canceled + + onConnectionsChange : a connection changed (new one or removed) (NodeSlotType.INPUT or NodeSlotType.OUTPUT, slot, true if connected, link_info, input_info ) + + onAction: action slot triggered + + getExtraMenuOptions: to add option to context menu +*/ + +export interface LGraphNode { + constructor: LGraphNodeConstructor +} + +// #endregion Types + +/** + * Base class for all nodes + * @param title a name for the node + * @param type a type for the node + */ + +export class LGraphNode + implements NodeLike, Positionable, IPinnable, IColorable +{ + // Static properties used by dynamic child classes + static title?: string + static MAX_CONSOLE?: number + static type?: string + static category?: string + static description?: string + static filter?: string + static skip_list?: boolean + + static resizeHandleSize = 15 + static resizeEdgeSize = 5 + + /** Default setting for {@link LGraphNode.connectInputToOutput}. @see {@link INodeFlags.keepAllLinksOnBypass} */ + static keepAllLinksOnBypass: boolean = false + + /** The title text of the node. */ + title: string + /** + * The font style used to render the node's title text. + */ + get titleFontStyle(): string { + return `${LiteGraph.NODE_TEXT_SIZE}px ${LiteGraph.NODE_FONT}` + } + + get innerFontStyle(): string { + return `normal ${LiteGraph.NODE_SUBTEXT_SIZE}px ${LiteGraph.NODE_FONT}` + } + + get displayType(): string { + return this.type + } + + graph: LGraph | Subgraph | null = null + id: NodeId + type: string = '' + inputs: INodeInputSlot[] = [] + outputs: INodeOutputSlot[] = [] + + #concreteInputs: NodeInputSlot[] = [] + #concreteOutputs: NodeOutputSlot[] = [] + + properties: Dictionary = {} + properties_info: INodePropertyInfo[] = [] + flags: INodeFlags = {} + widgets?: IBaseWidget[] + + /** Property manager for this node */ + changeTracker: LGraphNodeProperties + + /** + * The amount of space available for widgets to grow into. + * @see {@link layoutWidgets} + */ + freeWidgetSpace?: number + + locked?: boolean + + /** Execution order, automatically computed during run @see {@link LGraph.computeExecutionOrder} */ + order: number = 0 + mode: LGraphEventMode = LGraphEventMode.ALWAYS + last_serialization?: ISerialisedNode + serialize_widgets?: boolean + /** + * The overridden fg color used to render the node. + * @see {@link renderingColor} + */ + color?: string + /** + * The overridden bg color used to render the node. + * @see {@link renderingBgColor} + */ + bgcolor?: string + /** + * The overridden box color used to render the node. + * @see {@link renderingBoxColor} + */ + boxcolor?: string + + /** The fg color used to render the node. */ + get renderingColor(): string { + const baseColor = + this.color || this.constructor.color || LiteGraph.NODE_DEFAULT_COLOR + return adjustColor(baseColor, { lightness: LiteGraph.nodeLightness }) + } + + /** The bg color used to render the node. */ + get renderingBgColor(): string { + const baseBgColor = + this.bgcolor || this.constructor.bgcolor || LiteGraph.NODE_DEFAULT_BGCOLOR + const adjustments: ColorAdjustOptions = { + opacity: LiteGraph.nodeOpacity, + lightness: LiteGraph.nodeLightness + } + + return adjustColor( + this.mode === LGraphEventMode.BYPASS + ? LiteGraph.NODE_DEFAULT_BYPASS_COLOR + : baseBgColor, + adjustments + ) + } + + /** The box color used to render the node. */ + get renderingBoxColor(): string { + if (this.boxcolor) return this.boxcolor + + if (LiteGraph.node_box_coloured_when_on) { + if (this.action_triggered) return '#FFF' + if (this.execute_triggered) return '#AAA' + } + + if (LiteGraph.node_box_coloured_by_mode) { + const modeColour = + LiteGraph.NODE_MODES_COLORS[this.mode ?? LGraphEventMode.ALWAYS] + if (modeColour) return modeColour + } + return LiteGraph.NODE_DEFAULT_BOXCOLOR + } + + /** @inheritdoc {@link IColorable.setColorOption} */ + setColorOption(colorOption: ColorOption | null): void { + if (colorOption == null) { + this.color = undefined + this.bgcolor = undefined + } else { + this.color = colorOption.color + this.bgcolor = colorOption.bgcolor + } + } + + /** @inheritdoc {@link IColorable.getColorOption} */ + getColorOption(): ColorOption | null { + return ( + Object.values(LGraphCanvas.node_colors).find( + (colorOption) => + colorOption.color === this.color && + colorOption.bgcolor === this.bgcolor + ) ?? null + ) + } + + /** + * The stroke styles that should be applied to the node. + */ + strokeStyles: Record< + string, + (this: LGraphNode) => IDrawBoundingOptions | undefined + > + + /** + * The progress of node execution. Used to render a progress bar. Value between 0 and 1. + */ + progress?: number + + exec_version?: number + action_call?: string + execute_triggered?: number + action_triggered?: number + widgets_up?: boolean + widgets_start_y?: number + lostFocusAt?: number + gotFocusAt?: number + badges: (LGraphBadge | (() => LGraphBadge))[] = [] + title_buttons: LGraphButton[] = [] + badgePosition: BadgePosition = BadgePosition.TopLeft + onOutputRemoved?(this: LGraphNode, slot: number): void + onInputRemoved?(this: LGraphNode, slot: number, input: INodeInputSlot): void + /** + * The width of the node when collapsed. + * Updated by {@link LGraphCanvas.drawNode} + */ + _collapsed_width?: number + /** + * Called once at the start of every frame. Caller may change the values in {@link out}, which will be reflected in {@link boundingRect}. + * WARNING: Making changes to boundingRect via onBounding is poorly supported, and will likely result in strange behaviour. + */ + onBounding?(this: LGraphNode, out: Rect): void + console?: string[] + _level?: number + _shape?: RenderShape + mouseOver?: IMouseOverData + redraw_on_mouse?: boolean + resizable?: boolean + clonable?: boolean + _relative_id?: number + clip_area?: boolean + ignore_remove?: boolean + has_errors?: boolean + removable?: boolean + block_delete?: boolean + selected?: boolean + showAdvanced?: boolean + + declare comfyDynamic?: Record + declare comfyClass?: string + declare isVirtualNode?: boolean + applyToGraph?(extraLinks?: LLink[]): void + + isSubgraphNode(): this is SubgraphNode { + return false + } + + /** @inheritdoc {@link renderArea} */ + #renderArea = new Rectangle() + /** + * Rect describing the node area, including shadows and any protrusions. + * Determines if the node is visible. Calculated once at the start of every frame. + */ + get renderArea(): ReadOnlyRect { + return this.#renderArea + } + + /** @inheritdoc {@link boundingRect} */ + #boundingRect: Rectangle = new Rectangle() + /** + * Cached node position & area as `x, y, width, height`. Includes changes made by {@link onBounding}, if present. + * + * Determines the node hitbox and other rendering effects. Calculated once at the start of every frame. + */ + get boundingRect(): ReadOnlyRectangle { + return this.#boundingRect + } + + /** The offset from {@link pos} to the top-left of {@link boundingRect}. */ + get boundingOffset(): Readonly { + const { + pos: [posX, posY], + boundingRect: [bX, bY] + } = this + return [posX - bX, posY - bY] + } + + /** {@link pos} and {@link size} values are backed by this {@link Rectangle}. */ + _posSize = new Rectangle() + _pos: Point = this._posSize.pos + _size: Size = this._posSize.size + + public get pos() { + return this._pos + } + + /** Node position does not necessarily correlate to the top-left corner. */ + public set pos(value) { + if (!value || value.length < 2) return + + this._pos[0] = value[0] + this._pos[1] = value[1] + } + + public get size() { + return this._size + } + + public set size(value) { + if (!value || value.length < 2) return + + this._size[0] = value[0] + this._size[1] = value[1] + } + + /** + * The size of the node used for rendering. + */ + get renderingSize(): Size { + return this.flags.collapsed ? [this._collapsed_width ?? 0, 0] : this._size + } + + get shape(): RenderShape | undefined { + return this._shape + } + + set shape(v: RenderShape | 'default' | 'box' | 'round' | 'circle' | 'card') { + const oldValue = this._shape + switch (v) { + case 'default': + this._shape = undefined + break + case 'box': + this._shape = RenderShape.BOX + break + case 'round': + this._shape = RenderShape.ROUND + break + case 'circle': + this._shape = RenderShape.CIRCLE + break + case 'card': + this._shape = RenderShape.CARD + break + default: + this._shape = v + } + if (oldValue !== this._shape) { + this.graph?.trigger('node:property:changed', { + nodeId: this.id, + property: 'shape', + oldValue, + newValue: this._shape + }) + } + } + + /** + * The shape of the node used for rendering. @see {@link RenderShape} + */ + get renderingShape(): RenderShape { + return this._shape || this.constructor.shape || LiteGraph.NODE_DEFAULT_SHAPE + } + + public get is_selected(): boolean | undefined { + return this.selected + } + + public set is_selected(value: boolean) { + this.selected = value + } + + public get title_mode(): TitleMode { + return this.constructor.title_mode ?? TitleMode.NORMAL_TITLE + } + + onConnectInput?( + this: LGraphNode, + target_slot: number, + type: unknown, + output: INodeOutputSlot | SubgraphIO, + node: LGraphNode | SubgraphInputNode, + slot: number + ): boolean + onConnectOutput?( + this: LGraphNode, + slot: number, + type: unknown, + input: INodeInputSlot | SubgraphIO, + target_node: number | LGraphNode | SubgraphOutputNode, + target_slot: number + ): boolean + onResize?(this: LGraphNode, size: Size): void + onPropertyChanged?( + this: LGraphNode, + name: string, + value: unknown, + prev_value?: unknown + ): boolean + /** Called for each connection that is created, updated, or removed. This includes "restored" connections when deserialising. */ + onConnectionsChange?( + this: LGraphNode, + type: ISlotType, + index: number, + isConnected: boolean, + link_info: LLink | null | undefined, + inputOrOutput: INodeInputSlot | INodeOutputSlot | SubgraphIO + ): void + onInputAdded?(this: LGraphNode, input: INodeInputSlot): void + onOutputAdded?(this: LGraphNode, output: INodeOutputSlot): void + onConfigure?(this: LGraphNode, serialisedNode: ISerialisedNode): void + onSerialize?(this: LGraphNode, serialised: ISerialisedNode): void + onExecute?( + this: LGraphNode, + param?: unknown, + options?: { action_call?: string } + ): void + onAction?( + this: LGraphNode, + action: string, + param: unknown, + options: { action_call?: string } + ): void + onDrawBackground?(this: LGraphNode, ctx: CanvasRenderingContext2D): void + onNodeCreated?(this: LGraphNode): void + /** + * Callback invoked by {@link connect} to override the target slot index. + * Its return value overrides the target index selection. + * @param target_slot The current input slot index + * @param requested_slot The originally requested slot index - could be negative, or if using (deprecated) name search, a string + * @returns {number | null} If a number is returned, the connection will be made to that input index. + * If an invalid index or non-number (false, null, NaN etc) is returned, the connection will be cancelled. + */ + onBeforeConnectInput?( + this: LGraphNode, + target_slot: number, + requested_slot?: number | string + ): number | false | null + onShowCustomPanelInfo?(this: LGraphNode, panel: any): void + onAddPropertyToPanel?(this: LGraphNode, pName: string, panel: any): boolean + onWidgetChanged?( + this: LGraphNode, + name: string, + value: unknown, + old_value: unknown, + w: IBaseWidget + ): void + onDeselected?(this: LGraphNode): void + onKeyUp?(this: LGraphNode, e: KeyboardEvent): void + onKeyDown?(this: LGraphNode, e: KeyboardEvent): void + onSelected?(this: LGraphNode): void + getExtraMenuOptions?( + this: LGraphNode, + canvas: LGraphCanvas, + options: (IContextMenuValue | null)[] + ): (IContextMenuValue | null)[] + getMenuOptions?(this: LGraphNode, canvas: LGraphCanvas): IContextMenuValue[] + onAdded?(this: LGraphNode, graph: LGraph): void + onDrawCollapsed?( + this: LGraphNode, + ctx: CanvasRenderingContext2D, + cavnas: LGraphCanvas + ): boolean + onDrawForeground?( + this: LGraphNode, + ctx: CanvasRenderingContext2D, + canvas: LGraphCanvas, + canvasElement: HTMLCanvasElement + ): void + onMouseLeave?(this: LGraphNode, e: CanvasPointerEvent): void + /** + * Override the default slot menu options. + */ + getSlotMenuOptions?(this: LGraphNode, slot: IFoundSlot): IContextMenuValue[] + /** + * Add extra menu options to the slot context menu. + */ + getExtraSlotMenuOptions?( + this: LGraphNode, + slot: IFoundSlot + ): IContextMenuValue[] + + // FIXME: Re-typing + onDropItem?(this: LGraphNode, event: Event): boolean + onDropData?( + this: LGraphNode, + data: string | ArrayBuffer, + filename: string, + file: File + ): void + onDropFile?(this: LGraphNode, file: File): void + onInputClick?(this: LGraphNode, index: number, e: CanvasPointerEvent): void + onInputDblClick?(this: LGraphNode, index: number, e: CanvasPointerEvent): void + onOutputClick?(this: LGraphNode, index: number, e: CanvasPointerEvent): void + onOutputDblClick?( + this: LGraphNode, + index: number, + e: CanvasPointerEvent + ): void + // TODO: Return type + onGetPropertyInfo?(this: LGraphNode, property: string): any + onNodeOutputAdd?(this: LGraphNode, value: unknown): void + onNodeInputAdd?(this: LGraphNode, value: unknown): void + onMenuNodeInputs?( + this: LGraphNode, + entries: (IContextMenuValue | null)[] + ): (IContextMenuValue | null)[] + onMenuNodeOutputs?( + this: LGraphNode, + entries: (IContextMenuValue | null)[] + ): (IContextMenuValue | null)[] + onMouseUp?( + this: LGraphNode, + e: CanvasPointerEvent, + pos: Point, + canvas: LGraphCanvas + ): void + onMouseEnter?(this: LGraphNode, e: CanvasPointerEvent): void + /** Blocks drag if return value is truthy. @param pos Offset from {@link LGraphNode.pos}. */ + onMouseDown?( + this: LGraphNode, + e: CanvasPointerEvent, + pos: Point, + canvas: LGraphCanvas + ): boolean + /** @param pos Offset from {@link LGraphNode.pos}. */ + onDblClick?( + this: LGraphNode, + e: CanvasPointerEvent, + pos: Point, + canvas: LGraphCanvas + ): void + /** @param pos Offset from {@link LGraphNode.pos}. */ + onNodeTitleDblClick?( + this: LGraphNode, + e: CanvasPointerEvent, + pos: Point, + canvas: LGraphCanvas + ): void + onDrawTitle?(this: LGraphNode, ctx: CanvasRenderingContext2D): void + onDrawTitleText?( + this: LGraphNode, + ctx: CanvasRenderingContext2D, + title_height: number, + size: Size, + scale: number, + title_text_font: string, + selected?: boolean + ): void + onDrawTitleBox?( + this: LGraphNode, + ctx: CanvasRenderingContext2D, + title_height: number, + size: Size, + scale: number + ): void + onDrawTitleBar?( + this: LGraphNode, + ctx: CanvasRenderingContext2D, + title_height: number, + size: Size, + scale: number, + fgcolor: string + ): void + onRemoved?(this: LGraphNode): void + onMouseMove?( + this: LGraphNode, + e: CanvasPointerEvent, + pos: Point, + arg2: LGraphCanvas + ): void + onPropertyChange?(this: LGraphNode): void + updateOutputData?(this: LGraphNode, origin_slot: number): void + + #getErrorStrokeStyle(this: LGraphNode): IDrawBoundingOptions | undefined { + if (this.has_errors) { + return { + padding: 12, + lineWidth: 10, + color: LiteGraph.NODE_ERROR_COLOUR + } + } + } + + #getSelectedStrokeStyle(this: LGraphNode): IDrawBoundingOptions | undefined { + if (this.selected) { + return { + padding: this.has_errors ? 20 : undefined + } + } + } + + constructor(title: string, type?: string) { + this.id = LiteGraph.use_uuids ? LiteGraph.uuidv4() : -1 + this.title = title || 'Unnamed' + this.type = type ?? '' + this.size = [LiteGraph.NODE_WIDTH, 60] + this.pos = [10, 10] + this.strokeStyles = { + error: this.#getErrorStrokeStyle, + selected: this.#getSelectedStrokeStyle + } + // Initialize property manager with tracked properties + this.changeTracker = new LGraphNodeProperties(this) + } + + /** Internal callback for subgraph nodes. Do not implement externally. */ + _internalConfigureAfterSlots?(): void + + /** + * configure a node from an object containing the serialized info + */ + configure(info: ISerialisedNode): void { + if (this.graph) { + this.graph._version++ + } + for (const j in info) { + if (j == 'properties') { + // i don't want to clone properties, I want to reuse the old container + for (const k in info.properties) { + this.properties[k] = info.properties[k] + this.onPropertyChanged?.(k, info.properties[k]) + } + continue + } + + // @ts-expect-error #594 + if (info[j] == null) { + continue + // @ts-expect-error #594 + } else if (typeof info[j] == 'object') { + // @ts-expect-error #594 + if (this[j]?.configure) { + // @ts-expect-error #594 + this[j]?.configure(info[j]) + } else { + // @ts-expect-error #594 + this[j] = LiteGraph.cloneObject(info[j], this[j]) + } + } else { + // value + // @ts-expect-error #594 + this[j] = info[j] + } + } + + if (!info.title) { + this.title = this.constructor.title + } + + this.inputs ??= [] + this.inputs = this.inputs.map((input) => + toClass(NodeInputSlot, input, this) + ) + for (const [i, input] of this.inputs.entries()) { + const link = + this.graph && input.link != null + ? this.graph._links.get(input.link) + : null + this.onConnectionsChange?.(NodeSlotType.INPUT, i, true, link, input) + this.onInputAdded?.(input) + } + + this.outputs ??= [] + this.outputs = this.outputs.map((output) => + toClass(NodeOutputSlot, output, this) + ) + for (const [i, output] of this.outputs.entries()) { + if (!output.links) continue + + for (const linkId of output.links) { + const link = this.graph ? this.graph._links.get(linkId) : null + this.onConnectionsChange?.(NodeSlotType.OUTPUT, i, true, link, output) + } + this.onOutputAdded?.(output) + } + + // SubgraphNode callback. + this._internalConfigureAfterSlots?.() + + if (this.widgets) { + for (const w of this.widgets) { + if (!w) continue + + const input = this.inputs.find((i) => i.widget?.name === w.name) + if (input?.label) w.label = input.label + + if ( + w.options?.property && + this.properties[w.options.property] != undefined + ) + w.value = JSON.parse( + JSON.stringify(this.properties[w.options.property]) + ) + } + + if (info.widgets_values) { + let i = 0 + for (const widget of this.widgets ?? []) { + if (widget.serialize === false) continue + if (i >= info.widgets_values.length) break + widget.value = info.widgets_values[i++] + } + } + } + + // Sync the state of this.resizable. + if (this.pinned) this.resizable = false + + this.onConfigure?.(info) + } + + /** + * serialize the content + */ + serialize(): ISerialisedNode { + // create serialization object + const o: ISerialisedNode = { + id: this.id, + type: this.type, + pos: [this.pos[0], this.pos[1]], + size: [this.size[0], this.size[1]], + flags: LiteGraph.cloneObject(this.flags), + order: this.order, + mode: this.mode, + showAdvanced: this.showAdvanced + } + + // special case for when there were errors + if (this.constructor === LGraphNode && this.last_serialization) + return { ...this.last_serialization, mode: o.mode, pos: o.pos } + + if (this.inputs) + o.inputs = this.inputs.map((input) => inputAsSerialisable(input)) + if (this.outputs) + // @ts-expect-error - Output serialization type mismatch + o.outputs = this.outputs.map((output) => outputAsSerialisable(output)) + + if (this.title && this.title != this.constructor.title) o.title = this.title + + if (this.properties) o.properties = LiteGraph.cloneObject(this.properties) + + const { widgets } = this + if (widgets && this.serialize_widgets) { + o.widgets_values = [] + for (const [i, widget] of widgets.entries()) { + if (widget.serialize === false) continue + // @ts-expect-error #595 No-null + o.widgets_values[i] = widget ? widget.value : null + } + } + + if (!o.type && this.constructor.type) o.type = this.constructor.type + + if (this.color) o.color = this.color + if (this.bgcolor) o.bgcolor = this.bgcolor + if (this.boxcolor) o.boxcolor = this.boxcolor + if (this.shape) o.shape = this.shape + + if (this.onSerialize?.(o)) + console.warn( + "node onSerialize shouldn't return anything, data should be stored in the object pass in the first parameter" + ) + + return o + } + + /* Creates a clone of this node */ + clone(): LGraphNode | null { + if (this.type == null) return null + const node = LiteGraph.createNode(this.type) + if (!node) return null + + // we clone it because serialize returns shared containers + const data = LiteGraph.cloneObject(this.serialize()) + const { inputs, outputs } = data + + // remove links + if (inputs) { + for (const input of inputs) { + input.link = null + } + } + + if (outputs) { + for (const { links } of outputs) { + if (links) links.length = 0 + } + } + + // @ts-expect-error Exceptional case: id is removed so that the graph can assign a new one on add. + data.id = undefined + + if (LiteGraph.use_uuids) data.id = LiteGraph.uuidv4() + + node.configure(data) + + return node + } + + /** + * serialize and stringify + */ + toString(): string { + return JSON.stringify(this.serialize()) + } + + /** + * get the title string + */ + getTitle(): string { + return this.title || this.constructor.title + } + + /** + * sets the value of a property + * @param name + * @param value + */ + setProperty(name: string, value: TWidgetValue): void { + this.properties ||= {} + if (value === this.properties[name]) return + + const prev_value = this.properties[name] + this.properties[name] = value + // abort change + if (this.onPropertyChanged?.(name, value, prev_value) === false) + this.properties[name] = prev_value + + if (this.widgets) { + for (const w of this.widgets) { + if (!w) continue + + if (w.options.property == name) { + w.value = value + break + } + } + } + } + + /** + * sets the output data + * @param slot + * @param data + */ + setOutputData( + slot: number, + data: number | string | boolean | { toToolTip?(): string } + ): void { + const { outputs } = this + if (!outputs) return + + // this maybe slow and a niche case + if (slot == -1 || slot >= outputs.length) return + + const output_info = outputs[slot] + if (!output_info) return + + // store data in the output itself in case we want to debug + output_info._data = data + + if (!this.graph) throw new NullGraphError() + + // if there are connections, pass the data to the connections + const { links } = outputs[slot] + if (links) { + for (const id of links) { + const link = this.graph._links.get(id) + if (link) link.data = data + } + } + } + + /** + * sets the output data type, useful when you want to be able to overwrite the data type + */ + setOutputDataType(slot: number, type: ISlotType): void { + const { outputs } = this + if (!outputs || slot == -1 || slot >= outputs.length) return + + const output_info = outputs[slot] + if (!output_info) return + // store data in the output itself in case we want to debug + output_info.type = type + + if (!this.graph) throw new NullGraphError() + + // if there are connections, pass the data to the connections + const { links } = outputs[slot] + if (links) { + for (const id of links) { + const link = this.graph._links.get(id) + if (link) link.type = type + } + } + } + + /** + * Retrieves the input data (data traveling through the connection) from one slot + * @param slot + * @param force_update if set to true it will force the connected node of this slot to output data into this link + * @returns data or if it is not connected returns undefined + */ + getInputData(slot: number, force_update?: boolean): unknown { + if (!this.inputs) return + + if (slot >= this.inputs.length || this.inputs[slot].link == null) return + if (!this.graph) throw new NullGraphError() + + const link_id = this.inputs[slot].link + const link = this.graph._links.get(link_id) + // bug: weird case but it happens sometimes + if (!link) return null + + if (!force_update) return link.data + + // special case: used to extract data from the incoming connection before the graph has been executed + const node = this.graph.getNodeById(link.origin_id) + if (!node) return link.data + + if (node.updateOutputData) { + node.updateOutputData(link.origin_slot) + } else { + node.onExecute?.() + } + + return link.data + } + + /** + * Retrieves the input data type (in case this supports multiple input types) + * @param slot + * @returns datatype in string format + */ + getInputDataType(slot: number): ISlotType | null { + if (!this.inputs) return null + if (slot >= this.inputs.length || this.inputs[slot].link == null) + return null + if (!this.graph) throw new NullGraphError() + + const link_id = this.inputs[slot].link + const link = this.graph._links.get(link_id) + // bug: weird case but it happens sometimes + if (!link) return null + + const node = this.graph.getNodeById(link.origin_id) + if (!node) return link.type + + const output_info = node.outputs[link.origin_slot] + return output_info ? output_info.type : null + } + + /** + * Retrieves the input data from one slot using its name instead of slot number + * @param slot_name + * @param force_update if set to true it will force the connected node of this slot to output data into this link + * @returns data or if it is not connected returns null + */ + getInputDataByName(slot_name: string, force_update: boolean): unknown { + const slot = this.findInputSlot(slot_name) + return slot == -1 ? null : this.getInputData(slot, force_update) + } + + /** + * tells you if there is a connection in one input slot + * @param slot The 0-based index of the input to check + * @returns `true` if the input slot has a link ID (does not perform validation) + */ + isInputConnected(slot: number): boolean { + if (!this.inputs) return false + return slot < this.inputs.length && this.inputs[slot].link != null + } + + /** + * tells you info about an input connection (which node, type, etc) + * @returns object or null { link: id, name: string, type: string or 0 } + */ + getInputInfo(slot: number): INodeInputSlot | null { + return !this.inputs || !(slot < this.inputs.length) + ? null + : this.inputs[slot] + } + + /** + * Returns the link info in the connection of an input slot + * @returns object or null + */ + getInputLink(slot: number): LLink | null { + if (!this.inputs) return null + + if (slot < this.inputs.length) { + if (!this.graph) throw new NullGraphError() + + const input = this.inputs[slot] + if (input.link != null) { + return this.graph._links.get(input.link) ?? null + } + } + return null + } + + /** + * returns the node connected in the input slot + * @returns node or null + */ + getInputNode(slot: number): LGraphNode | null { + if (!this.inputs) return null + if (slot >= this.inputs.length) return null + + const input = this.inputs[slot] + if (!input || input.link === null) return null + if (!this.graph) throw new NullGraphError() + + const link_info = this.graph._links.get(input.link) + if (!link_info) return null + + return this.graph.getNodeById(link_info.origin_id) + } + + /** + * returns the value of an input with this name, otherwise checks if there is a property with that name + * @returns value + */ + getInputOrProperty(name: string): unknown { + const { inputs } = this + if (!inputs?.length) { + return this.properties ? this.properties[name] : null + } + if (!this.graph) throw new NullGraphError() + + for (const input of inputs) { + if (name == input.name && input.link != null) { + const link = this.graph._links.get(input.link) + if (link) return link.data + } + } + return this.properties[name] + } + + /** + * tells you the last output data that went in that slot + * @returns object or null + */ + getOutputData(slot: number): unknown { + if (!this.outputs) return null + if (slot >= this.outputs.length) return null + + const info = this.outputs[slot] + return info._data + } + + /** + * tells you info about an output connection (which node, type, etc) + * @returns object or null { name: string, type: string, links: [ ids of links in number ] } + */ + getOutputInfo(slot: number): INodeOutputSlot | null { + return !this.outputs || !(slot < this.outputs.length) + ? null + : this.outputs[slot] + } + + /** + * tells you if there is a connection in one output slot + */ + isOutputConnected(slot: number): boolean { + if (!this.outputs) return false + return ( + slot < this.outputs.length && Number(this.outputs[slot].links?.length) > 0 + ) + } + + /** + * tells you if there is any connection in the output slots + */ + isAnyOutputConnected(): boolean { + const { outputs } = this + if (!outputs) return false + + for (const output of outputs) { + if (output.links?.length) return true + } + return false + } + + /** + * retrieves all the nodes connected to this output slot + */ + getOutputNodes(slot: number): LGraphNode[] | null { + const { outputs } = this + if (!outputs || outputs.length == 0) return null + + if (slot >= outputs.length) return null + + const { links } = outputs[slot] + if (!links || links.length == 0) return null + if (!this.graph) throw new NullGraphError() + + const r: LGraphNode[] = [] + for (const id of links) { + const link = this.graph._links.get(id) + if (link) { + const target_node = this.graph.getNodeById(link.target_id) + if (target_node) { + r.push(target_node) + } + } + } + return r + } + + addOnTriggerInput(): number { + const trigS = this.findInputSlot('onTrigger') + if (trigS == -1) { + this.addInput('onTrigger', LiteGraph.EVENT, { + nameLocked: true + }) + return this.findInputSlot('onTrigger') + } + return trigS + } + + addOnExecutedOutput(): number { + const trigS = this.findOutputSlot('onExecuted') + if (trigS == -1) { + this.addOutput('onExecuted', LiteGraph.ACTION, { + nameLocked: true + }) + return this.findOutputSlot('onExecuted') + } + return trigS + } + + onAfterExecuteNode(param: unknown, options?: { action_call?: string }) { + const trigS = this.findOutputSlot('onExecuted') + if (trigS != -1) { + this.triggerSlot(trigS, param, null, options) + } + } + + changeMode(modeTo: number): boolean { + switch (modeTo) { + case LGraphEventMode.ON_EVENT: + break + + case LGraphEventMode.ON_TRIGGER: + this.addOnTriggerInput() + this.addOnExecutedOutput() + break + + case LGraphEventMode.NEVER: + break + + case LGraphEventMode.ALWAYS: + break + + // @ts-expect-error Not impl. + case LiteGraph.ON_REQUEST: + break + + default: + return false + break + } + this.mode = modeTo + return true + } + + /** + * Triggers the node code execution, place a boolean/counter to mark the node as being executed + */ + doExecute(param?: unknown, options?: { action_call?: string }): void { + options = options || {} + if (this.onExecute) { + // enable this to give the event an ID + options.action_call ||= `${this.id}_exec_${Math.floor(Math.random() * 9999)}` + if (!this.graph) throw new NullGraphError() + + // @ts-expect-error Technically it works when id is a string. Array gets props. + this.graph.nodes_executing[this.id] = true + this.onExecute(param, options) + // @ts-expect-error deprecated + this.graph.nodes_executing[this.id] = false + + // save execution/action ref + this.exec_version = this.graph.iteration + if (options?.action_call) { + this.action_call = options.action_call + // @ts-expect-error deprecated + this.graph.nodes_executedAction[this.id] = options.action_call + } + } + // the nFrames it will be used (-- each step), means "how old" is the event + this.execute_triggered = 2 + this.onAfterExecuteNode?.(param, options) + } + + /** + * Triggers an action, wrapped by logics to control execution flow + * @param action name + */ + actionDo( + action: string, + param: unknown, + options: { action_call?: string } + ): void { + options = options || {} + if (this.onAction) { + // enable this to give the event an ID + options.action_call ||= `${this.id}_${action || 'action'}_${Math.floor(Math.random() * 9999)}` + if (!this.graph) throw new NullGraphError() + + // @ts-expect-error deprecated + this.graph.nodes_actioning[this.id] = action || 'actioning' + this.onAction(action, param, options) + // @ts-expect-error deprecated + this.graph.nodes_actioning[this.id] = false + + // save execution/action ref + if (options?.action_call) { + this.action_call = options.action_call + // @ts-expect-error deprecated + this.graph.nodes_executedAction[this.id] = options.action_call + } + } + // the nFrames it will be used (-- each step), means "how old" is the event + this.action_triggered = 2 + this.onAfterExecuteNode?.(param, options) + } + + /** + * Triggers an event in this node, this will trigger any output with the same name + * @param action name ( "on_play", ... ) if action is equivalent to false then the event is send to all + */ + trigger( + action: string, + param: unknown, + options: { action_call?: string } + ): void { + const { outputs } = this + if (!outputs || !outputs.length) { + return + } + + if (this.graph) this.graph._last_trigger_time = LiteGraph.getTime() + + for (const [i, output] of outputs.entries()) { + if ( + !output || + output.type !== LiteGraph.EVENT || + (action && output.name != action) + ) { + continue + } + this.triggerSlot(i, param, null, options) + } + } + + /** + * Triggers a slot event in this node: cycle output slots and launch execute/action on connected nodes + * @param slot the index of the output slot + * @param link_id [optional] in case you want to trigger and specific output link in a slot + */ + triggerSlot( + slot: number, + param: unknown, + link_id: number | null, + options?: { action_call?: string } + ): void { + options = options || {} + if (!this.outputs) return + + if (slot == null) { + console.error('slot must be a number') + return + } + + if (typeof slot !== 'number') + console.warn( + "slot must be a number, use node.trigger('name') if you want to use a string" + ) + + const output = this.outputs[slot] + if (!output) return + + const links = output.links + if (!links || !links.length) return + + if (!this.graph) throw new NullGraphError() + this.graph._last_trigger_time = LiteGraph.getTime() + + // for every link attached here + for (const id of links) { + // to skip links + if (link_id != null && link_id != id) continue + + const link_info = this.graph._links.get(id) + // not connected + if (!link_info) continue + + link_info._last_time = LiteGraph.getTime() + const node = this.graph.getNodeById(link_info.target_id) + // node not found? + if (!node) continue + + if (node.mode === LGraphEventMode.ON_TRIGGER) { + // generate unique trigger ID if not present + if (!options.action_call) + options.action_call = `${this.id}_trigg_${Math.floor(Math.random() * 9999)}` + // -- wrapping node.onExecute(param); -- + node.doExecute?.(param, options) + } else if (node.onAction) { + // generate unique action ID if not present + if (!options.action_call) + options.action_call = `${this.id}_act_${Math.floor(Math.random() * 9999)}` + // pass the action name + const target_connection = node.inputs[link_info.target_slot] + node.actionDo(target_connection.name, param, options) + } + } + } + + /** + * clears the trigger slot animation + * @param slot the index of the output slot + * @param link_id [optional] in case you want to trigger and specific output link in a slot + */ + clearTriggeredSlot(slot: number, link_id: number): void { + if (!this.outputs) return + + const output = this.outputs[slot] + if (!output) return + + const links = output.links + if (!links || !links.length) return + + if (!this.graph) throw new NullGraphError() + + // for every link attached here + for (const id of links) { + // to skip links + if (link_id != null && link_id != id) continue + + const link_info = this.graph._links.get(id) + // not connected + if (!link_info) continue + + link_info._last_time = 0 + } + } + + /** + * changes node size and triggers callback + */ + setSize(size: Size): void { + this.size = size + this.onResize?.(this.size) + } + + /** + * Expands the node size to fit its content. + */ + expandToFitContent(): void { + const newSize = this.computeSize() + this.setSize([ + Math.max(this.size[0], newSize[0]), + Math.max(this.size[1], newSize[1]) + ]) + } + + /** + * add a new property to this node + * @param type string defining the output type ("vec3","number",...) + * @param extra_info this can be used to have special properties of the property (like values, etc) + */ + addProperty( + name: string, + default_value: NodeProperty | undefined, + type?: string, + extra_info?: Partial + ): INodePropertyInfo { + const o: INodePropertyInfo = { name, type, default_value } + if (extra_info) Object.assign(o, extra_info) + + this.properties_info ||= [] + this.properties_info.push(o) + this.properties ||= {} + this.properties[name] = default_value + return o + } + + /** + * add a new output slot to use in this node + * @param type string defining the output type ("vec3","number",...) + * @param extra_info this can be used to have special properties of an output (label, special color, position, etc) + */ + addOutput>( + name: string, + type: ISlotType, + extra_info?: TProperties + ): INodeOutputSlot & TProperties { + const output = Object.assign( + new NodeOutputSlot({ name, type, links: null }, this), + extra_info + ) + + this.outputs ||= [] + this.outputs.push(output) + this.onOutputAdded?.(output) + + if (LiteGraph.auto_load_slot_types) + LiteGraph.registerNodeAndSlotType(this, type, true) + + this.expandToFitContent() + this.setDirtyCanvas(true, true) + return output + } + + /** + * remove an existing output slot + */ + removeOutput(slot: number): void { + // Only disconnect if node is part of a graph + if (this.graph) { + this.disconnectOutput(slot) + } + const { outputs } = this + outputs.splice(slot, 1) + + for (let i = slot; i < outputs.length; ++i) { + const output = outputs[i] + if (!output || !output.links) continue + + // Only update link indices if node is part of a graph + if (this.graph) { + for (const linkId of output.links) { + const link = this.graph._links.get(linkId) + if (link) link.origin_slot-- + } + } + } + + this.onOutputRemoved?.(slot) + this.setDirtyCanvas(true, true) + } + + /** + * add a new input slot to use in this node + * @param type string defining the input type ("vec3","number",...), it its a generic one use 0 + * @param extra_info this can be used to have special properties of an input (label, color, position, etc) + */ + addInput>( + name: string, + type: ISlotType, + extra_info?: TProperties + ): INodeInputSlot & TProperties { + type ||= 0 + + const input = Object.assign( + new NodeInputSlot({ name, type, link: null }, this), + extra_info + ) + + this.inputs ||= [] + this.inputs.push(input) + this.expandToFitContent() + + this.onInputAdded?.(input) + LiteGraph.registerNodeAndSlotType(this, type) + + this.setDirtyCanvas(true, true) + return input + } + + /** + * remove an existing input slot + */ + removeInput(slot: number): void { + // Only disconnect if node is part of a graph + if (this.graph) { + this.disconnectInput(slot, true) + } + const { inputs } = this + const slot_info = inputs.splice(slot, 1) + + for (let i = slot; i < inputs.length; ++i) { + const input = inputs[i] + if (!input?.link) continue + + // Only update link indices if node is part of a graph + if (this.graph) { + const link = this.graph._links.get(input.link) + if (link) link.target_slot-- + } + } + this.onInputRemoved?.(slot, slot_info[0]) + this.setDirtyCanvas(true, true) + } + + /** + * computes the minimum size of a node according to its inputs and output slots + * @returns the total size + */ + computeSize(out?: Size): Size { + const ctorSize = this.constructor.size + if (ctorSize) return [ctorSize[0], ctorSize[1]] + + const { inputs, outputs, widgets } = this + let rows = Math.max( + inputs ? inputs.filter((input) => !isWidgetInputSlot(input)).length : 1, + outputs ? outputs.length : 1 + ) + const size = out ?? [0, 0] + rows = Math.max(rows, 1) + // although it should be graphcanvas.inner_text_font size + const font_size = LiteGraph.NODE_TEXT_SIZE + + const padLeft = LiteGraph.NODE_TITLE_HEIGHT + const padRight = padLeft * 0.33 + const title_width = + padLeft + compute_text_size(this.title, this.titleFontStyle) + padRight + let input_width = 0 + let widgetWidth = 0 + let output_width = 0 + + if (inputs) { + for (const input of inputs) { + const text = input.label || input.localized_name || input.name || '' + const text_width = compute_text_size(text, this.innerFontStyle) + if (isWidgetInputSlot(input)) { + const widget = this.getWidgetFromSlot(input) + if (widget && !this.isWidgetVisible(widget)) continue + + if (text_width > widgetWidth) widgetWidth = text_width + } else { + if (text_width > input_width) input_width = text_width + } + } + } + + if (outputs) { + for (const output of outputs) { + const text = output.label || output.localized_name || output.name || '' + const text_width = compute_text_size(text, this.innerFontStyle) + if (output_width < text_width) output_width = text_width + } + } + + const minWidth = LiteGraph.NODE_WIDTH * (widgets?.length ? 1.5 : 1) + // Text + slot width + centre padding + const centrePadding = input_width && output_width ? 5 : 0 + const slotsWidth = + input_width + + output_width + + 2 * LiteGraph.NODE_SLOT_HEIGHT + + centrePadding + + // Total distance from edge of node to the inner edge of the widget 'previous' arrow button + const widgetMargin = + BaseWidget.margin + BaseWidget.arrowMargin + BaseWidget.arrowWidth + const widgetPadding = BaseWidget.minValueWidth + 2 * widgetMargin + if (widgetWidth) widgetWidth += widgetPadding + + size[0] = Math.max(slotsWidth, widgetWidth, title_width, minWidth) + size[1] = + (this.constructor.slot_start_y || 0) + rows * LiteGraph.NODE_SLOT_HEIGHT + + // Get widget height & expand size if necessary + let widgets_height = 0 + if (widgets?.length) { + for (const widget of widgets) { + if (!this.isWidgetVisible(widget)) continue + + let widget_height = 0 + if (widget.computeSize) { + widget_height += widget.computeSize(size[0])[1] + } else if (widget.computeLayoutSize) { + // Expand widget width if necessary + const { minHeight, minWidth } = widget.computeLayoutSize(this) + const widgetWidth = minWidth + widgetPadding + if (widgetWidth > size[0]) size[0] = widgetWidth + + widget_height += minHeight + } else { + widget_height += LiteGraph.NODE_WIDGET_HEIGHT + } + widgets_height += widget_height + 4 + } + widgets_height += 8 + } + + // compute height using widgets height + if (this.widgets_up) size[1] = Math.max(size[1], widgets_height) + else if (this.widgets_start_y != null) + size[1] = Math.max(size[1], widgets_height + this.widgets_start_y) + else size[1] += widgets_height + + function compute_text_size(text: string, fontStyle: string) { + return ( + LGraphCanvas._measureText?.(text, fontStyle) ?? + font_size * (text?.length ?? 0) * 0.6 + ) + } + + if (this.constructor.min_height && size[1] < this.constructor.min_height) { + size[1] = this.constructor.min_height + } + + // margin + size[1] += 6 + + return size + } + + inResizeCorner(canvasX: number, canvasY: number): boolean { + const rows = this.outputs ? this.outputs.length : 1 + const outputs_offset = + (this.constructor.slot_start_y || 0) + rows * LiteGraph.NODE_SLOT_HEIGHT + return isInRectangle( + canvasX, + canvasY, + this.pos[0] + this.size[0] - 15, + this.pos[1] + Math.max(this.size[1] - 15, outputs_offset), + 20, + 20 + ) + } + + /** + * Returns which resize corner the point is over, if any. + * @param canvasX X position in canvas coordinates + * @param canvasY Y position in canvas coordinates + * @returns The compass corner the point is in, otherwise `undefined`. + */ + findResizeDirection( + canvasX: number, + canvasY: number + ): CompassCorners | undefined { + if (this.resizable === false) return + + const { boundingRect } = this + if (!boundingRect.containsXy(canvasX, canvasY)) return + + // Check corners first (they take priority over edges) + return boundingRect.findContainingCorner( + canvasX, + canvasY, + LGraphNode.resizeHandleSize + ) + } + + /** + * returns all the info available about a property of this node. + * @param property name of the property + * @returns the object with all the available info + */ + getPropertyInfo(property: string) { + let info = null + + // there are several ways to define info about a property + // legacy mode + const { properties_info } = this + if (properties_info) { + for (const propInfo of properties_info) { + if (propInfo.name == property) { + info = propInfo + break + } + } + } + // litescene mode using the constructor + // @ts-expect-error deprecated https://github.com/Comfy-Org/litegraph.js/issues/639 + if (this.constructor[`@${property}`]) + // @ts-expect-error deprecated https://github.com/Comfy-Org/litegraph.js/issues/639 + info = this.constructor[`@${property}`] + + if (this.constructor.widgets_info?.[property]) + info = this.constructor.widgets_info[property] + + // litescene mode using the constructor + if (!info && this.onGetPropertyInfo) { + info = this.onGetPropertyInfo(property) + } + + info ||= {} + info.type ||= typeof this.properties[property] + if (info.widget == 'combo') info.type = 'enum' + + return info + } + + /** + * Defines a widget inside the node, it will be rendered on top of the node, you can control lots of properties + * @param type the widget type + * @param name the text to show on the widget + * @param value the default value + * @param callback function to call when it changes (optionally, it can be the name of the property to modify) + * @param options the object that contains special properties of this widget + * @returns the created widget object + */ + addWidget< + Type extends TWidgetType, + TValue extends WidgetTypeMap[Type]['value'] + >( + type: Type, + name: string, + value: TValue, + callback: IBaseWidget['callback'] | string | null, + options?: IWidgetOptions | string + ): WidgetTypeMap[Type] | IBaseWidget { + this.widgets ||= [] + + if (!options && callback && typeof callback === 'object') { + options = callback + callback = null + } + + // options can be the property name + options ||= {} + if (typeof options === 'string') options = { property: options } + + // callback can be the property name + if (callback && typeof callback === 'string') { + options.property = callback + callback = null + } + + const w: IBaseWidget & { type: Type } = { + // @ts-expect-error - Type casting for widget type property + type: type.toLowerCase(), + name: name, + value: value, + callback: typeof callback !== 'function' ? undefined : callback, + options, + y: 0 + } + + if (w.options.y !== undefined) { + w.y = w.options.y + } + + if (!callback && !w.options.callback && !w.options.property) { + console.warn( + 'LiteGraph addWidget(...) without a callback or property assigned' + ) + } + if (type == 'combo' && !w.options.values) { + throw "LiteGraph addWidget('combo',...) requires to pass values in options: { values:['red','blue'] }" + } + + const widget = this.addCustomWidget(w) + this.expandToFitContent() + return widget + } + + addCustomWidget( + custom_widget: TPlainWidget + ): TPlainWidget | WidgetTypeMap[TPlainWidget['type']] { + this.widgets ||= [] + const widget = toConcreteWidget(custom_widget, this, false) ?? custom_widget + this.widgets.push(widget) + return widget + } + + addTitleButton(options: LGraphButtonOptions): LGraphButton { + this.title_buttons ||= [] + const button = new LGraphButton(options) + this.title_buttons.push(button) + return button + } + + onTitleButtonClick(button: LGraphButton, canvas: LGraphCanvas): void { + // Dispatch event for button click + canvas.dispatch('litegraph:node-title-button-clicked', { + node: this, + button: button + }) + } + + removeWidgetByName(name: string): void { + const widget = this.widgets?.find((x) => x.name === name) + if (widget) this.removeWidget(widget) + } + + removeWidget(widget: IBaseWidget): void { + if (!this.widgets) + throw new Error('removeWidget called on node without widgets') + + const widgetIndex = this.widgets.indexOf(widget) + if (widgetIndex === -1) throw new Error('Widget not found on this node') + + // Clean up slot references to prevent memory leaks + if (this.inputs) { + for (const input of this.inputs) { + if (input._widget === widget) { + input._widget = undefined + input.widget = undefined + } + } + } + + widget.onRemove?.() + this.widgets.splice(widgetIndex, 1) + } + + ensureWidgetRemoved(widget: IBaseWidget): void { + try { + this.removeWidget(widget) + } catch (error) { + console.error('Failed to remove widget', error) + } + } + + move(deltaX: number, deltaY: number): void { + if (this.pinned) return + + // If Vue nodes mode is enabled, skip LiteGraph's direct position update + // The layout store will handle the movement and sync back to LiteGraph + if (LiteGraph.vueNodesMode) { + // Vue nodes handle their own dragging through the layout store + // This prevents the snap-back issue from conflicting position updates + return + } + + this.pos[0] += deltaX + this.pos[1] += deltaY + } + + /** + * Internal method to measure the node for rendering. Prefer {@link boundingRect} where possible. + * + * Populates {@link out} with the results in graph space. + * Populates {@link _collapsed_width} with the collapsed width if the node is collapsed. + * Adjusts for title and collapsed status, but does not call {@link onBounding}. + * @param out `x, y, width, height` are written to this array. + * @param ctx The canvas context to use for measuring text. + */ + measure(out: Rect, ctx?: CanvasRenderingContext2D): void { + const titleMode = this.title_mode + const renderTitle = + titleMode != TitleMode.TRANSPARENT_TITLE && + titleMode != TitleMode.NO_TITLE + const titleHeight = renderTitle ? LiteGraph.NODE_TITLE_HEIGHT : 0 + + out[0] = this.pos[0] + out[1] = this.pos[1] + -titleHeight + if (!this.flags?.collapsed) { + out[2] = this.size[0] + out[3] = this.size[1] + titleHeight + } else { + if (ctx) ctx.font = this.innerFontStyle + this._collapsed_width = Math.min( + this.size[0], + ctx + ? ctx.measureText(this.getTitle() ?? '').width + + LiteGraph.NODE_TITLE_HEIGHT * 2 + : 0 + ) + out[2] = this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH + out[3] = LiteGraph.NODE_TITLE_HEIGHT + } + } + + /** + * returns the bounding of the object, used for rendering purposes + * @param out {Rect?} [optional] a place to store the output, to free garbage + * @param includeExternal {boolean?} [optional] set to true to + * include the shadow and connection points in the bounding calculation + * @returns the bounding box in format of [topleft_cornerx, topleft_cornery, width, height] + */ + getBounding(out?: Rect, includeExternal?: boolean): Rect { + out ||= [0, 0, 0, 0] + + const rect = includeExternal ? this.renderArea : this.boundingRect + out[0] = rect[0] + out[1] = rect[1] + out[2] = rect[2] + out[3] = rect[3] + + return out + } + + /** + * Calculates the render area of this node, populating both {@link boundingRect} and {@link renderArea}. + * Called automatically at the start of every frame. + */ + updateArea(ctx?: CanvasRenderingContext2D): void { + const bounds = this.#boundingRect + this.measure(bounds, ctx) + this.onBounding?.(bounds) + + const renderArea = this.#renderArea + renderArea.set(bounds) + // 4 offset for collapsed node connection points + renderArea[0] -= 4 + renderArea[1] -= 4 + // Add shadow & left offset + renderArea[2] += 6 + 4 + // Add shadow & top offsets + renderArea[3] += 5 + 4 + } + + /** + * checks if a point is inside the shape of a node + */ + isPointInside(x: number, y: number): boolean { + return isInRect(x, y, this.boundingRect) + } + + /** + * Checks if the provided point is inside this node's collapse button area. + * @param x X co-ordinate to check + * @param y Y co-ordinate to check + * @returns true if the x,y point is in the collapse button area, otherwise false + */ + isPointInCollapse(x: number, y: number): boolean { + const squareLength = LiteGraph.NODE_TITLE_HEIGHT + return isInRectangle( + x, + y, + this.pos[0], + this.pos[1] - squareLength, + squareLength, + squareLength + ) + } + + /** + * Returns the input slot at the given position. Uses full 20 height, and approximates the label length. + * @param pos The graph co-ordinates to check + * @returns The input slot at the given position if found, otherwise `undefined`. + */ + getInputOnPos(pos: Point): INodeInputSlot | undefined { + return getNodeInputOnPos(this, pos[0], pos[1])?.input + } + + /** + * Returns the output slot at the given position. Uses full 20x20 box for the slot. + * @param pos The graph co-ordinates to check + * @returns The output slot at the given position if found, otherwise `undefined`. + */ + getOutputOnPos(pos: Point): INodeOutputSlot | undefined { + return getNodeOutputOnPos(this, pos[0], pos[1])?.output + } + + /** + * Returns the input or output slot at the given position. + * + * Tries {@link getNodeInputOnPos} first, then {@link getNodeOutputOnPos}. + * @param pos The graph co-ordinates to check + * @returns The input or output slot at the given position if found, otherwise `undefined`. + */ + getSlotOnPos(pos: Point): INodeInputSlot | INodeOutputSlot | undefined { + if (!isPointInRect(pos, this.boundingRect)) return + + return this.getInputOnPos(pos) ?? this.getOutputOnPos(pos) + } + + /** + * @deprecated Use {@link getSlotOnPos} instead. + * checks if a point is inside a node slot, and returns info about which slot + * @param x + * @param y + * @returns if found the object contains { input|output: slot object, slot: number, link_pos: [x,y] } + */ + getSlotInPosition(x: number, y: number): IFoundSlot | null { + // search for inputs + const { inputs, outputs } = this + + if (inputs) { + for (const [i, input] of inputs.entries()) { + const pos = this.getInputPos(i) + if (isInRectangle(x, y, pos[0] - 10, pos[1] - 10, 20, 20)) { + return { input, slot: i, link_pos: pos } + } + } + } + + if (outputs) { + for (const [i, output] of outputs.entries()) { + const pos = this.getOutputPos(i) + if (isInRectangle(x, y, pos[0] - 10, pos[1] - 10, 20, 20)) { + return { output, slot: i, link_pos: pos } + } + } + } + + return null + } + + /** + * Gets the widget on this node at the given co-ordinates. + * @param canvasX X co-ordinate in graph space + * @param canvasY Y co-ordinate in graph space + * @returns The widget found, otherwise `null` + */ + getWidgetOnPos( + canvasX: number, + canvasY: number, + includeDisabled = false + ): IBaseWidget | undefined { + const { widgets, pos, size } = this + if (!widgets?.length) return + + const x = canvasX - pos[0] + const y = canvasY - pos[1] + const nodeWidth = size[0] + + for (const widget of widgets) { + if ( + (widget.computedDisabled && !includeDisabled) || + !this.isWidgetVisible(widget) + ) { + continue + } + + const h = + widget.computedHeight ?? + widget.computeSize?.(nodeWidth)[1] ?? + LiteGraph.NODE_WIDGET_HEIGHT + + const maybeDOMWidget = widget as { margin?: number } + const mtop = maybeDOMWidget.margin ?? -2 + const mbot = maybeDOMWidget.margin ?? 2 + const mx = maybeDOMWidget.margin ?? 6 + + const w = widget.width || nodeWidth + if ( + widget.last_y !== undefined && + isInRectangle( + x, + y, + mx, + widget.last_y + mtop, + w - 2 * mx, + h - mtop - mbot + ) + ) { + return widget + } + } + } + + /** + * Returns the input slot with a given name (used for dynamic slots), -1 if not found + * @param name the name of the slot to find + * @param returnObj if the obj itself wanted + * @returns the slot (-1 if not found) + */ + findInputSlot( + name: string, + returnObj?: TReturn + ): number + findInputSlot( + name: string, + returnObj?: TReturn + ): INodeInputSlot + findInputSlot(name: string, returnObj: boolean = false) { + const { inputs } = this + if (!inputs) return -1 + + for (const [i, input] of inputs.entries()) { + if (name == input.name) { + return !returnObj ? i : input + } + } + return -1 + } + + /** + * returns the output slot with a given name (used for dynamic slots), -1 if not found + * @param name the name of the slot to find + * @param returnObj if the obj itself wanted + * @returns the slot (-1 if not found) + */ + findOutputSlot( + name: string, + returnObj?: TReturn + ): number + findOutputSlot( + name: string, + returnObj?: TReturn + ): INodeOutputSlot + findOutputSlot(name: string, returnObj: boolean = false) { + const { outputs } = this + if (!outputs) return -1 + + for (const [i, output] of outputs.entries()) { + if (name == output.name) { + return !returnObj ? i : output + } + } + return -1 + } + + /** + * Finds the first free input slot. + * @param optsIn + * @returns The index of the first matching slot, the slot itself if returnObj is true, or -1 if not found. + */ + findInputSlotFree( + optsIn?: FindFreeSlotOptions & { returnObj?: TReturn } + ): number + findInputSlotFree( + optsIn?: FindFreeSlotOptions & { returnObj?: TReturn } + ): INodeInputSlot | -1 + findInputSlotFree(optsIn?: FindFreeSlotOptions) { + return this.#findFreeSlot(this.inputs, optsIn) + } + + /** + * Finds the first free output slot. + * @param optsIn + * @returns The index of the first matching slot, the slot itself if returnObj is true, or -1 if not found. + */ + findOutputSlotFree( + optsIn?: FindFreeSlotOptions & { returnObj?: TReturn } + ): number + findOutputSlotFree( + optsIn?: FindFreeSlotOptions & { returnObj?: TReturn } + ): INodeOutputSlot | -1 + findOutputSlotFree(optsIn?: FindFreeSlotOptions) { + return this.#findFreeSlot(this.outputs, optsIn) + } + + /** + * Finds the next free slot + * @param slots The slots to search, i.e. this.inputs or this.outputs + */ + #findFreeSlot( + slots: TSlot[], + options?: FindFreeSlotOptions + ): TSlot | number { + const defaults = { + returnObj: false, + typesNotAccepted: [] + } + const opts = Object.assign(defaults, options || {}) + const length = slots?.length + if (!(length > 0)) return -1 + + for (let i = 0; i < length; ++i) { + const slot: TSlot & IGenericLinkOrLinks = slots[i] + if (!slot || slot.link || slot.links?.length) continue + if (opts.typesNotAccepted?.includes?.(slot.type)) continue + return !opts.returnObj ? i : slot + } + return -1 + } + + /** + * findSlotByType for INPUTS + */ + findInputSlotByType( + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): number + findInputSlotByType( + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): INodeInputSlot + findInputSlotByType( + type: ISlotType, + returnObj?: boolean, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ) { + return this.#findSlotByType( + this.inputs, + type, + returnObj, + preferFreeSlot, + doNotUseOccupied + ) + } + + /** + * findSlotByType for OUTPUTS + */ + findOutputSlotByType( + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): number + findOutputSlotByType( + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): INodeOutputSlot + findOutputSlotByType( + type: ISlotType, + returnObj?: boolean, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ) { + return this.#findSlotByType( + this.outputs, + type, + returnObj, + preferFreeSlot, + doNotUseOccupied + ) + } + + /** + * returns the output (or input) slot with a given type, -1 if not found + * @param input use inputs instead of outputs + * @param type the type of the slot to find + * @param returnObj if the obj itself wanted + * @param preferFreeSlot if we want a free slot (if not found, will return the first of the type anyway) + * @returns the slot (-1 if not found) + */ + findSlotByType( + input: TSlot, + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): number + findSlotByType( + input: TSlot, + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): INodeInputSlot | -1 + findSlotByType( + input: TSlot, + type: ISlotType, + returnObj?: TReturn, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): INodeOutputSlot | -1 + findSlotByType( + input: boolean, + type: ISlotType, + returnObj?: boolean, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): number | INodeOutputSlot | INodeInputSlot { + return input + ? this.#findSlotByType( + this.inputs, + type, + returnObj, + preferFreeSlot, + doNotUseOccupied + ) + : this.#findSlotByType( + this.outputs, + type, + returnObj, + preferFreeSlot, + doNotUseOccupied + ) + } + + /** + * Finds a matching slot from those provided, returning the slot itself or its index in {@link slots}. + * @param slots Slots to search (this.inputs or this.outputs) + * @param type Type of slot to look for + * @param returnObj If true, returns the slot itself. Otherwise, the index. + * @param preferFreeSlot Prefer a free slot, but if none are found, fall back to an occupied slot. + * @param doNotUseOccupied Do not fall back to occupied slots. + * @see {findSlotByType} + * @see {findOutputSlotByType} + * @see {findInputSlotByType} + * @returns If a match is found, the slot if returnObj is true, otherwise the index. If no matches are found, -1 + */ + #findSlotByType( + slots: TSlot[], + type: ISlotType, + returnObj?: boolean, + preferFreeSlot?: boolean, + doNotUseOccupied?: boolean + ): TSlot | number { + const length = slots?.length + if (!length) return -1 + + // Empty string and * match anything (type: 0) + if (type == '' || type == '*') type = 0 + const sourceTypes = String(type).toLowerCase().split(',') + + // Run the search + let occupiedSlot: number | TSlot | null = null + for (let i = 0; i < length; ++i) { + const slot: TSlot & IGenericLinkOrLinks = slots[i] + const destTypes = + slot.type == '0' || slot.type == '*' + ? ['0'] + : String(slot.type).toLowerCase().split(',') + + for (const sourceType of sourceTypes) { + // TODO: Remove _event_ entirely. + const source = sourceType == '_event_' ? LiteGraph.EVENT : sourceType + + for (const destType of destTypes) { + const dest = destType == '_event_' ? LiteGraph.EVENT : destType + + if (source == dest || source === '*' || dest === '*') { + if (preferFreeSlot && (slot.links?.length || slot.link != null)) { + // In case we can't find a free slot. + occupiedSlot ??= returnObj ? slot : i + continue + } + return returnObj ? slot : i + } + } + } + } + + return doNotUseOccupied ? -1 : (occupiedSlot ?? -1) + } + + /** + * Determines the slot index to connect to when attempting to connect by type. + * @param findInputs If true, searches for an input. Otherwise, an output. + * @param node The node at the other end of the connection. + * @param slotType The type of slot at the other end of the connection. + * @param options Search restrictions to adhere to. + * @see {connectByType} + * @see {connectByTypeOutput} + */ + findConnectByTypeSlot( + findInputs: boolean, + node: LGraphNode, + slotType: ISlotType, + options?: ConnectByTypeOptions + ): number | undefined { + // LEGACY: Old options names + if (options && typeof options === 'object') { + if ('firstFreeIfInputGeneralInCase' in options) + options.wildcardToTyped = !!options.firstFreeIfInputGeneralInCase + if ('firstFreeIfOutputGeneralInCase' in options) + options.wildcardToTyped = !!options.firstFreeIfOutputGeneralInCase + if ('generalTypeInCase' in options) + options.typedToWildcard = !!options.generalTypeInCase + } + const optsDef: ConnectByTypeOptions = { + createEventInCase: true, + wildcardToTyped: true, + typedToWildcard: true + } + const opts = Object.assign(optsDef, options) + + if (!this.graph) throw new NullGraphError() + + if (node && typeof node === 'number') { + const nodeById = this.graph.getNodeById(node) + if (!nodeById) return + + node = nodeById + } + const slot = node.findSlotByType(findInputs, slotType, false, true) + if (slot >= 0 && slot !== null) return slot + + // TODO: Remove or reimpl. events. WILL CREATE THE onTrigger IN SLOT + if (opts.createEventInCase && slotType == LiteGraph.EVENT) { + if (findInputs) return -1 + if (LiteGraph.do_add_triggers_slots) return node.addOnExecutedOutput() + } + + // connect to the first general output slot if not found a specific type and + if (opts.typedToWildcard) { + const generalSlot = node.findSlotByType(findInputs, 0, false, true, true) + if (generalSlot >= 0) return generalSlot + } + // connect to the first free input slot if not found a specific type and this output is general + if ( + opts.wildcardToTyped && + (slotType == 0 || slotType == '*' || slotType == '') + ) { + const opt = { typesNotAccepted: [LiteGraph.EVENT] } + const nonEventSlot = findInputs + ? node.findInputSlotFree(opt) + : node.findOutputSlotFree(opt) + if (nonEventSlot >= 0) return nonEventSlot + } + } + + /** + * Finds the first free output slot with any of the comma-delimited types in {@link type}. + * + * If no slots are free, falls back in order to: + * - The first free wildcard slot + * - The first occupied slot + * - The first occupied wildcard slot + * @param type The {@link ISlotType type} of slot to find + * @returns The index and slot if found, otherwise `undefined`. + */ + findOutputByType( + type: ISlotType + ): { index: number; slot: INodeOutputSlot } | undefined { + return findFreeSlotOfType( + this.outputs, + type, + (output) => !output.links?.length + ) + } + + /** + * Finds the first free input slot with any of the comma-delimited types in {@link type}. + * + * If no slots are free, falls back in order to: + * - The first free wildcard slot + * - The first occupied slot + * - The first occupied wildcard slot + * @param type The {@link ISlotType type} of slot to find + * @returns The index and slot if found, otherwise `undefined`. + */ + findInputByType( + type: ISlotType + ): { index: number; slot: INodeInputSlot } | undefined { + return findFreeSlotOfType( + this.inputs, + type, + (input) => + input.link == null || !!this.graph?.getLink(input.link)?._dragging + ) + } + + /** + * connect this node output to the input of another node BY TYPE + * @param slot (could be the number of the slot or the string with the name of the slot) + * @param target_node the target node + * @param target_slotType the input slot type of the target node + * @returns the link_info is created, otherwise null + */ + connectByType( + slot: number | string, + target_node: LGraphNode, + target_slotType: ISlotType, + optsIn?: ConnectByTypeOptions + ): LLink | null { + const slotIndex = this.findConnectByTypeSlot( + true, + target_node, + target_slotType, + optsIn + ) + if (slotIndex !== undefined) + return this.connect(slot, target_node, slotIndex, optsIn?.afterRerouteId) + + // No compatible slot found - connection not possible + return null + } + + /** + * connect this node input to the output of another node BY TYPE + * @param slot (could be the number of the slot or the string with the name of the slot) + * @param source_node the target node + * @param source_slotType the output slot type of the target node + * @returns the link_info is created, otherwise null + */ + connectByTypeOutput( + slot: number | string, + source_node: LGraphNode, + source_slotType: ISlotType, + optsIn?: ConnectByTypeOptions + ): LLink | null { + // LEGACY: Old options names + if (typeof optsIn === 'object') { + if ('firstFreeIfInputGeneralInCase' in optsIn) + optsIn.wildcardToTyped = !!optsIn.firstFreeIfInputGeneralInCase + if ('generalTypeInCase' in optsIn) + optsIn.typedToWildcard = !!optsIn.generalTypeInCase + } + const slotIndex = this.findConnectByTypeSlot( + false, + source_node, + source_slotType, + optsIn + ) + if (slotIndex !== undefined) + return source_node.connect(slotIndex, this, slot, optsIn?.afterRerouteId) + + console.error( + '[connectByType]: no way to connect type:', + source_slotType, + 'to node:', + source_node + ) + return null + } + + canConnectTo( + node: NodeLike, + toSlot: INodeInputSlot | SubgraphIO, + fromSlot: INodeOutputSlot | SubgraphIO + ) { + return ( + this.id !== node.id && + LiteGraph.isValidConnection(fromSlot.type, toSlot.type) + ) + } + + /** + * Connect an output of this node to an input of another node + * @param slot (could be the number of the slot or the string with the name of the slot) + * @param target_node the target node + * @param target_slot the input slot of the target node (could be the number of the slot or the string with the name of the slot, or -1 to connect a trigger) + * @returns the link_info is created, otherwise null + */ + connect( + slot: number | string, + target_node: LGraphNode, + target_slot: ISlotType, + afterRerouteId?: RerouteId + ): LLink | null { + // Allow legacy API support for searching target_slot by string, without mutating the input variables + let targetIndex: number | null + + const { graph, outputs } = this + if (!graph) { + // could be connected before adding it to a graph + // due to link ids being associated with graphs + console.error( + "Connect: Error, node doesn't belong to any graph. Nodes must be added first to a graph before connecting them." + ) + return null + } + + // seek for the output slot + if (typeof slot === 'string') { + slot = this.findOutputSlot(slot) + if (slot == -1) { + if (LiteGraph.debug) + console.error(`Connect: Error, no slot of name ${slot}`) + return null + } + } else if (!outputs || slot >= outputs.length) { + if (LiteGraph.debug) + console.error('Connect: Error, slot number not found') + return null + } + + if (target_node && typeof target_node === 'number') { + const nodeById = graph.getNodeById(target_node) + if (!nodeById) throw 'target node is null' + + target_node = nodeById + } + if (!target_node) throw 'target node is null' + + // avoid loopback + if (target_node == this) return null + + // you can specify the slot by name + if (typeof target_slot === 'string') { + targetIndex = target_node.findInputSlot(target_slot) + if (targetIndex == -1) { + if (LiteGraph.debug) + console.error(`Connect: Error, no slot of name ${targetIndex}`) + return null + } + } else if (target_slot === LiteGraph.EVENT) { + // TODO: Events + if (LiteGraph.do_add_triggers_slots) { + target_node.changeMode(LGraphEventMode.ON_TRIGGER) + targetIndex = target_node.findInputSlot('onTrigger') + } else { + return null + } + } else if (typeof target_slot === 'number') { + targetIndex = target_slot + } else { + targetIndex = 0 + } + + // Allow target node to change slot + if (target_node.onBeforeConnectInput) { + // This way node can choose another slot (or make a new one?) + const requestedIndex = target_node.onBeforeConnectInput( + targetIndex, + target_slot + ) + targetIndex = typeof requestedIndex === 'number' ? requestedIndex : null + } + + if ( + targetIndex === null || + !target_node.inputs || + targetIndex >= target_node.inputs.length + ) { + if (LiteGraph.debug) + console.error('Connect: Error, slot number not found') + return null + } + + const input = target_node.inputs[targetIndex] + const output = outputs[slot] + + if (!output) return null + + if (output.links?.length) { + if ( + output.type === LiteGraph.EVENT && + !LiteGraph.allow_multi_output_for_events + ) { + graph.beforeChange() + this.disconnectOutput(slot) + } + } + + const link = this.connectSlots(output, target_node, input, afterRerouteId) + return link ?? null + } + + /** + * Connect two slots between two nodes + * @param output The output slot to connect + * @param inputNode The node that the input slot is on + * @param input The input slot to connect + * @param afterRerouteId The reroute ID to use for the link + * @returns The link that was created, or null if the connection was blocked + */ + connectSlots( + output: INodeOutputSlot, + inputNode: LGraphNode, + input: INodeInputSlot, + afterRerouteId: RerouteId | undefined + ): LLink | null | undefined { + const { graph } = this + if (!graph) throw new NullGraphError() + + const layoutMutations = useLayoutMutations() + + const outputIndex = this.outputs.indexOf(output) + if (outputIndex === -1) { + console.warn('connectSlots: output not found') + return + } + const inputIndex = inputNode.inputs.indexOf(input) + if (inputIndex === -1) { + console.warn('connectSlots: input not found') + return + } + + // check targetSlot and check connection types + if (!LiteGraph.isValidConnection(output.type, input.type)) { + this.setDirtyCanvas(false, true) + return null + } + + // Allow nodes to block connection + if ( + inputNode.onConnectInput?.( + inputIndex, + output.type, + output, + this, + outputIndex + ) === false + ) + return null + if ( + this.onConnectOutput?.( + outputIndex, + input.type, + input, + inputNode, + inputIndex + ) === false + ) + return null + + // if there is something already plugged there, disconnect + if (inputNode.inputs[inputIndex]?.link != null) { + graph.beforeChange() + inputNode.disconnectInput(inputIndex, true) + } + + const maybeCommonType = + input.type && output.type && commonType(input.type, output.type) + + const link = new LLink( + ++graph.state.lastLinkId, + maybeCommonType || input.type || output.type, + this.id, + outputIndex, + inputNode.id, + inputIndex, + afterRerouteId + ) + + // add to graph links list + graph._links.set(link.id, link) + + // Register link in Layout Store for spatial tracking + layoutMutations.setSource(LayoutSource.Canvas) + layoutMutations.createLink( + link.id, + this.id, + outputIndex, + inputNode.id, + inputIndex + ) + + // connect in output + output.links ??= [] + output.links.push(link.id) + // connect in input + const targetInput = inputNode.inputs[inputIndex] + targetInput.link = link.id + if (targetInput.widget) { + graph.trigger('node:slot-links:changed', { + nodeId: inputNode.id, + slotType: NodeSlotType.INPUT, + slotIndex: inputIndex, + connected: true, + linkId: link.id + }) + } + + // Reroutes + const reroutes = LLink.getReroutes(graph, link) + for (const reroute of reroutes) { + reroute.linkIds.add(link.id) + if (reroute.floating) reroute.floating = undefined + reroute._dragging = undefined + } + + // If this is the terminus of a floating link, remove it + const lastReroute = reroutes.at(-1) + if (lastReroute) { + for (const linkId of lastReroute.floatingLinkIds) { + const link = graph.floatingLinks.get(linkId) + if (link?.parentId === lastReroute.id) { + graph.removeFloatingLink(link) + } + } + } + graph._version++ + + // link has been created now, so its updated + this.onConnectionsChange?.( + NodeSlotType.OUTPUT, + outputIndex, + true, + link, + output + ) + + inputNode.onConnectionsChange?.( + NodeSlotType.INPUT, + inputIndex, + true, + link, + input + ) + + this.setDirtyCanvas(false, true) + graph.afterChange() + + return link + } + + connectFloatingReroute( + pos: Point, + slot: INodeInputSlot | INodeOutputSlot, + afterRerouteId?: RerouteId + ): Reroute { + const { graph, id } = this + if (!graph) throw new NullGraphError() + + // Assertion: It's either there or it isn't. + const inputIndex = this.inputs.indexOf(slot as INodeInputSlot) + const outputIndex = this.outputs.indexOf(slot as INodeOutputSlot) + if (inputIndex === -1 && outputIndex === -1) throw new Error('Invalid slot') + + const slotType = outputIndex === -1 ? 'input' : 'output' + + const reroute = graph.setReroute({ + pos, + parentId: afterRerouteId, + linkIds: [], + floating: { slotType } + }) + + const parentReroute = graph.getReroute(afterRerouteId) + const fromLastFloatingReroute = + parentReroute?.floating?.slotType === 'output' + + // Adding from an output, or a floating reroute that is NOT the tip of an existing floating chain + if (afterRerouteId == null || !fromLastFloatingReroute) { + const link = new LLink( + -1, + slot.type, + outputIndex === -1 ? -1 : id, + outputIndex, + inputIndex === -1 ? -1 : id, + inputIndex + ) + link.parentId = reroute.id + graph.addFloatingLink(link) + return reroute + } + + // Adding a new floating reroute from the tip of a floating chain. + if (!parentReroute) + throw new Error('[connectFloatingReroute] Parent reroute not found') + + const link = parentReroute.getFloatingLinks('output')?.[0] + if (!link) + throw new Error('[connectFloatingReroute] Floating link not found') + + reroute.floatingLinkIds.add(link.id) + link.parentId = reroute.id + parentReroute.floating = undefined + return reroute + } + + /** + * disconnect one output to an specific node + * @param slot (could be the number of the slot or the string with the name of the slot) + * @param target_node the target node to which this slot is connected [Optional, + * if not target_node is specified all nodes will be disconnected] + * @returns if it was disconnected successfully + */ + disconnectOutput(slot: string | number, target_node?: LGraphNode): boolean { + if (typeof slot === 'string') { + slot = this.findOutputSlot(slot) + if (slot == -1) { + if (LiteGraph.debug) + console.error(`Connect: Error, no slot of name ${slot}`) + return false + } + } else if (!this.outputs || slot >= this.outputs.length) { + if (LiteGraph.debug) + console.error('Connect: Error, slot number not found') + return false + } + + // get output slot + const output = this.outputs[slot] + if (!output) return false + + if (output._floatingLinks) { + for (const link of output._floatingLinks) { + if (link.hasOrigin(this.id, slot)) { + this.graph?.removeFloatingLink(link) + } + } + } + + if (!output.links || output.links.length == 0) return false + const { links } = output + + // one of the output links in this slot + const graph = this.graph + if (!graph) throw new NullGraphError() + + if (target_node) { + const target = + typeof target_node === 'number' + ? graph.getNodeById(target_node) + : target_node + if (!target) throw 'Target Node not found' + + for (const [i, link_id] of links.entries()) { + const link_info = graph._links.get(link_id) + if (link_info?.target_id != target.id) continue + + // is the link we are searching for... + // remove here + links.splice(i, 1) + const input = target.inputs[link_info.target_slot] + // remove there + input.link = null + if (input.widget) { + graph.trigger('node:slot-links:changed', { + nodeId: target.id, + slotType: NodeSlotType.INPUT, + slotIndex: link_info.target_slot, + connected: false, + linkId: link_info.id + }) + } + + // remove the link from the links pool + link_info.disconnect(graph, 'input') + graph._version++ + + // link_info hasn't been modified so its ok + target.onConnectionsChange?.( + NodeSlotType.INPUT, + link_info.target_slot, + false, + link_info, + input + ) + this.onConnectionsChange?.( + NodeSlotType.OUTPUT, + slot, + false, + link_info, + output + ) + + break + } + } else { + // all the links in this output slot + for (const link_id of links) { + const link_info = graph._links.get(link_id) + if (!link_info) continue + if ( + link_info.target_id === SUBGRAPH_OUTPUT_ID && + graph instanceof Subgraph + ) { + const targetSlot = graph.outputNode.slots[link_info.target_slot] + if (targetSlot) { + targetSlot.linkIds.length = 0 + } else { + console.error('Missing subgraphOutput slot when disconnecting link') + } + } + + const target = graph.getNodeById(link_info.target_id) + graph._version++ + + if (target) { + const input = target.inputs[link_info.target_slot] + // remove other side link + input.link = null + if (input.widget) { + graph.trigger('node:slot-links:changed', { + nodeId: target.id, + slotType: NodeSlotType.INPUT, + slotIndex: link_info.target_slot, + connected: false, + linkId: link_info.id + }) + } + + // link_info hasn't been modified so its ok + target.onConnectionsChange?.( + NodeSlotType.INPUT, + link_info.target_slot, + false, + link_info, + input + ) + } + // remove the link from the links pool + link_info.disconnect(graph, 'input') + + this.onConnectionsChange?.( + NodeSlotType.OUTPUT, + slot, + false, + link_info, + output + ) + } + output.links = null + } + + this.setDirtyCanvas(false, true) + return true + } + + /** + * Disconnect one input + * @param slot Input slot index, or the name of the slot + * @param keepReroutes If `true`, reroutes will not be garbage collected. + * @returns true if disconnected successfully or already disconnected, otherwise false + */ + disconnectInput(slot: number | string, keepReroutes?: boolean): boolean { + // Allow search by string + if (typeof slot === 'string') { + slot = this.findInputSlot(slot) + if (slot == -1) { + if (LiteGraph.debug) + console.error(`Connect: Error, no slot of name ${slot}`) + return false + } + } else if (!this.inputs || slot >= this.inputs.length) { + if (LiteGraph.debug) { + console.error('Connect: Error, slot number not found') + } + return false + } + + const input = this.inputs[slot] + if (!input) { + console.error('disconnectInput: input not found', slot, this.inputs) + return false + } + + const { graph } = this + if (!graph) throw new NullGraphError() + + // Break floating links + if (input._floatingLinks?.size) { + for (const link of input._floatingLinks) { + graph.removeFloatingLink(link) + } + } + + const link_id = this.inputs[slot].link + if (link_id != null) { + this.inputs[slot].link = null + if (input.widget) { + graph.trigger('node:slot-links:changed', { + nodeId: this.id, + slotType: NodeSlotType.INPUT, + slotIndex: slot, + connected: false, + linkId: link_id + }) + } + + // remove other side + const link_info = graph._links.get(link_id) + if (link_info) { + // Let SubgraphInput do the disconnect. + if (link_info.origin_id === -10 && 'inputNode' in graph) { + graph.inputNode._disconnectNodeInput(this, input, link_info) + return true + } + + const target_node = graph.getNodeById(link_info.origin_id) + if (!target_node) { + console.error( + 'disconnectInput: output not found', + link_info.origin_slot + ) + return false + } + + const output = target_node.outputs[link_info.origin_slot] + if (!output?.links?.length) { + // Output not found - may have been removed + return false + } + + // search in the inputs list for this link + let i = 0 + for (const l = output.links.length; i < l; i++) { + if (output.links[i] == link_id) { + output.links.splice(i, 1) + break + } + } + + link_info.disconnect(graph, keepReroutes ? 'output' : undefined) + if (graph) graph._version++ + + this.onConnectionsChange?.( + NodeSlotType.INPUT, + slot, + false, + link_info, + input + ) + target_node.onConnectionsChange?.( + NodeSlotType.OUTPUT, + i, + false, + link_info, + output + ) + } + } + + this.setDirtyCanvas(false, true) + return true + } + + /** + * @deprecated Use {@link getInputPos} or {@link getOutputPos} instead. + * returns the center of a connection point in canvas coords + * @param is_input true if if a input slot, false if it is an output + * @param slot_number (could be the number of the slot or the string with the name of the slot) + * @param out [optional] a place to store the output, to free garbage + * @returns the position + */ + getConnectionPos(is_input: boolean, slot_number: number, out?: Point): Point { + out ||= [0, 0] + + const { + pos: [nodeX, nodeY], + inputs, + outputs + } = this + + if (this.flags.collapsed) { + const w = this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH + out[0] = is_input ? nodeX : nodeX + w + out[1] = nodeY - LiteGraph.NODE_TITLE_HEIGHT * 0.5 + return out + } + + // weird feature that never got finished + if (is_input && slot_number == -1) { + out[0] = nodeX + LiteGraph.NODE_TITLE_HEIGHT * 0.5 + out[1] = nodeY + LiteGraph.NODE_TITLE_HEIGHT * 0.5 + return out + } + + // hard-coded pos + const inputPos = inputs?.[slot_number]?.pos + const outputPos = outputs?.[slot_number]?.pos + + if (is_input && inputPos) { + out[0] = nodeX + inputPos[0] + out[1] = nodeY + inputPos[1] + return out + } else if (!is_input && outputPos) { + out[0] = nodeX + outputPos[0] + out[1] = nodeY + outputPos[1] + return out + } + + // default vertical slots + const offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5 + const slotIndex = is_input + ? this.#defaultVerticalInputs.indexOf(this.inputs[slot_number]) + : this.#defaultVerticalOutputs.indexOf(this.outputs[slot_number]) + + out[0] = is_input ? nodeX + offset : nodeX + this.size[0] + 1 - offset + out[1] = + nodeY + + (slotIndex + 0.7) * LiteGraph.NODE_SLOT_HEIGHT + + (this.constructor.slot_start_y || 0) + return out + } + + /** + * @internal The inputs that are not positioned with absolute coordinates. + */ + get #defaultVerticalInputs() { + return this.inputs.filter( + (slot) => !slot.pos && !(this.widgets?.length && isWidgetInputSlot(slot)) + ) + } + + /** + * @internal The outputs that are not positioned with absolute coordinates. + */ + get #defaultVerticalOutputs() { + return this.outputs.filter((slot: INodeOutputSlot) => !slot.pos) + } + + /** + * Get the context needed for slot position calculations + * @internal + */ + #getSlotPositionContext(): SlotPositionContext { + return { + nodeX: this.pos[0], + nodeY: this.pos[1], + nodeWidth: this.size[0], + nodeHeight: this.size[1], + collapsed: this.flags.collapsed ?? false, + collapsedWidth: this._collapsed_width, + slotStartY: this.constructor.slot_start_y, + inputs: this.inputs, + outputs: this.outputs, + widgets: this.widgets + } + } + + /** + * Gets the position of an input slot, in graph co-ordinates. + * + * This method is preferred over the legacy {@link getConnectionPos} method. + * @param slot Input slot index + * @returns Position of the input slot + */ + getInputPos(slot: number): Point { + return calculateInputSlotPos(this.#getSlotPositionContext(), slot) + } + + /** + * Gets the position of an input slot, in graph co-ordinates. + * @param input The actual node input object + * @returns Position of the centre of the input slot in graph co-ordinates. + */ + getInputSlotPos(input: INodeInputSlot): Point { + return calculateInputSlotPosFromSlot(this.#getSlotPositionContext(), input) + } + + /** + * Gets the position of an output slot, in graph co-ordinates. + * + * This method is preferred over the legacy {@link getConnectionPos} method. + * @param outputSlotIndex Output slot index + * @returns Position of the output slot + */ + getOutputPos(outputSlotIndex: number): Point { + return calculateOutputSlotPos( + this.#getSlotPositionContext(), + outputSlotIndex + ) + } + + /** + * Get slot position using layout tree if available, fallback to node's position * Unified implementation used by both LitegraphLinkAdapter and useLinkLayoutSync + * @param slotIndex The slot index + * @param isInput Whether this is an input slot + * @returns Position of the slot center in graph coordinates + */ + getSlotPosition(slotIndex: number, isInput: boolean): Point { + return getSlotPosition(this, slotIndex, isInput) + } + + /** @inheritdoc */ + snapToGrid(snapTo: number): boolean { + return this.pinned ? false : snapPoint(this.pos, snapTo) + } + + /** @see {@link snapToGrid} */ + alignToGrid(): void { + this.snapToGrid(LiteGraph.CANVAS_GRID_SIZE) + } + + /* Console output */ + trace(msg: string): void { + this.console ||= [] + this.console.push(msg) + // @ts-expect-error deprecated + if (this.console.length > LGraphNode.MAX_CONSOLE) this.console.shift() + } + + /* Forces to redraw or the main canvas (LGraphNode) or the bg canvas (links) */ + setDirtyCanvas(dirty_foreground: boolean, dirty_background?: boolean): void { + this.graph?.canvasAction((c) => + c.setDirty(dirty_foreground, dirty_background) + ) + } + + loadImage(url: string): HTMLImageElement { + interface AsyncImageElement extends HTMLImageElement { + ready?: boolean + } + + const img: AsyncImageElement = new Image() + img.src = LiteGraph.node_images_path + url + img.ready = false + + const dirty = () => this.setDirtyCanvas(true) + img.addEventListener('load', function (this: AsyncImageElement) { + this.ready = true + dirty() + }) + return img + } + + /** + * Allows to get onMouseMove and onMouseUp events even if the mouse is out of focus + * @deprecated Use {@link LGraphCanvas.pointer} instead. + */ + captureInput(v: boolean): void { + warnDeprecated( + '[DEPRECATED] captureInput will be removed in a future version. Please use LGraphCanvas.pointer (CanvasPointer) instead.' + ) + if (!this.graph || !this.graph.list_of_graphcanvas) return + + const list = this.graph.list_of_graphcanvas + + for (const c of list) { + // releasing somebody elses capture?! + if (!v && c.node_capturing_input != this) continue + + // change + c.node_capturing_input = v ? this : null + } + } + + get collapsed() { + return !!this.flags.collapsed + } + + get collapsible() { + return !this.pinned && this.constructor.collapsable !== false + } + + /** + * Toggle node collapse (makes it smaller on the canvas) + */ + collapse(force?: boolean): void { + if (!this.collapsible && !force) return + if (!this.graph) throw new NullGraphError() + this.graph._version++ + this.flags.collapsed = !this.flags.collapsed + this.setDirtyCanvas(true, true) + } + + /** + * Toggles advanced mode of the node, showing advanced widgets + */ + toggleAdvanced() { + if (!this.widgets?.some((w) => w.advanced)) return + if (!this.graph) throw new NullGraphError() + this.graph._version++ + this.showAdvanced = !this.showAdvanced + this.expandToFitContent() + this.setDirtyCanvas(true, true) + } + + get pinned() { + return !!this.flags.pinned + } + + /** + * Prevents the node being accidentally moved or resized by mouse interaction. + * Toggles pinned state if no value is provided. + */ + pin(v?: boolean): void { + if (!this.graph) throw new NullGraphError() + + this.graph._version++ + this.flags.pinned = v ?? !this.flags.pinned + this.resizable = !this.pinned + if (!this.pinned) this.flags.pinned = undefined + } + + unpin(): void { + this.pin(false) + } + + localToScreen(x: number, y: number, dragAndScale: DragAndScale): Point { + return [ + (x + this.pos[0]) * dragAndScale.scale + dragAndScale.offset[0], + (y + this.pos[1]) * dragAndScale.scale + dragAndScale.offset[1] + ] + } + + get width() { + return this.collapsed + ? this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH + : this.size[0] + } + + /** + * Returns the height of the node, including the title bar. + */ + get height() { + return LiteGraph.NODE_TITLE_HEIGHT + this.bodyHeight + } + + /** + * Returns the height of the node, excluding the title bar. + */ + get bodyHeight() { + return this.collapsed ? 0 : this.size[1] + } + + drawBadges(ctx: CanvasRenderingContext2D, { gap = 2 } = {}): void { + const badgeInstances = this.badges.map((badge) => + badge instanceof LGraphBadge ? badge : badge() + ) + const isLeftAligned = this.badgePosition === BadgePosition.TopLeft + + let currentX = isLeftAligned + ? 0 + : this.width - + badgeInstances.reduce( + (acc, badge) => acc + badge.getWidth(ctx) + gap, + 0 + ) + const y = -(LiteGraph.NODE_TITLE_HEIGHT + gap) + + for (const badge of badgeInstances) { + badge.draw(ctx, currentX, y - badge.height) + currentX += badge.getWidth(ctx) + gap + } + } + + /** + * Renders the node's title bar background + */ + drawTitleBarBackground( + ctx: CanvasRenderingContext2D, + { + scale, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + low_quality = false + }: DrawTitleOptions + ): void { + const fgcolor = this.renderingColor + const shape = this.renderingShape + const size = this.renderingSize + + if (this.onDrawTitleBar) { + this.onDrawTitleBar(ctx, title_height, size, scale, fgcolor) + return + } + + if (this.title_mode === TitleMode.TRANSPARENT_TITLE) { + return + } + + if (this.collapsed) { + ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR + } + + ctx.fillStyle = this.constructor.title_color || fgcolor + ctx.beginPath() + + if (shape == RenderShape.BOX || low_quality) { + ctx.rect(0, -title_height, size[0], title_height) + } else if (shape == RenderShape.ROUND || shape == RenderShape.CARD) { + ctx.roundRect( + 0, + -title_height, + size[0], + title_height, + this.collapsed + ? [LiteGraph.ROUND_RADIUS] + : [LiteGraph.ROUND_RADIUS, LiteGraph.ROUND_RADIUS, 0, 0] + ) + } + ctx.fill() + ctx.shadowColor = 'transparent' + } + + /** + * Renders the node's title box, i.e. the dot in front of the title text that + * when clicked toggles the node's collapsed state. The term `title box` comes + * from the original LiteGraph implementation. + */ + drawTitleBox( + ctx: CanvasRenderingContext2D, + { + scale, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT, + box_size = 10 + }: DrawTitleBoxOptions + ): void { + const size = this.renderingSize + const shape = this.renderingShape + + if (this.onDrawTitleBox) { + this.onDrawTitleBox(ctx, title_height, size, scale) + return + } + + if ( + [RenderShape.ROUND, RenderShape.CIRCLE, RenderShape.CARD].includes(shape) + ) { + if (low_quality) { + ctx.fillStyle = 'black' + ctx.beginPath() + ctx.arc( + title_height * 0.5, + title_height * -0.5, + box_size * 0.5 + 1, + 0, + Math.PI * 2 + ) + ctx.fill() + } + + ctx.fillStyle = this.renderingBoxColor + if (low_quality) { + ctx.fillRect( + title_height * 0.5 - box_size * 0.5, + title_height * -0.5 - box_size * 0.5, + box_size, + box_size + ) + } else { + ctx.beginPath() + ctx.arc( + title_height * 0.5, + title_height * -0.5, + box_size * 0.5, + 0, + Math.PI * 2 + ) + ctx.fill() + } + } else { + if (low_quality) { + ctx.fillStyle = 'black' + ctx.fillRect( + (title_height - box_size) * 0.5 - 1, + (title_height + box_size) * -0.5 - 1, + box_size + 2, + box_size + 2 + ) + } + ctx.fillStyle = this.renderingBoxColor + ctx.fillRect( + (title_height - box_size) * 0.5, + (title_height + box_size) * -0.5, + box_size, + box_size + ) + } + } + + /** + * Renders the node's title text. + */ + drawTitleText( + ctx: CanvasRenderingContext2D, + { + scale, + default_title_color, + low_quality = false, + title_height = LiteGraph.NODE_TITLE_HEIGHT + }: DrawTitleTextOptions + ): void { + const size = this.renderingSize + const selected = this.selected + + if (this.onDrawTitleText) { + this.onDrawTitleText( + ctx, + title_height, + size, + scale, + this.titleFontStyle, + selected + ) + return + } + + // Don't render title text if low quality + if (low_quality) { + return + } + + ctx.font = this.titleFontStyle + const rawTitle = this.getTitle() ?? `❌ ${this.type}` + const title = String(rawTitle) + (this.pinned ? '📌' : '') + if (title) { + if (selected) { + ctx.fillStyle = LiteGraph.NODE_SELECTED_TITLE_COLOR + } else { + ctx.fillStyle = this.constructor.title_text_color || default_title_color + } + + // Calculate available width for title + let availableWidth = size[0] - title_height * 2 // Basic margins + + // Subtract space for title buttons + if (this.title_buttons?.length > 0) { + let buttonsWidth = 0 + const savedFont = ctx.font // Save current font + for (const button of this.title_buttons) { + if (button.visible) { + buttonsWidth += button.getWidth(ctx) + 2 // button width + gap + } + } + ctx.font = savedFont // Restore font after button measurements + if (buttonsWidth > 0) { + buttonsWidth -= 20 // Reduce by empty padding + availableWidth -= buttonsWidth + } + } + + // Truncate title if needed + let displayTitle = title + + if (this.collapsed) { + // For collapsed nodes, limit to 20 chars as before + displayTitle = title.substr(0, 20) + } else if (availableWidth > 0) { + // For regular nodes, truncate based on available width + displayTitle = truncateText(ctx, title, availableWidth) + } + + ctx.textAlign = 'left' + ctx.fillText( + displayTitle, + title_height, + LiteGraph.NODE_TITLE_TEXT_Y - title_height + ) + } + } + + /** + * Attempts to gracefully bypass this node in all of its connections by reconnecting all links. + * + * Each input is checked against each output. This is done on a matching index basis, i.e. input 3 -> output 3. + * If there are any input links remaining, + * and {@link flags}.{@link INodeFlags.keepAllLinksOnBypass keepAllLinksOnBypass} is `true`, + * each input will check for outputs that match, and take the first one that matches + * `true`: Try the index matching first, then every input to every output. + * `false`: Only matches indexes, e.g. input 3 to output 3. + * + * If {@link flags}.{@link INodeFlags.keepAllLinksOnBypass keepAllLinksOnBypass} is `undefined`, it will fall back to + * the static {@link keepAllLinksOnBypass}. + * @returns `true` if any new links were established, otherwise `false`. + * @todo Decision: Change API to return array of new links instead? + */ + connectInputToOutput(): boolean | undefined { + const { inputs, outputs, graph } = this + if (!inputs || !outputs) return + if (!graph) throw new NullGraphError() + + const { _links } = graph + let madeAnyConnections = false + + // First pass: only match exactly index-to-index + for (const [index, input] of inputs.entries()) { + if (input.link == null) continue + + const output = outputs[index] + if (!output || !LiteGraph.isValidConnection(input.type, output.type)) + continue + + const inLink = _links.get(input.link) + if (!inLink) continue + const inNode = graph.getNodeById(inLink?.origin_id) + if (!inNode) continue + + bypassAllLinks(output, inNode, inLink, graph) + } + // Configured to only use index-to-index matching + if (!(this.flags.keepAllLinksOnBypass ?? LGraphNode.keepAllLinksOnBypass)) + return madeAnyConnections + + // Second pass: match any remaining links + for (const input of inputs) { + if (input.link == null) continue + + const inLink = _links.get(input.link) + if (!inLink) continue + const inNode = graph.getNodeById(inLink?.origin_id) + if (!inNode) continue + + for (const output of outputs) { + if (!LiteGraph.isValidConnection(input.type, output.type)) continue + + bypassAllLinks(output, inNode, inLink, graph) + break + } + } + return madeAnyConnections + + function bypassAllLinks( + output: INodeOutputSlot, + inNode: LGraphNode, + inLink: LLink, + graph: LGraph + ) { + const outLinks = output.links + ?.map((x) => _links.get(x)) + .filter((x) => !!x) + if (!outLinks?.length) return + + for (const outLink of outLinks) { + const outNode = graph.getNodeById(outLink.target_id) + if (!outNode) continue + + const result = inNode.connect( + inLink.origin_slot, + outNode, + outLink.target_slot, + inLink.parentId + ) + madeAnyConnections ||= !!result + } + } + } + + /** + * Returns `true` if the widget is visible, otherwise `false`. + */ + isWidgetVisible(widget: IBaseWidget): boolean { + const isHidden = + this.collapsed || widget.hidden || (widget.advanced && !this.showAdvanced) + return !isHidden + } + + updateComputedDisabled() { + if (!this.widgets) return + for (const widget of this.widgets) + widget.computedDisabled = + widget.disabled || this.getSlotFromWidget(widget)?.link != null + } + + drawWidgets( + ctx: CanvasRenderingContext2D, + { lowQuality = false, editorAlpha = 1 }: DrawWidgetsOptions + ): void { + if (!this.widgets) return + + const nodeWidth = this.size[0] + const { widgets } = this + const H = LiteGraph.NODE_WIDGET_HEIGHT + const showText = !lowQuality + ctx.save() + ctx.globalAlpha = editorAlpha + + this.updateComputedDisabled() + for (const widget of widgets) { + if (!this.isWidgetVisible(widget)) continue + + const { y } = widget + const outlineColour = widget.advanced + ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR + : LiteGraph.WIDGET_OUTLINE_COLOR + + widget.last_y = y + + ctx.strokeStyle = outlineColour + ctx.fillStyle = '#222' + ctx.textAlign = 'left' + if (widget.computedDisabled) ctx.globalAlpha *= 0.5 + const width = widget.width || nodeWidth + + if (typeof widget.draw === 'function') { + widget.draw(ctx, this, width, y, H, lowQuality) + } else { + toConcreteWidget(widget, this, false)?.drawWidget(ctx, { + width, + showText + }) + } + ctx.globalAlpha = editorAlpha + } + ctx.restore() + } + + /** + * When {@link LGraphNode.collapsed} is `true`, this method draws the node's collapsed slots. + */ + drawCollapsedSlots(ctx: CanvasRenderingContext2D): void { + // Render the first connected slot only. + for (const slot of this.#concreteInputs) { + if (slot.link != null) { + slot.drawCollapsed(ctx) + break + } + } + for (const slot of this.#concreteOutputs) { + if (slot.links?.length) { + slot.drawCollapsed(ctx) + break + } + } + } + + get slots(): (INodeInputSlot | INodeOutputSlot)[] { + return [...this.inputs, ...this.outputs] + } + + #measureSlot( + slot: NodeInputSlot | NodeOutputSlot, + slotIndex: number, + isInput: boolean + ): void { + const pos = isInput + ? this.getInputPos(slotIndex) + : this.getOutputPos(slotIndex) + + slot.boundingRect[0] = pos[0] - LiteGraph.NODE_SLOT_HEIGHT * 0.5 + slot.boundingRect[1] = pos[1] - LiteGraph.NODE_SLOT_HEIGHT * 0.5 + slot.boundingRect[2] = slot.isWidgetInputSlot + ? BaseWidget.margin + : LiteGraph.NODE_SLOT_HEIGHT + slot.boundingRect[3] = LiteGraph.NODE_SLOT_HEIGHT + } + + #measureSlots(): ReadOnlyRect | null { + const slots: (NodeInputSlot | NodeOutputSlot)[] = [] + + for (const [slotIndex, slot] of this.#concreteInputs.entries()) { + // Unrecognized nodes (Nodes with error) has inputs but no widgets. Treat + // converted inputs as normal inputs. + /** Widget input slots are handled in {@link layoutWidgetInputSlots} */ + if (this.widgets?.length && isWidgetInputSlot(slot)) continue + + this.#measureSlot(slot, slotIndex, true) + slots.push(slot) + } + for (const [slotIndex, slot] of this.#concreteOutputs.entries()) { + this.#measureSlot(slot, slotIndex, false) + slots.push(slot) + } + + return slots.length ? createBounds(slots, 0) : null + } + + #getMouseOverSlot(slot: INodeSlot): INodeSlot | null { + const isInput = isINodeInputSlot(slot) + const mouseOverId = this.mouseOver?.[isInput ? 'inputId' : 'outputId'] ?? -1 + if (mouseOverId === -1) { + return null + } + return isInput ? this.inputs[mouseOverId] : this.outputs[mouseOverId] + } + + #isMouseOverSlot(slot: INodeSlot): boolean { + return this.#getMouseOverSlot(slot) === slot + } + + #isMouseOverWidget(widget: IBaseWidget | undefined): boolean { + if (!widget) return false + return this.mouseOver?.overWidget === widget + } + + /** + * Returns the input slot that is associated with the given widget. + */ + getSlotFromWidget( + widget: IBaseWidget | undefined + ): INodeInputSlot | undefined { + if (widget) + return this.inputs.find( + (slot) => isWidgetInputSlot(slot) && slot.widget.name === widget.name + ) + } + + /** + * Returns the widget that is associated with the given input slot. + */ + getWidgetFromSlot(slot: INodeInputSlot): IBaseWidget | undefined { + if (!isWidgetInputSlot(slot)) return + return this.widgets?.find((w) => w.name === slot.widget.name) + } + + /** + * Draws the node's input and output slots. + */ + drawSlots( + ctx: CanvasRenderingContext2D, + { fromSlot, colorContext, editorAlpha, lowQuality }: DrawSlotsOptions + ) { + for (const slot of [...this.#concreteInputs, ...this.#concreteOutputs]) { + const isValidTarget = fromSlot && slot.isValidTarget(fromSlot) + const isMouseOverSlot = this.#isMouseOverSlot(slot) + + // change opacity of incompatible slots when dragging a connection + const isValid = !fromSlot || isValidTarget + const highlight = isValid && isMouseOverSlot + + // Show slot if it's not a widget input slot + // or if it's a widget input slot and satisfies one of the following: + // - the mouse is over the widget + // - the slot is valid during link drop + // - the slot is connected + if ( + isMouseOverSlot || + isValidTarget || + !slot.isWidgetInputSlot || + this.#isMouseOverWidget(this.getWidgetFromSlot(slot)) || + slot.isConnected || + slot.alwaysVisible + ) { + ctx.globalAlpha = isValid ? editorAlpha : 0.4 * editorAlpha + slot.draw(ctx, { + colorContext, + lowQuality, + highlight + }) + } + } + } + + /** + * Arranges the node's widgets vertically. + * Sets following properties on each widget: + * - {@link IBaseWidget.computedHeight} + * - {@link IBaseWidget.y} + * @param widgetStartY The y-coordinate of the first widget + */ + #arrangeWidgets(widgetStartY: number): void { + if (!this.widgets || !this.widgets.length) return + + const bodyHeight = this.bodyHeight + const startY = + this.widgets_start_y ?? (this.widgets_up ? 0 : widgetStartY) + 2 + + let freeSpace = bodyHeight - startY + + // Collect fixed height widgets first + let fixedWidgetHeight = 0 + const growableWidgets: { + minHeight: number + prefHeight?: number + w: IBaseWidget + }[] = [] + + const visibleWidgets = this.widgets.filter((w) => !w.hidden) + + for (const w of visibleWidgets) { + if (w.computeSize) { + const height = w.computeSize()[1] + 4 + w.computedHeight = height + fixedWidgetHeight += height + } else if (w.computeLayoutSize) { + const { minHeight, maxHeight } = w.computeLayoutSize(this) + growableWidgets.push({ + minHeight, + prefHeight: maxHeight, + w + }) + } else { + const height = LiteGraph.NODE_WIDGET_HEIGHT + 4 + w.computedHeight = height + fixedWidgetHeight += height + } + } + + // Calculate remaining space for DOM widgets + freeSpace -= fixedWidgetHeight + this.freeWidgetSpace = freeSpace + + // Prepare space requests for distribution + const spaceRequests = growableWidgets.map((d) => ({ + minSize: d.minHeight, + maxSize: d.prefHeight + })) + + // Distribute space among DOM widgets + const allocations = distributeSpace(Math.max(0, freeSpace), spaceRequests) + + // Apply computed heights + for (const [i, d] of growableWidgets.entries()) { + d.w.computedHeight = allocations[i] + } + + // Position widgets + let y = startY + for (const w of visibleWidgets) { + w.y = y + y += w.computedHeight ?? 0 + } + + if (!this.graph) throw new NullGraphError() + + // Grow the node if necessary. + // Ref: https://github.com/Comfy-Org/ComfyUI_frontend/issues/2652 + // TODO: Move the layout logic before drawing of the node shape, so we don't + // need to trigger extra round of rendering. + if (y > bodyHeight) { + this.setSize([this.size[0], y]) + this.graph.setDirtyCanvas(false, true) + } + } + + /** + * Arranges the layout of the node's widget input slots. + */ + #arrangeWidgetInputSlots(): void { + if (!this.widgets) return + + const slotByWidgetName = new Map< + string, + INodeInputSlot & { index: number } + >() + + for (const [i, slot] of this.inputs.entries()) { + if (!isWidgetInputSlot(slot)) continue + + slotByWidgetName.set(slot.widget.name, { ...slot, index: i }) + } + if (!slotByWidgetName.size) return + + // Only set custom pos if not using Vue positioning + // Vue positioning calculates widget slot positions dynamically + if (!LiteGraph.vueNodesMode) { + for (const widget of this.widgets) { + const slot = slotByWidgetName.get(widget.name) + if (!slot) continue + + const actualSlot = this.#concreteInputs[slot.index] + const offset = LiteGraph.NODE_SLOT_HEIGHT * 0.5 + actualSlot.pos = [offset, widget.y + offset] + this.#measureSlot(actualSlot, slot.index, true) + } + } else { + // For Vue positioning, just measure the slots without setting pos + for (const widget of this.widgets) { + const slot = slotByWidgetName.get(widget.name) + if (!slot) continue + + this.#measureSlot(this.#concreteInputs[slot.index], slot.index, true) + } + } + } + + /** + * @internal Sets the internal concrete slot arrays, ensuring they are instances of + * {@link NodeInputSlot} or {@link NodeOutputSlot}. + * + * A temporary workaround until duck-typed inputs and outputs + * have been removed from the ecosystem. + */ + _setConcreteSlots(): void { + this.#concreteInputs = this.inputs.map((slot) => + toClass(NodeInputSlot, slot, this) + ) + this.#concreteOutputs = this.outputs.map((slot) => + toClass(NodeOutputSlot, slot, this) + ) + } + + /** + * Arranges node elements in preparation for rendering (slots & widgets). + */ + arrange(): void { + const slotsBounds = this.#measureSlots() + const widgetStartY = slotsBounds + ? slotsBounds[1] + slotsBounds[3] - this.pos[1] + : 0 + this.#arrangeWidgets(widgetStartY) + this.#arrangeWidgetInputSlots() + } + + /** + * Draws a progress bar on the node. + * @param ctx The canvas context to draw on + */ + drawProgressBar(ctx: CanvasRenderingContext2D): void { + if (!this.progress) return + + const originalFillStyle = ctx.fillStyle + ctx.fillStyle = 'green' + ctx.fillRect(0, 0, this.width * this.progress, 6) + ctx.fillStyle = originalFillStyle + } +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__BaseWidget.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__BaseWidget.ts new file mode 100644 index 00000000..a580fc69 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__BaseWidget.ts @@ -0,0 +1,349 @@ +import { drawTextInArea } from '@/lib/litegraph/src/draw' +import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' +import type { Point } from '@/lib/litegraph/src/interfaces' +import type { + CanvasPointer, + LGraphCanvas, + LGraphNode, + Size +} from '@/lib/litegraph/src/litegraph' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { CanvasPointerEvent } from '@/lib/litegraph/src/types/events' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' + +export interface DrawWidgetOptions { + /** The width of the node where this widget will be displayed. */ + width: number + /** Synonym for "low quality". */ + showText?: boolean +} + +interface DrawTruncatingTextOptions extends DrawWidgetOptions { + /** The canvas context to draw the text on. */ + ctx: CanvasRenderingContext2D + /** The amount of padding to add to the left of the text. */ + leftPadding?: number + /** The amount of padding to add to the right of the text. */ + rightPadding?: number +} + +export interface WidgetEventOptions { + e: CanvasPointerEvent + node: LGraphNode + canvas: LGraphCanvas +} + +export abstract class BaseWidget< + TWidget extends IBaseWidget = IBaseWidget +> implements IBaseWidget { + /** From node edge to widget edge */ + static margin = 15 + /** From widget edge to tip of arrow button */ + static arrowMargin = 6 + /** Arrow button width */ + static arrowWidth = 10 + /** Absolute minimum display width of widget values */ + static minValueWidth = 42 + /** Minimum gap between label and value */ + static labelValueGap = 5 + + declare computedHeight?: number + declare serialize?: boolean + computeLayoutSize?(node: LGraphNode): { + minHeight: number + maxHeight?: number + minWidth: number + maxWidth?: number + } + + #node: LGraphNode + /** The node that this widget belongs to. */ + get node() { + return this.#node + } + + linkedWidgets?: IBaseWidget[] + name: string + options: TWidget['options'] + label?: string + type: TWidget['type'] + y: number = 0 + last_y?: number + width?: number + disabled?: boolean + computedDisabled?: boolean + hidden?: boolean + advanced?: boolean + promoted?: boolean + tooltip?: string + element?: HTMLElement + callback?( + value: TWidget['value'], + canvas?: LGraphCanvas, + node?: LGraphNode, + pos?: Point, + e?: CanvasPointerEvent + ): void + mouse?( + event: CanvasPointerEvent, + pointerOffset: Point, + node: LGraphNode + ): boolean + computeSize?(width?: number): Size + onPointerDown?( + pointer: CanvasPointer, + node: LGraphNode, + canvas: LGraphCanvas + ): boolean + + #value?: TWidget['value'] + get value(): TWidget['value'] { + return this.#value + } + + set value(value: TWidget['value']) { + this.#value = value + } + + constructor(widget: TWidget & { node: LGraphNode }) + constructor(widget: TWidget, node: LGraphNode) + constructor(widget: TWidget & { node: LGraphNode }, node?: LGraphNode) { + // Private fields + this.#node = node ?? widget.node + + // The set and get functions for DOM widget values are hacked on to the options object; + // attempting to set value before options will throw. + // https://github.com/Comfy-Org/ComfyUI_frontend/blob/df86da3d672628a452baed3df3347a52c0c8d378/src/scripts/domWidget.ts#L125 + this.name = widget.name + this.options = widget.options + this.type = widget.type + + // `node` has no setter - Object.assign will throw. + // TODO: Resolve this workaround. Ref: https://github.com/Comfy-Org/litegraph.js/issues/1022 + const { + node: _, + // @ts-expect-error Prevent naming conflicts with custom nodes. + outline_color, + // @ts-expect-error Prevent naming conflicts with custom nodes. + background_color, + // @ts-expect-error Prevent naming conflicts with custom nodes. + height, + // @ts-expect-error Prevent naming conflicts with custom nodes. + text_color, + // @ts-expect-error Prevent naming conflicts with custom nodes. + secondary_text_color, + // @ts-expect-error Prevent naming conflicts with custom nodes. + disabledTextColor, + // @ts-expect-error Prevent naming conflicts with custom nodes. + displayName, + // @ts-expect-error Prevent naming conflicts with custom nodes. + displayValue, + // @ts-expect-error Prevent naming conflicts with custom nodes. + labelBaseline, + promoted, + ...safeValues + } = widget + + Object.assign(this, safeValues) + } + + get outline_color() { + if (this.promoted) return LiteGraph.WIDGET_PROMOTED_OUTLINE_COLOR + return this.advanced + ? LiteGraph.WIDGET_ADVANCED_OUTLINE_COLOR + : LiteGraph.WIDGET_OUTLINE_COLOR + } + + get background_color() { + return LiteGraph.WIDGET_BGCOLOR + } + + get height() { + return LiteGraph.NODE_WIDGET_HEIGHT + } + + get text_color() { + return LiteGraph.WIDGET_TEXT_COLOR + } + + get secondary_text_color() { + return LiteGraph.WIDGET_SECONDARY_TEXT_COLOR + } + + get disabledTextColor() { + return LiteGraph.WIDGET_DISABLED_TEXT_COLOR + } + + get displayName() { + return this.label || this.name + } + + // TODO: Resolve this workaround. Ref: https://github.com/Comfy-Org/litegraph.js/issues/1022 + get _displayValue(): string { + return this.computedDisabled ? '' : String(this.value) + } + + get labelBaseline() { + return this.y + this.height * 0.7 + } + + /** + * Draws the widget + * @param ctx The canvas context + * @param options The options for drawing the widget + * @remarks Not naming this `draw` as `draw` conflicts with the `draw` method in + * custom widgets. + */ + abstract drawWidget( + ctx: CanvasRenderingContext2D, + options: DrawWidgetOptions + ): void + + /** + * Draws the standard widget shape - elongated capsule. The path of the widget shape is not + * cleared, and may be used for further drawing. + * @param ctx The canvas context + * @param options The options for drawing the widget + * @remarks Leaves {@link ctx} dirty. + */ + protected drawWidgetShape( + ctx: CanvasRenderingContext2D, + { width, showText }: DrawWidgetOptions + ): void { + const { height, y } = this + const { margin } = BaseWidget + + ctx.textAlign = 'left' + ctx.strokeStyle = this.outline_color + ctx.fillStyle = this.background_color + ctx.beginPath() + + if (showText) { + ctx.roundRect(margin, y, width - margin * 2, height, [height * 0.5]) + } else { + ctx.rect(margin, y, width - margin * 2, height) + } + ctx.fill() + if (showText && !this.computedDisabled) ctx.stroke() + } + + /** + * A shared routine for drawing a label and value as text, truncated + * if they exceed the available width. + */ + protected drawTruncatingText({ + ctx, + width, + leftPadding = 5, + rightPadding = 20 + }: DrawTruncatingTextOptions): void { + const { height, y } = this + const { margin } = BaseWidget + + // Measure label and value + const { displayName, _displayValue } = this + const labelWidth = ctx.measureText(displayName).width + const valueWidth = ctx.measureText(_displayValue).width + + const gap = BaseWidget.labelValueGap + const x = margin * 2 + leftPadding + + const totalWidth = width - x - 2 * margin - rightPadding + const requiredWidth = labelWidth + gap + valueWidth + + const area = new Rectangle(x, y, totalWidth, height * 0.7) + + ctx.fillStyle = this.secondary_text_color + + if (requiredWidth <= totalWidth) { + // Draw label & value normally + drawTextInArea({ ctx, text: displayName, area, align: 'left' }) + } else if (LiteGraph.truncateWidgetTextEvenly) { + // Label + value will not fit - scale evenly to fit + const scale = (totalWidth - gap) / (requiredWidth - gap) + area.width = labelWidth * scale + + drawTextInArea({ ctx, text: displayName, area, align: 'left' }) + + // Move the area to the right to render the value + area.right = x + totalWidth + area.setWidthRightAnchored(valueWidth * scale) + } else if (LiteGraph.truncateWidgetValuesFirst) { + // Label + value will not fit - use legacy scaling of value first + const cappedLabelWidth = Math.min(labelWidth, totalWidth) + + area.width = cappedLabelWidth + drawTextInArea({ ctx, text: displayName, area, align: 'left' }) + + area.right = x + totalWidth + area.setWidthRightAnchored( + Math.max(totalWidth - gap - cappedLabelWidth, 0) + ) + } else { + // Label + value will not fit - scale label first + const cappedValueWidth = Math.min(valueWidth, totalWidth) + + area.width = Math.max(totalWidth - gap - cappedValueWidth, 0) + drawTextInArea({ ctx, text: displayName, area, align: 'left' }) + + area.right = x + totalWidth + area.setWidthRightAnchored(cappedValueWidth) + } + ctx.fillStyle = this.text_color + drawTextInArea({ ctx, text: _displayValue, area, align: 'right' }) + } + + /** + * Handles the click event for the widget + * @param options The options for handling the click event + */ + abstract onClick(options: WidgetEventOptions): void + + /** + * Handles the drag event for the widget + * @param options The options for handling the drag event + */ + onDrag?(options: WidgetEventOptions): void + + /** + * Sets the value of the widget + * @param value The value to set + * @param options The options for setting the value + */ + setValue( + value: TWidget['value'], + { e, node, canvas }: WidgetEventOptions + ): void { + const oldValue = this.value + if (value === this.value) return + + const v = this.type === 'number' ? Number(value) : value + this.value = v + if ( + this.options?.property && + node.properties[this.options.property] !== undefined + ) { + node.setProperty(this.options.property, v) + } + const pos = canvas.graph_mouse + this.callback?.(this.value, canvas, node, pos, e) + + node.onWidgetChanged?.(this.name ?? '', v, oldValue, this) + if (node.graph) node.graph._version++ + } + + /** + * Clones the widget. + * @param node The node that will own the cloned widget. + * @returns A new widget with the same properties as the original + * @remarks Subclasses with custom constructors must override this method. + * + * Correctly and safely typing this is currently not possible (practical?) in TypeScript 5.8. + */ + createCopyForNode(node: LGraphNode): this { + // @ts-expect-error - Constructor type casting for widget cloning + const cloned: this = new (this.constructor as typeof this)(this, node) + cloned.value = this.value + return cloned + } +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__LegacyWidget.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__LegacyWidget.ts new file mode 100644 index 00000000..1c48bb32 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__LegacyWidget.ts @@ -0,0 +1,40 @@ +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import { LiteGraph } from '@/lib/litegraph/src/litegraph' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' + +import { BaseWidget } from './BaseWidget' +import type { DrawWidgetOptions } from './BaseWidget' + +/** + * Wraps a legacy POJO custom widget, so that all widgets may be called via the same internal interface. + * + * Support will eventually be removed. + * @remarks Expect this class to undergo breaking changes without warning. + */ +export class LegacyWidget + extends BaseWidget + implements IBaseWidget +{ + override draw?( + ctx: CanvasRenderingContext2D, + node: LGraphNode, + widget_width: number, + y: number, + H: number, + lowQuality?: boolean + ): void + + override drawWidget( + ctx: CanvasRenderingContext2D, + options: DrawWidgetOptions + ) { + const H = LiteGraph.NODE_WIDGET_HEIGHT + this.draw?.(ctx, this.node, options.width, this.y, H, !!options.showText) + } + + override onClick() { + console.warn( + 'Custom widget wrapper onClick was just called. Handling for third party widgets is done via LGraphCanvas - the mouse callback.' + ) + } +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useBooleanWidget.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useBooleanWidget.ts new file mode 100644 index 00000000..242afe54 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useBooleanWidget.ts @@ -0,0 +1,31 @@ +import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { isBooleanInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' +import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' +import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets' + +export const useBooleanWidget = () => { + const widgetConstructor: ComfyWidgetConstructorV2 = ( + node: LGraphNode, + inputSpec: InputSpec + ) => { + if (!isBooleanInputSpec(inputSpec)) { + throw new Error(`Invalid input data: ${inputSpec}`) + } + + const defaultVal = inputSpec.default ?? false + const options = { + on: inputSpec.label_on, + off: inputSpec.label_off + } + + return node.addWidget( + 'toggle', + inputSpec.name, + defaultVal, + () => {}, + options + ) + } + + return widgetConstructor +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useStringWidget.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useStringWidget.ts new file mode 100644 index 00000000..1ace7e9e --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useStringWidget.ts @@ -0,0 +1,137 @@ +import type { LGraphNode } from '@/lib/litegraph/src/litegraph' +import { useSettingStore } from '@/platform/settings/settingStore' +import { isStringInputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' +import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' +import { app } from '@/scripts/app' +import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets' + +const TRACKPAD_DETECTION_THRESHOLD = 50 + +function addMultilineWidget( + node: LGraphNode, + name: string, + opts: { defaultVal: string; placeholder?: string } +) { + const inputEl = document.createElement('textarea') + inputEl.className = 'comfy-multiline-input' + inputEl.value = opts.defaultVal + inputEl.placeholder = opts.placeholder || name + inputEl.spellcheck = useSettingStore().get('Comfy.TextareaWidget.Spellcheck') + + const widget = node.addDOMWidget(name, 'customtext', inputEl, { + getValue(): string { + return inputEl.value + }, + setValue(v: string) { + inputEl.value = v + } + }) + + widget.inputEl = inputEl + widget.options.minNodeSize = [400, 200] + + inputEl.addEventListener('input', () => { + widget.callback?.(widget.value) + }) + + // Allow middle mouse button panning + inputEl.addEventListener('pointerdown', (event: PointerEvent) => { + if (event.button === 1) { + app.canvas.processMouseDown(event) + } + }) + + inputEl.addEventListener('pointermove', (event: PointerEvent) => { + if ((event.buttons & 4) === 4) { + app.canvas.processMouseMove(event) + } + }) + + inputEl.addEventListener('pointerup', (event: PointerEvent) => { + if (event.button === 1) { + app.canvas.processMouseUp(event) + } + }) + + inputEl.addEventListener('wheel', (event: WheelEvent) => { + const gesturesEnabled = useSettingStore().get( + 'LiteGraph.Pointer.TrackpadGestures' + ) + const deltaX = event.deltaX + const deltaY = event.deltaY + + const canScrollY = inputEl.scrollHeight > inputEl.clientHeight + const isHorizontal = Math.abs(deltaX) > Math.abs(deltaY) + + // Prevent pinch zoom from zooming the page + if (event.ctrlKey) { + event.preventDefault() + event.stopPropagation() + app.canvas.processMouseWheel(event) + return + } + + // Detect if this is likely a trackpad gesture vs mouse wheel + // Trackpads usually have deltaX or smaller deltaY values (< TRACKPAD_DETECTION_THRESHOLD) + // Mouse wheels typically have larger discrete deltaY values (>= TRACKPAD_DETECTION_THRESHOLD) + const isLikelyTrackpad = + Math.abs(deltaX) > 0 || Math.abs(deltaY) < TRACKPAD_DETECTION_THRESHOLD + + // Trackpad gestures: when enabled, trackpad panning goes to canvas + if (gesturesEnabled && isLikelyTrackpad) { + event.preventDefault() + event.stopPropagation() + app.canvas.processMouseWheel(event) + return + } + + // When gestures disabled: horizontal always goes to canvas (no horizontal scroll in textarea) + if (isHorizontal) { + event.preventDefault() + event.stopPropagation() + app.canvas.processMouseWheel(event) + return + } + + // Vertical scrolling when gestures disabled: let textarea scroll if scrollable + if (canScrollY) { + event.stopPropagation() + return + } + + // If textarea can't scroll vertically, pass to canvas + event.preventDefault() + app.canvas.processMouseWheel(event) + }) + + return widget +} + +export const useStringWidget = () => { + const widgetConstructor: ComfyWidgetConstructorV2 = ( + node: LGraphNode, + inputSpec: InputSpec + ) => { + if (!isStringInputSpec(inputSpec)) { + throw new Error(`Invalid input data: ${inputSpec}`) + } + + const defaultVal = inputSpec.default ?? '' + const multiline = inputSpec.multiline + + const widget = multiline + ? addMultilineWidget(node, inputSpec.name, { + defaultVal, + placeholder: inputSpec.placeholder + }) + : node.addWidget('text', inputSpec.name, defaultVal, () => {}, {}) + + if (typeof inputSpec.dynamicPrompts === 'boolean') { + widget.dynamicPrompts = inputSpec.dynamicPrompts + } + + return widget + } + + return widgetConstructor +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__app.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__app.ts new file mode 100644 index 00000000..edcc6451 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__app.ts @@ -0,0 +1,1744 @@ +import { useEventListener, useResizeObserver } from '@vueuse/core' +import _ from 'es-toolkit/compat' +import type { ToastMessageOptions } from 'primevue/toast' +import { reactive, unref } from 'vue' +import { shallowRef } from 'vue' + +import { useCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion' +import { registerProxyWidgets } from '@/core/graph/subgraph/proxyWidget' +import { st, t } from '@/i18n' +import type { IContextMenuValue } from '@/lib/litegraph/src/interfaces' +import { + LGraph, + LGraphCanvas, + LGraphNode, + LiteGraph +} from '@/lib/litegraph/src/litegraph' +import type { Vector2 } from '@/lib/litegraph/src/litegraph' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' +import { isCloud } from '@/platform/distribution/types' +import { useSettingStore } from '@/platform/settings/settingStore' +import { useTelemetry } from '@/platform/telemetry' +import type { WorkflowOpenSource } from '@/platform/telemetry/types' +import { useToastStore } from '@/platform/updates/common/toastStore' +import { useWorkflowService } from '@/platform/workflow/core/services/workflowService' +import { ComfyWorkflow } from '@/platform/workflow/management/stores/workflowStore' +import { useWorkflowValidation } from '@/platform/workflow/validation/composables/useWorkflowValidation' +import { + type ComfyApiWorkflow, + type ComfyWorkflowJSON, + type ModelFile, + type NodeId, + isSubgraphDefinition +} from '@/platform/workflow/validation/schemas/workflowSchema' +import type { + ExecutionErrorWsMessage, + NodeError, + NodeExecutionOutput, + ResultItem +} from '@/schemas/apiSchema' +import { + type ComfyNodeDef as ComfyNodeDefV1, + isComboInputSpecV1, + isComboInputSpecV2 +} from '@/schemas/nodeDefSchema' +import { + type BaseDOMWidget, + ComponentWidgetImpl, + DOMWidgetImpl +} from '@/scripts/domWidget' +import { useDialogService } from '@/services/dialogService' +import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription' +import { useExtensionService } from '@/services/extensionService' +import { useLitegraphService } from '@/services/litegraphService' +import { useSubgraphService } from '@/services/subgraphService' +import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore' +import { useCommandStore } from '@/stores/commandStore' +import { useDomWidgetStore } from '@/stores/domWidgetStore' +import { useExecutionStore } from '@/stores/executionStore' +import { useExtensionStore } from '@/stores/extensionStore' +import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' +import { useNodeOutputStore } from '@/stores/imagePreviewStore' +import { KeyComboImpl, useKeybindingStore } from '@/stores/keybindingStore' +import { useModelStore } from '@/stores/modelStore' +import { SYSTEM_NODE_DEFS, useNodeDefStore } from '@/stores/nodeDefStore' +import { useSubgraphStore } from '@/stores/subgraphStore' +import { useWidgetStore } from '@/stores/widgetStore' +import { useWorkspaceStore } from '@/stores/workspaceStore' +import type { ComfyExtension, MissingNodeType } from '@/types/comfy' +import { type ExtensionManager } from '@/types/extensionTypes' +import type { NodeExecutionId } from '@/types/nodeIdentification' +import { graphToPrompt } from '@/utils/executionUtil' +import { anyItemOverlapsRect } from '@/utils/mathUtil' +import { collectAllNodes, forEachNode } from '@/utils/graphTraversalUtil' +import { + getNodeByExecutionId, + triggerCallbackOnAllNodes +} from '@/utils/graphTraversalUtil' +import { + executeWidgetsCallback, + fixLinkInputSlots, + isImageNode +} from '@/utils/litegraphUtil' +import { + findLegacyRerouteNodes, + noNativeReroutes +} from '@/utils/migration/migrateReroute' +import { getSelectedModelsMetadata } from '@/workbench/utils/modelMetadataUtil' +import { deserialiseAndCreate } from '@/utils/vintageClipboard' + +import { type ComfyApi, PromptExecutionError, api } from './api' +import { defaultGraph } from './defaultGraph' +import { importA1111 } from './pnginfo' +import { $el, ComfyUI } from './ui' +import { ComfyAppMenu } from './ui/menu/index' +import { clone } from './utils' +import { type ComfyWidgetConstructor } from './widgets' +import { ensureCorrectLayoutScale } from '@/renderer/extensions/vueNodes/layout/ensureCorrectLayoutScale' +import { extractFileFromDragEvent } from '@/utils/eventUtils' +import { getWorkflowDataFromFile } from '@/scripts/metadata/parser' +import { pasteImageNode } from '@/composables/usePaste' + +export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview' + +function sanitizeNodeName(string: string) { + let entityMap = { + '&': '', + '<': '', + '>': '', + '"': '', + "'": '', + '`': '', + '=': '' + } + return String(string).replace(/[&<>"'`=]/g, function fromEntityMap(s) { + return entityMap[s as keyof typeof entityMap] + }) +} + +type Clipspace = { + widgets?: Pick[] | null + imgs?: HTMLImageElement[] | null + original_imgs?: HTMLImageElement[] | null + images?: any[] | null + selectedIndex: number + img_paste_mode: string + paintedIndex: number + combinedIndex: number +} + +export class ComfyApp { + /** + * List of entries to queue + */ + private queueItems: { + number: number + batchCount: number + queueNodeIds?: NodeExecutionId[] + }[] = [] + /** + * If the queue is currently being processed + */ + private processingQueue: boolean = false + + /** + * Content Clipboard + * @type {serialized node object} + */ + static clipspace: Clipspace | null = null + static clipspace_invalidate_handler: (() => void) | null = null + static open_maskeditor: (() => void) | null = null + static maskeditor_is_opended: (() => void) | null = null + static clipspace_return_node = null + + vueAppReady: boolean + api: ComfyApi + ui: ComfyUI + extensionManager!: ExtensionManager + private _nodeOutputs!: Record + nodePreviewImages: Record + + private rootGraphInternal: LGraph | undefined + + // TODO: Migrate internal usage to the + /** @deprecated Use {@link rootGraph} instead */ + get graph(): unknown { + return this.rootGraphInternal! + } + + get rootGraph(): LGraph { + if (!this.rootGraphInternal) { + console.error('ComfyApp graph accessed before initialization') + } + return this.rootGraphInternal! + } + + canvas!: LGraphCanvas + dragOverNode: LGraphNode | null = null + readonly canvasElRef = shallowRef() + get canvasEl() { + // TODO: Fix possibly undefined reference + return unref(this.canvasElRef)! + } + + private configuringGraphLevel: number = 0 + get configuringGraph() { + return this.configuringGraphLevel > 0 + } + ctx!: CanvasRenderingContext2D + bodyTop: HTMLElement + bodyLeft: HTMLElement + bodyRight: HTMLElement + bodyBottom: HTMLElement + canvasContainer: HTMLElement + menu: ComfyAppMenu + // Set by Comfy.Clipspace extension + openClipspace: () => void = () => {} + + private positionConversion?: { + clientPosToCanvasPos: (pos: Vector2) => Vector2 + canvasPosToClientPos: (pos: Vector2) => Vector2 + } + + /** + * The node errors from the previous execution. + * @deprecated Use useExecutionStore().lastNodeErrors instead + */ + get lastNodeErrors(): Record | null { + return useExecutionStore().lastNodeErrors + } + + /** + * The error from the previous execution. + * @deprecated Use useExecutionStore().lastExecutionError instead + */ + get lastExecutionError(): ExecutionErrorWsMessage | null { + return useExecutionStore().lastExecutionError + } + + /** + * @deprecated Use useExecutionStore().executingNodeId instead + * TODO: Update to support multiple executing nodes. This getter returns only the first executing node. + * Consider updating consumers to handle multiple nodes or use executingNodeIds array. + */ + get runningNodeId(): NodeId | null { + return useExecutionStore().executingNodeId + } + + /** + * @deprecated Use useWorkspaceStore().shiftDown instead + */ + get shiftDown(): boolean { + return useWorkspaceStore().shiftDown + } + + /** + * @deprecated Use useWidgetStore().widgets instead + */ + get widgets(): Record { + return Object.fromEntries(useWidgetStore().widgets.entries()) + } + + /** + * @deprecated storageLocation is always 'server' since + * https://github.com/comfyanonymous/ComfyUI/commit/53c8a99e6c00b5e20425100f6680cd9ea2652218 + */ + get storageLocation() { + return 'server' + } + + /** + * @deprecated storage migration is no longer needed. + */ + get isNewUserSession() { + return false + } + + /** + * @deprecated Use useExtensionStore().extensions instead + */ + get extensions(): ComfyExtension[] { + return useExtensionStore().extensions + } + + /** + * The progress on the current executing node, if the node reports any. + * @deprecated Use useExecutionStore().executingNodeProgress instead + */ + get progress() { + return useExecutionStore()._executingNodeProgress + } + + /** + * @deprecated Use {@link isImageNode} from @/utils/litegraphUtil instead + */ + static isImageNode(node: LGraphNode) { + return isImageNode(node) + } + + /** + * Resets the canvas view to the default + * @deprecated Use {@link useLitegraphService().resetView} instead + */ + resetView() { + useLitegraphService().resetView() + } + + constructor() { + this.vueAppReady = false + this.ui = new ComfyUI(this) + this.api = api + // Dummy placeholder elements before GraphCanvas is mounted. + this.bodyTop = $el('div.comfyui-body-top') + this.bodyLeft = $el('div.comfyui-body-left') + this.bodyRight = $el('div.comfyui-body-right') + this.bodyBottom = $el('div.comfyui-body-bottom') + this.canvasContainer = $el('div.graph-canvas-container') + + this.menu = new ComfyAppMenu(this) + + /** + * Stores the execution output data for each node + * @type {Record} + */ + this.nodeOutputs = {} + + /** + * Stores the preview image data for each node + * @type {Record} + */ + this.nodePreviewImages = {} + } + + get nodeOutputs() { + return this._nodeOutputs + } + + set nodeOutputs(value) { + this._nodeOutputs = value + if (this.vueAppReady) + useExtensionService().invokeExtensions('onNodeOutputsUpdated', value) + } + + /** + * If the user has specified a preferred format to receive preview images in, + * this function will return that format as a url query param. + * If the node's outputs are not images, this param should not be used, as it will + * force the server to load the output file as an image. + */ + getPreviewFormatParam() { + let preview_format = useSettingStore().get('Comfy.PreviewFormat') + if (preview_format) return `&preview=${preview_format}` + else return '' + } + + getRandParam() { + if (isCloud) return '' + return '&rand=' + Math.random() + } + + static onClipspaceEditorSave() { + if (ComfyApp.clipspace_return_node) { + ComfyApp.pasteFromClipspace(ComfyApp.clipspace_return_node) + } + } + + static onClipspaceEditorClosed() { + ComfyApp.clipspace_return_node = null + } + + static copyToClipspace(node: LGraphNode) { + var widgets = null + if (node.widgets) { + widgets = node.widgets.map(({ type, name, value }) => ({ + type, + name, + value + })) + } + + var imgs = undefined + var orig_imgs = undefined + if (node.imgs != undefined) { + imgs = [] + orig_imgs = [] + + for (let i = 0; i < node.imgs.length; i++) { + imgs[i] = new Image() + imgs[i].src = node.imgs[i].src + orig_imgs[i] = imgs[i] + } + } + + var selectedIndex = 0 + if (node.imageIndex) { + selectedIndex = node.imageIndex + } + + const paintedIndex = imgs ? imgs.length + 1 : 1 + const combinedIndex = imgs ? imgs.length + 2 : 2 + + // for vueNodes mode + const images = + node.images ?? useNodeOutputStore().getNodeOutputs(node)?.images + + ComfyApp.clipspace = { + widgets: widgets, + imgs: imgs, + original_imgs: orig_imgs, + images: images, + selectedIndex: selectedIndex, + img_paste_mode: 'selected', // reset to default im_paste_mode state on copy action + paintedIndex: paintedIndex, + combinedIndex: combinedIndex + } + + ComfyApp.clipspace_return_node = null + + if (ComfyApp.clipspace_invalidate_handler) { + ComfyApp.clipspace_invalidate_handler() + } + } + + static pasteFromClipspace(node: LGraphNode) { + if (ComfyApp.clipspace) { + // image paste + let combinedImgSrc: string | undefined + if ( + ComfyApp.clipspace.combinedIndex !== undefined && + ComfyApp.clipspace.imgs && + ComfyApp.clipspace.combinedIndex < ComfyApp.clipspace.imgs.length + ) { + combinedImgSrc = + ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src + } + if (ComfyApp.clipspace.imgs && node.imgs) { + // Update node.images even if it's initially undefined (vueNodes mode) + if (ComfyApp.clipspace.images) { + if (ComfyApp.clipspace['img_paste_mode'] == 'selected') { + node.images = [ + ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']] + ] + } else { + node.images = ComfyApp.clipspace.images + } + + if (app.nodeOutputs[node.id + '']) + app.nodeOutputs[node.id + ''].images = node.images + } + + if (ComfyApp.clipspace.imgs) { + // deep-copy to cut link with clipspace + if (ComfyApp.clipspace['img_paste_mode'] == 'selected') { + const img = new Image() + img.src = + ComfyApp.clipspace.imgs[ComfyApp.clipspace['selectedIndex']].src + node.imgs = [img] + node.imageIndex = 0 + } else { + const imgs = [] + for (let i = 0; i < ComfyApp.clipspace.imgs.length; i++) { + imgs[i] = new Image() + imgs[i].src = ComfyApp.clipspace.imgs[i].src + node.imgs = imgs + } + } + } + } + + // Paste the RGB canvas if paintedindex exists + if ( + ComfyApp.clipspace.imgs?.[ComfyApp.clipspace.paintedIndex] && + node.imgs + ) { + const paintedImg = new Image() + paintedImg.src = + ComfyApp.clipspace.imgs[ComfyApp.clipspace.paintedIndex].src + node.imgs.push(paintedImg) // Add the RGB canvas to the node's images + } + + // Store only combined image inside the node if it exists + if ( + ComfyApp.clipspace.imgs?.[ComfyApp.clipspace.combinedIndex] && + node.imgs && + combinedImgSrc + ) { + const combinedImg = new Image() + combinedImg.src = combinedImgSrc + node.imgs = [combinedImg] + } + + if (node.widgets) { + if (ComfyApp.clipspace.images) { + const clip_image = + ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']] + const index = node.widgets.findIndex((obj) => obj.name === 'image') + if (index >= 0) { + if ( + node.widgets[index].type != 'image' && + typeof node.widgets[index].value == 'string' && + clip_image.filename + ) { + node.widgets[index].value = + (clip_image.subfolder ? clip_image.subfolder + '/' : '') + + clip_image.filename + + (clip_image.type ? ` [${clip_image.type}]` : '') + } else { + node.widgets[index].value = clip_image + } + } + } + if (ComfyApp.clipspace.widgets && node.widgets) { + ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => { + const prop = node.widgets?.find( + (obj) => obj.type === type && obj.name === name + ) + if (prop && prop.type != 'button') { + const valueObj = value as Record | undefined + if ( + prop.type != 'image' && + typeof prop.value == 'string' && + valueObj?.filename + ) { + const resultItem = value as ResultItem + prop.value = + (resultItem.subfolder ? resultItem.subfolder + '/' : '') + + resultItem.filename + + (resultItem.type ? ` [${resultItem.type}]` : '') + } else { + prop.value = value + prop.callback?.(value) + } + } + }) + } + } + + app.canvas.setDirty(true) + + useNodeOutputStore().updateNodeImages(node) + } + } + + /** + * Adds a handler allowing drag+drop of files onto the window to load workflows + */ + private addDropHandler() { + // Get prompt from dropped PNG or json + useEventListener(document, 'drop', async (event: DragEvent) => { + try { + event.preventDefault() + event.stopPropagation() + + const n = this.dragOverNode + this.dragOverNode = null + // Node handles file drop, we dont use the built in onDropFile handler as its buggy + // If you drag multiple files it will call it multiple times with the same file + if (await n?.onDragDrop?.(event)) return + + const fileMaybe = await extractFileFromDragEvent(event) + if (!fileMaybe) return + + const workspace = useWorkspaceStore() + try { + workspace.spinner = true + await this.handleFile(fileMaybe, 'file_drop') + } finally { + workspace.spinner = false + } + } catch (error: unknown) { + useToastStore().addAlert(t('toastMessages.dropFileError', { error })) + } + }) + + // Always clear over node on drag leave + useEventListener(this.canvasElRef, 'dragleave', async () => { + if (!this.dragOverNode) return + this.dragOverNode = null + this.canvas.setDirty(false, true) + }) + + // Add handler for dropping onto a specific node + useEventListener( + this.canvasElRef, + 'dragover', + (event: DragEvent) => { + this.canvas.adjustMouseEvent(event) + const node = this.canvas.graph?.getNodeOnPos( + event.canvasX, + event.canvasY + ) + + if (!node?.onDragOver?.(event)) { + this.dragOverNode = null + return + } + + this.dragOverNode = node + + // dragover event is fired very frequently, run this on an animation frame + requestAnimationFrame(() => { + this.canvas.setDirty(false, true) + }) + }, + false + ) + } + + /** + * Handle keypress + */ + private addProcessKeyHandler() { + const origProcessKey = LGraphCanvas.prototype.processKey + LGraphCanvas.prototype.processKey = function (e: KeyboardEvent) { + if (!this.graph) return + + if (e.target instanceof Element && e.target.localName == 'input') { + return + } + + if (e.type == 'keydown' && !e.repeat) { + const keyCombo = KeyComboImpl.fromEvent(e) + const keybindingStore = useKeybindingStore() + const keybinding = keybindingStore.getKeybinding(keyCombo) + + if ( + keybinding && + keybinding.targetElementId === 'graph-canvas-container' + ) { + useCommandStore().execute(keybinding.commandId) + + this.graph.change() + e.preventDefault() + e.stopImmediatePropagation() + return + } + + // Ctrl+C Copy + if (e.key === 'c' && (e.metaKey || e.ctrlKey)) { + return + } + + // Ctrl+V Paste + if ( + (e.key === 'v' || e.key == 'V') && + (e.metaKey || e.ctrlKey) && + !e.shiftKey + ) { + return + } + } + + // Fall through to Litegraph defaults + return origProcessKey.apply(this, [e]) + } + } + + /** + * Handles updates from the API socket + */ + private addApiUpdateHandlers() { + api.addEventListener('status', ({ detail }) => { + this.ui.setStatus(detail) + }) + + api.addEventListener('progress', () => { + this.canvas.setDirty(true, false) + }) + + api.addEventListener('executing', () => { + this.canvas.setDirty(true, false) + }) + + api.addEventListener('executed', ({ detail }) => { + const nodeOutputStore = useNodeOutputStore() + const executionId = String(detail.display_node || detail.node) + + nodeOutputStore.setNodeOutputsByExecutionId(executionId, detail.output, { + merge: detail.merge + }) + + const node = getNodeByExecutionId(this.rootGraph, executionId) + if (node && node.onExecuted) { + node.onExecuted(detail.output) + } + }) + + api.addEventListener('execution_start', () => { + triggerCallbackOnAllNodes(this.rootGraph, 'onExecutionStart') + }) + + api.addEventListener('execution_error', ({ detail }) => { + // Check if this is an auth-related error or credits-related error + if ( + detail.exception_message?.includes( + 'Unauthorized: Please login first to use this node.' + ) + ) { + useDialogService().showApiNodesSignInDialog([detail.node_type]) + } else if ( + detail.exception_message?.includes( + 'Payment Required: Please add credits to your account to use this node.' + ) + ) { + const { isActiveSubscription } = useSubscription() + if (isActiveSubscription.value) { + useDialogService().showTopUpCreditsDialog({ + isInsufficientCredits: true + }) + } + } else { + useDialogService().showExecutionErrorDialog(detail) + } + this.canvas.draw(true, true) + }) + + api.addEventListener('b_preview_with_metadata', ({ detail }) => { + // Enhanced preview with explicit node context + const { blob, displayNodeId } = detail + const { setNodePreviewsByExecutionId, revokePreviewsByExecutionId } = + useNodeOutputStore() + // Ensure clean up if `executing` event is missed. + revokePreviewsByExecutionId(displayNodeId) + const blobUrl = URL.createObjectURL(blob) + // Preview cleanup is handled in progress_state event to support multiple concurrent previews + const nodeParents = displayNodeId.split(':') + for (let i = 1; i <= nodeParents.length; i++) { + setNodePreviewsByExecutionId(nodeParents.slice(0, i).join(':'), [ + blobUrl + ]) + } + }) + + api.init() + } + + /** Flag that the graph is configuring to prevent nodes from running checks while its still loading */ + private addConfigureHandler() { + const app = this + const configure = LGraph.prototype.configure + LGraph.prototype.configure = function (...args) { + app.configuringGraphLevel++ + try { + return configure.apply(this, args) + } finally { + app.configuringGraphLevel-- + } + } + } + + private addAfterConfigureHandler(graph: LGraph) { + const { onConfigure } = graph + graph.onConfigure = function (...args) { + fixLinkInputSlots(this) + + // Fire callbacks before the onConfigure, this is used by widget inputs to setup the config + triggerCallbackOnAllNodes(this, 'onGraphConfigured') + + const r = onConfigure?.apply(this, args) + + // Fire after onConfigure, used by primitives to generate widget using input nodes config + triggerCallbackOnAllNodes(this, 'onAfterGraphConfigured') + + return r + } + } + + /** + * Set up the app on the page + */ + async setup(canvasEl: HTMLCanvasElement) { + this.bodyTop = document.getElementById('comfyui-body-top')! + this.bodyLeft = document.getElementById('comfyui-body-left')! + this.bodyRight = document.getElementById('comfyui-body-right')! + this.bodyBottom = document.getElementById('comfyui-body-bottom')! + this.canvasContainer = document.getElementById('graph-canvas-container')! + + this.canvasElRef.value = canvasEl + + await useWorkspaceStore().workflow.syncWorkflows() + //Doesn't need to block. Blueprints will load async + void useSubgraphStore().fetchSubgraphs() + await useExtensionService().loadExtensions() + + this.addProcessKeyHandler() + this.addConfigureHandler() + this.addApiUpdateHandlers() + + const graph = new LGraph() + + // Register the subgraph - adds type wrapper for Litegraph's `createNode` factory + graph.events.addEventListener('subgraph-created', (e) => { + try { + const { subgraph, data } = e.detail + useSubgraphService().registerNewSubgraph(subgraph, data) + } catch (err) { + console.error('Failed to register subgraph', err) + useToastStore().add({ + severity: 'error', + summary: 'Failed to register subgraph', + detail: err instanceof Error ? err.message : String(err) + }) + } + }) + + this.addAfterConfigureHandler(graph) + + this.rootGraphInternal = graph + this.canvas = new LGraphCanvas(canvasEl, graph) + // Make canvas states reactive so we can observe changes on them. + this.canvas.state = reactive(this.canvas.state) + + this.ctx = canvasEl.getContext('2d')! + + LiteGraph.alt_drag_do_clone_nodes = true + LiteGraph.macGesturesRequireMac = false + + this.canvas.canvas.addEventListener<'litegraph:set-graph'>( + 'litegraph:set-graph', + (e) => { + const { newGraph } = e.detail + + const widgetStore = useDomWidgetStore() + + const activeWidgets: Record< + string, + BaseDOMWidget + > = Object.fromEntries( + newGraph.nodes + .flatMap((node) => node.widgets ?? []) + .filter( + (w) => + w instanceof DOMWidgetImpl || w instanceof ComponentWidgetImpl + ) + .map((w) => [w.id, w]) + ) + + for (const [ + widgetId, + widgetState + ] of widgetStore.widgetStates.entries()) { + if (widgetId in activeWidgets) { + widgetState.active = true + widgetState.widget = activeWidgets[widgetId] + } else { + widgetState.active = false + } + } + } + ) + + // Ensure subgraphs are scaled when entering them + this.canvas.canvas.addEventListener<'litegraph:set-graph'>( + 'litegraph:set-graph', + (e) => { + const { newGraph, oldGraph } = e.detail + // Only scale when switching between graphs (not during initial setup) + // oldGraph is null/undefined during initial setup, so skip scaling then + if (oldGraph) { + ensureCorrectLayoutScale( + newGraph.extra.workflowRendererVersion, + newGraph + ) + } + } + ) + + registerProxyWidgets(this.canvas) + + this.rootGraph.start() + + // Ensure the canvas fills the window + useResizeObserver(this.canvasElRef, ([canvasEl]) => { + if (canvasEl.target instanceof HTMLCanvasElement) { + this.resizeCanvas(canvasEl.target) + } + }) + + await useExtensionService().invokeExtensionsAsync('init') + await this.registerNodes() + + this.addDropHandler() + + await useExtensionService().invokeExtensionsAsync('setup') + + this.positionConversion = useCanvasPositionConversion( + this.canvasContainer, + this.canvas + ) + } + + private resizeCanvas(canvas: HTMLCanvasElement) { + // Limit minimal scale to 1, see https://github.com/comfyanonymous/ComfyUI/pull/845 + const scale = Math.max(window.devicePixelRatio, 1) + + // Clear fixed width and height while calculating rect so it uses 100% instead + canvas.height = canvas.width = NaN + const { width, height } = canvas.getBoundingClientRect() + canvas.width = Math.round(width * scale) + canvas.height = Math.round(height * scale) + canvas.getContext('2d')?.scale(scale, scale) + this.canvas?.draw(true, true) + } + + private updateVueAppNodeDefs(defs: Record) { + // Frontend only nodes registered by custom nodes. + // Example: https://github.com/rgthree/rgthree-comfy/blob/dd534e5384be8cf0c0fa35865afe2126ba75ac55/src_web/comfyui/fast_groups_bypasser.ts#L10 + + // Only create frontend_only definitions for nodes that don't have backend definitions + const frontendOnlyDefs: Record = {} + for (const [name, node] of Object.entries( + LiteGraph.registered_node_types + )) { + // Skip if we already have a backend definition or system definition + if (name in defs || name in SYSTEM_NODE_DEFS || node.skip_list) { + continue + } + + frontendOnlyDefs[name] = { + name, + display_name: name, + category: node.category || '__frontend_only__', + input: { required: {}, optional: {} }, + output: [], + output_name: [], + output_is_list: [], + output_node: false, + python_module: 'custom_nodes.frontend_only', + description: node.description ?? `Frontend only node for ${name}` + } as ComfyNodeDefV1 + } + + const allNodeDefs = { + ...frontendOnlyDefs, + ...defs, + ...SYSTEM_NODE_DEFS + } + + const nodeDefStore = useNodeDefStore() + const nodeDefArray: ComfyNodeDefV1[] = Object.values(allNodeDefs) + useExtensionService().invokeExtensions( + 'beforeRegisterVueAppNodeDefs', + nodeDefArray, + this + ) + nodeDefStore.updateNodeDefs(nodeDefArray) + } + + async getNodeDefs(): Promise> { + const translateNodeDef = (def: ComfyNodeDefV1): ComfyNodeDefV1 => ({ + ...def, + display_name: st( + `nodeDefs.${def.name}.display_name`, + def.display_name ?? def.name + ), + description: def.description + ? st(`nodeDefs.${def.name}.description`, def.description) + : '', + category: def.category + .split('/') + .map((category: string) => st(`nodeCategories.${category}`, category)) + .join('/') + }) + + return _.mapValues(await api.getNodeDefs(), (def) => translateNodeDef(def)) + } + + /** + * Registers nodes with the graph + */ + async registerNodes() { + // Load node definitions from the backend + const defs = await this.getNodeDefs() + await this.registerNodesFromDefs(defs) + await useExtensionService().invokeExtensionsAsync('registerCustomNodes') + if (this.vueAppReady) { + this.updateVueAppNodeDefs(defs) + } + } + + async registerNodeDef(nodeId: string, nodeDef: ComfyNodeDefV1) { + return await useLitegraphService().registerNodeDef(nodeId, nodeDef) + } + + async registerNodesFromDefs(defs: Record) { + await useExtensionService().invokeExtensionsAsync('addCustomNodeDefs', defs) + + // Register a node for each definition + for (const nodeId in defs) { + this.registerNodeDef(nodeId, defs[nodeId]) + } + } + + loadTemplateData(templateData: { + templates?: { name?: string; data?: string }[] + }): void { + if (!templateData?.templates) { + return + } + + const old = localStorage.getItem('litegrapheditor_clipboard') + + for (const template of templateData.templates) { + if (!template?.data) { + continue + } + + // Check for old clipboard format + const data = JSON.parse(template.data) + if (!data.reroutes) { + deserialiseAndCreate(template.data, app.canvas) + } else { + localStorage.setItem('litegrapheditor_clipboard', template.data) + app.canvas.pasteFromClipboard() + } + + // Move mouse position down to paste the next template below + let maxY: number | undefined + + for (const i in app.canvas.selected_nodes) { + const node = app.canvas.selected_nodes[i] + const nodeBottom = node.pos[1] + node.size[1] + if (maxY === undefined || nodeBottom > maxY) { + maxY = nodeBottom + } + } + + if (maxY !== undefined) { + app.canvas.graph_mouse[1] = maxY + 50 + } + } + + if (old !== null) { + localStorage.setItem('litegrapheditor_clipboard', old) + } + } + + private showMissingNodesError(missingNodeTypes: MissingNodeType[]) { + if (useSettingStore().get('Comfy.Workflow.ShowMissingNodesWarning')) { + useDialogService().showLoadWorkflowWarning({ missingNodeTypes }) + } + } + + private showMissingModelsError( + missingModels: ModelFile[], + paths: Record + ): void { + if (useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning')) { + useDialogService().showMissingModelsWarning({ + missingModels, + paths + }) + } + } + + async loadGraphData( + graphData?: ComfyWorkflowJSON, + clean: boolean = true, + restore_view: boolean = true, + workflow: string | null | ComfyWorkflow = null, + options: { + showMissingNodesDialog?: boolean + showMissingModelsDialog?: boolean + checkForRerouteMigration?: boolean + openSource?: WorkflowOpenSource + } = {} + ) { + const { + showMissingNodesDialog = true, + showMissingModelsDialog = true, + checkForRerouteMigration = false, + openSource + } = options + useWorkflowService().beforeLoadNewGraph() + + if (clean !== false) { + this.clean() + } + + let reset_invalid_values = false + // Use explicit validation instead of falsy check to avoid replacing + // valid but falsy values (empty objects, 0, false, etc.) + if ( + !graphData || + typeof graphData !== 'object' || + Array.isArray(graphData) + ) { + graphData = defaultGraph + reset_invalid_values = true + } + + graphData = clone(graphData) + + if (useSettingStore().get('Comfy.Validation.Workflows')) { + const { graphData: validatedGraphData } = + await useWorkflowValidation().validateWorkflow(graphData) + + // If the validation failed, use the original graph data. + // Ideally we should not block users from loading the workflow. + graphData = validatedGraphData ?? graphData + } + // Only show the reroute migration warning if the workflow does not have native + // reroutes. Merging reroute network has great complexity, and it is not supported + // for now. + // See: https://github.com/Comfy-Org/ComfyUI_frontend/issues/3317 + if ( + checkForRerouteMigration && + graphData.version === 0.4 && + findLegacyRerouteNodes(graphData).length && + noNativeReroutes(graphData) + ) { + useToastStore().add({ + group: 'reroute-migration', + severity: 'warn' + }) + } + useSubgraphService().loadSubgraphs(graphData) + + const missingNodeTypes: MissingNodeType[] = [] + const missingModels: ModelFile[] = [] + await useExtensionService().invokeExtensionsAsync( + 'beforeConfigureGraph', + graphData, + missingNodeTypes + ) + + const embeddedModels: ModelFile[] = [] + + const collectMissingNodesAndModels = ( + nodes: ComfyWorkflowJSON['nodes'], + path: string = '' + ) => { + if (!Array.isArray(nodes)) { + console.warn( + 'Workflow nodes data is missing or invalid, skipping node processing', + { nodes, path } + ) + return + } + for (let n of nodes) { + // Patch T2IAdapterLoader to ControlNetLoader since they are the same node now + if (n.type == 'T2IAdapterLoader') n.type = 'ControlNetLoader' + if (n.type == 'ConditioningAverage ') n.type = 'ConditioningAverage' //typo fix + if (n.type == 'SDV_img2vid_Conditioning') + n.type = 'SVD_img2vid_Conditioning' //typo fix + if (n.type == 'Load3DAnimation') n.type = 'Load3D' // Animation node merged into Load3D + if (n.type == 'Preview3DAnimation') n.type = 'Preview3D' // Animation node merged into Load3D + + // Find missing node types + if (!(n.type in LiteGraph.registered_node_types)) { + // Include context about subgraph location if applicable + if (path) { + missingNodeTypes.push({ + type: n.type, + hint: `in subgraph '${path}'` + }) + } else { + missingNodeTypes.push(n.type) + } + n.type = sanitizeNodeName(n.type) + } + + // Collect models metadata from node + const selectedModels = getSelectedModelsMetadata(n) + if (selectedModels?.length) { + embeddedModels.push(...selectedModels) + } + } + } + + // Process nodes at the top level + collectMissingNodesAndModels(graphData.nodes) + + // Process nodes in subgraphs + if (graphData.definitions?.subgraphs) { + for (const subgraph of graphData.definitions.subgraphs) { + if (isSubgraphDefinition(subgraph)) { + collectMissingNodesAndModels( + subgraph.nodes, + subgraph.name || subgraph.id + ) + } + } + } + + // Merge models from the workflow's root-level 'models' field + const workflowSchemaV1Models = graphData.models + if (workflowSchemaV1Models?.length) + embeddedModels.push(...workflowSchemaV1Models) + + const getModelKey = (model: ModelFile) => model.url || model.hash + const validModels = embeddedModels.filter(getModelKey) + const uniqueModels = _.uniqBy(validModels, getModelKey) + + if ( + uniqueModels.length && + useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning') + ) { + const modelStore = useModelStore() + await modelStore.loadModelFolders() + for (const m of uniqueModels) { + const modelFolder = await modelStore.getLoadedModelFolder(m.directory) + if (!modelFolder) + (m as ModelFile & { directory_invalid?: boolean }).directory_invalid = + true + + const modelsAvailable = modelFolder?.models + const modelExists = + modelsAvailable && + Object.values(modelsAvailable).some( + (model) => model.file_name === m.name + ) + if (!modelExists) missingModels.push(m) + } + } + + try { + // @ts-expect-error Discrepancies between zod and litegraph - in progress + this.rootGraph.configure(graphData) + + // Save original renderer version before scaling (it gets modified during scaling) + const originalMainGraphRenderer = + this.rootGraph.extra.workflowRendererVersion + + // Scale main graph + ensureCorrectLayoutScale(originalMainGraphRenderer) + + // Scale all subgraphs that were loaded with the workflow + // Use original main graph renderer as fallback (not the modified one) + for (const subgraph of this.rootGraph.subgraphs.values()) { + ensureCorrectLayoutScale( + subgraph.extra.workflowRendererVersion || originalMainGraphRenderer, + subgraph + ) + } + + if ( + restore_view && + useSettingStore().get('Comfy.EnableWorkflowViewRestore') + ) { + if (graphData.extra?.ds) { + this.canvas.ds.offset = graphData.extra.ds.offset + this.canvas.ds.scale = graphData.extra.ds.scale + + // Fit view if no nodes visible in restored viewport + this.canvas.ds.computeVisibleArea(this.canvas.viewport) + if ( + !anyItemOverlapsRect( + this.rootGraph._nodes, + this.canvas.visible_area + ) + ) { + requestAnimationFrame(() => useLitegraphService().fitView()) + } + } else { + useLitegraphService().fitView() + } + } + } catch (error) { + useDialogService().showErrorDialog(error, { + title: t('errorDialog.loadWorkflowTitle'), + reportType: 'loadWorkflowError' + }) + console.error(error) + return + } + forEachNode(this.rootGraph, (node) => { + const size = node.computeSize() + size[0] = Math.max(node.size[0], size[0]) + size[1] = Math.max(node.size[1], size[1]) + node.setSize(size) + if (node.widgets) { + // If you break something in the backend and want to patch workflows in the frontend + // This is the place to do this + for (let widget of node.widgets) { + if (node.type == 'KSampler' || node.type == 'KSamplerAdvanced') { + if (widget.name == 'sampler_name') { + if ( + typeof widget.value === 'string' && + widget.value.startsWith('sample_') + ) { + widget.value = widget.value.slice(7) + } + } + } + if ( + node.type == 'KSampler' || + node.type == 'KSamplerAdvanced' || + node.type == 'PrimitiveNode' + ) { + if (widget.name == 'control_after_generate') { + if (widget.value === true) { + widget.value = 'randomize' + } else if (widget.value === false) { + widget.value = 'fixed' + } + } + } + if (reset_invalid_values) { + if (widget.type == 'combo') { + const values = widget.options.values as + | (string | number | boolean)[] + | undefined + if ( + values && + values.length > 0 && + !values.includes(widget.value as string | number | boolean) + ) { + widget.value = values[0] + } + } + } + } + } + + useExtensionService().invokeExtensions('loadedGraphNode', node) + }) + + if (missingNodeTypes.length && showMissingNodesDialog) { + this.showMissingNodesError(missingNodeTypes) + } + if (missingModels.length && showMissingModelsDialog) { + const paths = await api.getFolderPaths() + this.showMissingModelsError(missingModels, paths) + } + await useExtensionService().invokeExtensionsAsync( + 'afterConfigureGraph', + missingNodeTypes + ) + + const telemetryPayload = { + missing_node_count: missingNodeTypes.length, + missing_node_types: missingNodeTypes.map((node) => + typeof node === 'string' ? node : node.type + ), + open_source: openSource ?? 'unknown' + } + useTelemetry()?.trackWorkflowOpened(telemetryPayload) + useTelemetry()?.trackWorkflowImported(telemetryPayload) + await useWorkflowService().afterLoadNewGraph( + workflow, + this.rootGraph.serialize() as unknown as ComfyWorkflowJSON + ) + requestAnimationFrame(() => { + this.canvas.setDirty(true, true) + }) + } + + async graphToPrompt(graph = this.rootGraph) { + return graphToPrompt(graph, { + sortNodes: useSettingStore().get('Comfy.Workflow.SortNodeIdOnSave') + }) + } + + async queuePrompt( + number: number, + batchCount: number = 1, + queueNodeIds?: NodeExecutionId[] + ): Promise { + this.queueItems.push({ number, batchCount, queueNodeIds }) + + // Only have one action process the items so each one gets a unique seed correctly + if (this.processingQueue) { + return false + } + + this.processingQueue = true + const executionStore = useExecutionStore() + executionStore.lastNodeErrors = null + + let comfyOrgAuthToken = await useFirebaseAuthStore().getIdToken() + let comfyOrgApiKey = useApiKeyAuthStore().getApiKey() + + try { + while (this.queueItems.length) { + const { number, batchCount, queueNodeIds } = this.queueItems.pop()! + const previewMethod = useSettingStore().get( + 'Comfy.Execution.PreviewMethod' + ) + + for (let i = 0; i < batchCount; i++) { + // Allow widgets to run callbacks before a prompt has been queued + // e.g. random seed before every gen + forEachNode(this.rootGraph, (node) => { + for (const widget of node.widgets ?? []) widget.beforeQueued?.() + }) + + const p = await this.graphToPrompt(this.rootGraph) + const queuedNodes = collectAllNodes(this.rootGraph) + try { + api.authToken = comfyOrgAuthToken + api.apiKey = comfyOrgApiKey ?? undefined + const res = await api.queuePrompt(number, p, { + partialExecutionTargets: queueNodeIds, + previewMethod + }) + delete api.authToken + delete api.apiKey + executionStore.lastNodeErrors = res.node_errors ?? null + if (executionStore.lastNodeErrors?.length) { + this.canvas.draw(true, true) + } else { + try { + if (res.prompt_id) { + executionStore.storePrompt({ + id: res.prompt_id, + nodes: Object.keys(p.output), + workflow: useWorkspaceStore().workflow + .activeWorkflow as ComfyWorkflow + }) + } + } catch (error) {} + } + } catch (error: unknown) { + useDialogService().showErrorDialog(error, { + title: t('errorDialog.promptExecutionError'), + reportType: 'promptExecutionError' + }) + console.error(error) + + if (error instanceof PromptExecutionError) { + executionStore.lastNodeErrors = error.response.node_errors ?? null + this.canvas.draw(true, true) + } + break + } + + // Allow widgets to run callbacks after a prompt has been queued + // e.g. random seed after every gen + executeWidgetsCallback(queuedNodes, 'afterQueued') + this.canvas.draw(true, true) + await this.ui.queue.update() + } + } + } finally { + this.processingQueue = false + } + api.dispatchCustomEvent('promptQueued', { number, batchCount }) + return !executionStore.lastNodeErrors + } + + showErrorOnFileLoad(file: File) { + useToastStore().addAlert( + t('toastMessages.fileLoadError', { fileName: file.name }) + ) + } + + /** + * Loads workflow data from the specified file + * @param {File} file + */ + async handleFile(file: File, openSource?: WorkflowOpenSource) { + const fileName = file.name.replace(/\.\w+$/, '') // Strip file extension + const workflowData = await getWorkflowDataFromFile(file) + if (!workflowData) { + if (file.type.startsWith('image')) { + const transfer = new DataTransfer() + transfer.items.add(file) + pasteImageNode(this.canvas, transfer.items) + return + } + + this.showErrorOnFileLoad(file) + return + } + + const { workflow, prompt, parameters, templates } = workflowData + + if ( + templates && + typeof templates === 'object' && + Array.isArray(templates) + ) { + this.loadTemplateData({ + templates: templates as { name?: string; data?: string }[] + }) + } + + // Check workflow first - it should take priority over parameters + // when both are present (e.g., in ComfyUI-generated PNGs) + if (workflow) { + let workflowObj: ComfyWorkflowJSON | undefined = undefined + try { + workflowObj = + typeof workflow === 'string' ? JSON.parse(workflow) : workflow + + // Only load workflow if parsing succeeded AND validation passed + if ( + workflowObj && + typeof workflowObj === 'object' && + !Array.isArray(workflowObj) + ) { + await this.loadGraphData(workflowObj, true, true, fileName, { + openSource + }) + return + } else { + console.error( + 'Invalid workflow structure, trying parameters fallback' + ) + this.showErrorOnFileLoad(file) + } + } catch (err) { + console.error('Failed to parse workflow:', err) + this.showErrorOnFileLoad(file) + // Fall through to check parameters as fallback + } + } + + if (prompt) { + try { + const promptObj = + typeof prompt === 'string' ? JSON.parse(prompt) : prompt + if (this.isApiJson(promptObj)) { + this.loadApiJson(promptObj, fileName) + return + } + } catch (err) { + console.error('Failed to parse prompt:', err) + } + // Fall through to parameters as a last resort + } + + // Use parameters strictly as the final fallback + if (parameters && typeof parameters === 'string') { + useWorkflowService().beforeLoadNewGraph() + importA1111(this.rootGraph, parameters) + useWorkflowService().afterLoadNewGraph( + fileName, + this.rootGraph.serialize() as unknown as ComfyWorkflowJSON + ) + return + } + + this.showErrorOnFileLoad(file) + } + + // @deprecated + isApiJson(data: unknown): data is ComfyApiWorkflow { + if (!_.isObject(data) || Array.isArray(data)) { + return false + } + if (Object.keys(data).length === 0) return false + + return Object.values(data).every((node) => { + if (!node || typeof node !== 'object' || Array.isArray(node)) { + return false + } + + const { class_type: classType, inputs } = node as Record + const inputsIsRecord = _.isObject(inputs) && !Array.isArray(inputs) + return typeof classType === 'string' && inputsIsRecord + }) + } + + loadApiJson(apiData: ComfyApiWorkflow, fileName: string) { + useWorkflowService().beforeLoadNewGraph() + + const missingNodeTypes = Object.values(apiData).filter( + (n) => !LiteGraph.registered_node_types[n.class_type] + ) + if (missingNodeTypes.length) { + this.showMissingNodesError(missingNodeTypes.map((t) => t.class_type)) + return + } + + const ids = Object.keys(apiData) + app.rootGraph.clear() + for (const id of ids) { + const data = apiData[id] + const node = LiteGraph.createNode(data.class_type) + if (!node) continue + node.id = isNaN(+id) ? id : +id + node.title = data._meta?.title ?? node.title + app.rootGraph.add(node) + } + + const processNodeInputs = (id: string) => { + const data = apiData[id] + const node = app.rootGraph.getNodeById(id) + if (!node) return + + for (const input in data.inputs ?? {}) { + const value = data.inputs[input] + if (value instanceof Array) { + const [fromId, fromSlot] = value + const fromNode = app.rootGraph.getNodeById(fromId) + if (!fromNode) continue + + let toSlot = node.inputs?.findIndex((inp) => inp.name === input) ?? -1 + if (toSlot === -1) { + try { + const widget = node.widgets?.find((w) => w.name === input) + const convertFn = ( + node as LGraphNode & { + convertWidgetToInput?: (w: IBaseWidget) => boolean + } + ).convertWidgetToInput + if (widget && convertFn?.(widget)) { + // Re-find the target slot by name after conversion + toSlot = + node.inputs?.findIndex((inp) => inp.name === input) ?? -1 + } + } catch (_error) { + // Ignore conversion errors + } + } + if (toSlot !== -1) { + fromNode.connect(fromSlot, node, toSlot) + } + } else { + const widget = node.widgets?.find((w) => w.name === input) + if (widget) { + widget.value = value + widget.callback?.(value) + } + } + } + } + + for (const id of ids) processNodeInputs(id) + app.rootGraph.arrange() + for (const id of ids) processNodeInputs(id) + app.rootGraph.arrange() + + useWorkflowService().afterLoadNewGraph( + fileName, + this.rootGraph.serialize() as unknown as ComfyWorkflowJSON + ) + } + + /** + * Registers a Comfy web extension with the app + * @param {ComfyExtension} extension + */ + registerExtension(extension: ComfyExtension) { + useExtensionService().registerExtension(extension) + } + + /** + * Collects context menu items from all extensions for canvas menus + * @param canvas The canvas instance + * @returns Array of context menu items from all extensions + */ + collectCanvasMenuItems(canvas: LGraphCanvas): IContextMenuValue[] { + return useExtensionService() + .invokeExtensions('getCanvasMenuItems', canvas) + .flat() as IContextMenuValue[] + } + + /** + * Collects context menu items from all extensions for node menus + * @param node The node being right-clicked + * @returns Array of context menu items from all extensions + */ + collectNodeMenuItems(node: LGraphNode): IContextMenuValue[] { + return useExtensionService() + .invokeExtensions('getNodeMenuItems', node) + .flat() as IContextMenuValue[] + } + + /** + * Refresh combo list on whole nodes + */ + async refreshComboInNodes() { + const requestToastMessage: ToastMessageOptions = { + severity: 'info', + summary: t('g.update'), + detail: t('toastMessages.updateRequested') + } + if (this.vueAppReady) { + useToastStore().add(requestToastMessage) + } + + const defs = await this.getNodeDefs() + for (const nodeId in defs) { + this.registerNodeDef(nodeId, defs[nodeId]) + } + // Refresh combo widgets in all nodes including those in subgraphs + forEachNode(this.rootGraph, (node) => { + const def = defs[node.type] + // Allow primitive nodes to handle refresh + node.refreshComboInNode?.(defs) + + if (!def?.input) return + + if (node.widgets) { + const nodeInputs = def.input + for (const widget of node.widgets) { + if (widget.type === 'combo') { + let inputType: 'required' | 'optional' | undefined + if (nodeInputs.required?.[widget.name] !== undefined) { + inputType = 'required' + } else if (nodeInputs.optional?.[widget.name] !== undefined) { + inputType = 'optional' + } + if (inputType !== undefined) { + // Get the input spec associated with the widget + const inputSpec = nodeInputs[inputType]?.[widget.name] + if (inputSpec) { + // Refresh the combo widget's options with the values from the input spec + if (isComboInputSpecV2(inputSpec)) { + widget.options.values = inputSpec[1]?.options + } else if (isComboInputSpecV1(inputSpec)) { + widget.options.values = inputSpec[0] + } + } + } + } + } + } + }) + + await useExtensionService().invokeExtensionsAsync( + 'refreshComboInNodes', + defs + ) + + if (this.vueAppReady) { + this.updateVueAppNodeDefs(defs) + useToastStore().remove(requestToastMessage) + useToastStore().add({ + severity: 'success', + summary: t('g.updated'), + detail: t('toastMessages.nodeDefinitionsUpdated'), + life: 1000 + }) + } + } + + /** + * Clean current state + */ + clean() { + const nodeOutputStore = useNodeOutputStore() + nodeOutputStore.resetAllOutputsAndPreviews() + const executionStore = useExecutionStore() + executionStore.lastNodeErrors = null + executionStore.lastExecutionError = null + + useDomWidgetStore().clear() + + // Subgraph does not properly implement `clear` and the parent class's + // (`LGraph`) `clear` breaks the subgraph structure. + if (this.rootGraph && !this.canvas.subgraph) { + this.rootGraph.clear() + } + } + + clientPosToCanvasPos(pos: Vector2): Vector2 { + if (!this.positionConversion) { + throw new Error('clientPosToCanvasPos called before setup') + } + return this.positionConversion.clientPosToCanvasPos(pos) + } + + canvasPosToClientPos(pos: Vector2): Vector2 { + if (!this.positionConversion) { + throw new Error('canvasPosToClientPos called before setup') + } + return this.positionConversion.canvasPosToClientPos(pos) + } +} + +export const app = new ComfyApp() diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__domWidget.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__domWidget.ts new file mode 100644 index 00000000..a1b57496 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__domWidget.ts @@ -0,0 +1,394 @@ +import _ from 'es-toolkit/compat' +import { type Component, toRaw } from 'vue' + +import { useChainCallback } from '@/composables/functional/useChainCallback' +import { + LGraphNode, + LegacyWidget, + LiteGraph +} from '@/lib/litegraph/src/litegraph' +import type { + IBaseWidget, + IWidgetOptions +} from '@/lib/litegraph/src/types/widgets' +import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2' +import { useDomWidgetStore } from '@/stores/domWidgetStore' +import { generateUUID } from '@/utils/formatUtil' + +export interface BaseDOMWidget< + V extends object | string = object | string +> extends IBaseWidget> { + // ICustomWidget properties + type: string + options: DOMWidgetOptions + value: V + callback?: (value: V) => void + + // BaseDOMWidget properties + /** The unique ID of the widget. */ + readonly id: string + /** The node that the widget belongs to. */ + readonly node: LGraphNode + /** Whether the widget is visible. */ + isVisible(): boolean + /** The margin of the widget. */ + margin: number +} + +/** + * A DOM widget that wraps a custom HTML element as a litegraph widget. + */ +export interface DOMWidget< + T extends HTMLElement, + V extends object | string +> extends BaseDOMWidget { + element: T + /** + * @deprecated Legacy property used by some extensions for customtext + * (textarea) widgets. Use {@link element} instead as it provides the same + * functionality and works for all DOMWidget types. + */ + inputEl?: T +} + +/** + * Additional props that can be passed to component widgets. + * These are in addition to the standard props that are always provided: + * - modelValue: The widget's value (handled by v-model) + * - widget: Reference to the widget instance + * - onUpdate:modelValue: The update handler for v-model + */ +type ComponentWidgetCustomProps = Record + +/** + * Standard props that are handled separately by DomWidget.vue and should be + * omitted when defining custom props for component widgets + */ +export type ComponentWidgetStandardProps = + | 'modelValue' + | 'widget' + | 'onUpdate:modelValue' + +/** + * A DOM widget that wraps a Vue component as a litegraph widget. + */ +export interface ComponentWidget< + V extends object | string, + P extends ComponentWidgetCustomProps = ComponentWidgetCustomProps +> extends BaseDOMWidget { + readonly component: Component + readonly inputSpec: InputSpec + readonly props?: P +} + +export interface DOMWidgetOptions< + V extends object | string +> extends IWidgetOptions { + /** + * Whether to render a placeholder rectangle when zoomed out. + */ + hideOnZoom?: boolean + selectOn?: string[] + onHide?: (widget: BaseDOMWidget) => void + getValue?: () => V + setValue?: (value: V) => void + getMinHeight?: () => number + getMaxHeight?: () => number + getHeight?: () => string | number + onDraw?: (widget: BaseDOMWidget) => void + margin?: number + /** + * @deprecated Use `afterResize` instead. This callback is a legacy API + * that fires before resize happens, but it is no longer supported. Now it + * fires after resize happens. + * The resize logic has been upstreamed to litegraph in + * https://github.com/Comfy-Org/ComfyUI_frontend/pull/2557 + */ + beforeResize?: (this: BaseDOMWidget, node: LGraphNode) => void + afterResize?: (this: BaseDOMWidget, node: LGraphNode) => void +} + +export const isDOMWidget = ( + widget: IBaseWidget +): widget is DOMWidget => 'element' in widget && !!widget.element + +export const isComponentWidget = ( + widget: IBaseWidget +): widget is ComponentWidget => 'component' in widget && !!widget.component + +abstract class BaseDOMWidgetImpl + extends LegacyWidget>> + implements BaseDOMWidget +{ + static readonly DEFAULT_MARGIN = 10 + declare readonly name: string + declare readonly options: DOMWidgetOptions + declare callback?: (value: V) => void + + readonly id: string + + constructor(obj: { + node: LGraphNode + name: string + type: string + options: DOMWidgetOptions + }) { + const { node, name, type, options } = obj + super({ y: 0, name, type, options }, node) + + this.id = generateUUID() + } + + override get value(): V { + return this.options.getValue?.() ?? ('' as V) + } + + override set value(v: V) { + this.options.setValue?.(v) + this.callback?.(this.value) + } + + get margin(): number { + return this.options.margin ?? BaseDOMWidgetImpl.DEFAULT_MARGIN + } + + isVisible(): boolean { + return !['hidden'].includes(this.type) && this.node.isWidgetVisible(this) + } + + override draw( + ctx: CanvasRenderingContext2D, + _node: LGraphNode, + widget_width: number, + y: number, + widget_height: number, + lowQuality?: boolean + ): void { + if (this.options.hideOnZoom && lowQuality && this.isVisible()) { + // Draw a placeholder rectangle + const originalFillStyle = ctx.fillStyle + ctx.beginPath() + ctx.fillStyle = LiteGraph.WIDGET_BGCOLOR + ctx.rect( + this.margin, + y + this.margin, + widget_width - this.margin * 2, + (this.computedHeight ?? widget_height) - 2 * this.margin + ) + ctx.fill() + ctx.fillStyle = originalFillStyle + } else if (this.promoted && this.isVisible()) { + ctx.save() + const adjustedMargin = this.margin - 1 + ctx.beginPath() + ctx.strokeStyle = LiteGraph.WIDGET_PROMOTED_OUTLINE_COLOR + ctx.strokeRect( + adjustedMargin, + y + adjustedMargin, + widget_width - adjustedMargin * 2, + (this.computedHeight ?? widget_height) - 2 * adjustedMargin + ) + ctx.restore() + } + this.options.onDraw?.(this) + } + + override onRemove(): void { + useDomWidgetStore().unregisterWidget(this.id) + } + + override createCopyForNode(node: LGraphNode): this { + // @ts-expect-error + const cloned: this = new (this.constructor as typeof this)({ + node: node, + name: this.name, + type: this.type, + options: this.options + }) + cloned.value = this.value + // Preserve the Y position from the original widget to maintain proper positioning + // when widgets are promoted through subgraph nesting + cloned.y = this.y + return cloned + } +} + +export class DOMWidgetImpl + extends BaseDOMWidgetImpl + implements DOMWidget +{ + override readonly element: T + + constructor(obj: { + node: LGraphNode + name: string + type: string + element: T + options: DOMWidgetOptions + }) { + super(obj) + this.element = obj.element + } + + override createCopyForNode(node: LGraphNode): this { + // @ts-expect-error + const cloned: this = new (this.constructor as typeof this)({ + node: node, + name: this.name, + type: this.type, + element: this.element, // Include the element! + options: this.options + }) + cloned.value = this.value + // Preserve the Y position from the original widget to maintain proper positioning + // when widgets are promoted through subgraph nesting + cloned.y = this.y + return cloned + } + + /** Extract DOM widget size info */ + override computeLayoutSize(node: LGraphNode) { + if (this.type === 'hidden') { + return { + minHeight: 0, + maxHeight: 0, + minWidth: 0 + } + } + + const styles = getComputedStyle(this.element) + let minHeight = + this.options.getMinHeight?.() ?? + parseInt(styles.getPropertyValue('--comfy-widget-min-height')) + let maxHeight = + this.options.getMaxHeight?.() ?? + parseInt(styles.getPropertyValue('--comfy-widget-max-height')) + + let prefHeight: string | number = + this.options.getHeight?.() ?? + styles.getPropertyValue('--comfy-widget-height') + + if (typeof prefHeight === 'string' && prefHeight.endsWith?.('%')) { + prefHeight = + node.size[1] * + (parseFloat(prefHeight.substring(0, prefHeight.length - 1)) / 100) + } else { + prefHeight = + typeof prefHeight === 'number' ? prefHeight : parseInt(prefHeight) + + if (isNaN(minHeight)) { + minHeight = prefHeight + } + } + + return { + minHeight: isNaN(minHeight) ? 50 : minHeight, + maxHeight: isNaN(maxHeight) ? undefined : maxHeight, + minWidth: 0 + } + } +} + +export class ComponentWidgetImpl< + V extends object | string, + P extends ComponentWidgetCustomProps = ComponentWidgetCustomProps +> + extends BaseDOMWidgetImpl + implements ComponentWidget +{ + readonly component: Component + readonly inputSpec: InputSpec + readonly props?: P + + constructor(obj: { + node: LGraphNode + name: string + component: Component + inputSpec: InputSpec + props?: P + options: DOMWidgetOptions + type?: string + }) { + super({ + type: 'custom', + ...obj + }) + this.component = obj.component + this.inputSpec = obj.inputSpec + this.props = obj.props + } + + override computeLayoutSize() { + const minHeight = this.options.getMinHeight?.() ?? 50 + const maxHeight = this.options.getMaxHeight?.() + return { + minHeight, + maxHeight, + minWidth: 0 + } + } + + override serializeValue(): V { + return toRaw(this.value) + } +} + +export const addWidget = >( + node: LGraphNode, + widget: W +) => { + node.addCustomWidget(widget) + + if (node.graph) { + useDomWidgetStore().registerWidget(widget) + } + + node.onAdded = useChainCallback(node.onAdded, () => { + useDomWidgetStore().registerWidget(widget) + }) + + node.onRemoved = useChainCallback(node.onRemoved, () => { + widget.onRemove?.() + }) + + node.onResize = useChainCallback(node.onResize, () => { + widget.options.beforeResize?.call(widget, node) + widget.options.afterResize?.call(widget, node) + }) +} + +LGraphNode.prototype.addDOMWidget = function < + T extends HTMLElement, + V extends object | string +>( + this: LGraphNode, + name: string, + type: string, + element: T, + options: DOMWidgetOptions = {} +): DOMWidget { + const widget = new DOMWidgetImpl({ + node: this, + name, + type, + element, + options: { hideOnZoom: true, ...options } + }) + // Note: Before `LGraphNode.configure` is called, `this.id` is always `-1`. + addWidget(this, widget as unknown as BaseDOMWidget) + + // Workaround for https://github.com/Comfy-Org/ComfyUI_frontend/issues/2493 + // Some custom nodes are explicitly expecting getter and setter of `value` + // property to be on instance instead of prototype. + Object.defineProperty(widget, 'value', { + get(this: DOMWidgetImpl): V { + return this.options.getValue?.() ?? ('' as V) + }, + set(this: DOMWidgetImpl, v: V) { + this.options.setValue?.(v) + this.callback?.(this.value) + } + }) + + return widget +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__widgets.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__widgets.ts new file mode 100644 index 00000000..50dabe01 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__scripts__widgets.ts @@ -0,0 +1,308 @@ +import { t } from '@/i18n' +import { type LGraphNode, isComboWidget } from '@/lib/litegraph/src/litegraph' +import type { + IBaseWidget, + IComboWidget, + IStringWidget +} from '@/lib/litegraph/src/types/widgets' +import { useSettingStore } from '@/platform/settings/settingStore' +import { dynamicWidgets } from '@/core/graph/widgets/dynamicWidgets' +import { useBooleanWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget' +import { useChartWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useChartWidget' +import { useColorWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useColorWidget' +import { useComboWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useComboWidget' +import { useFloatWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useFloatWidget' +import { useGalleriaWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useGalleriaWidget' +import { useImageCompareWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useImageCompareWidget' +import { useImageUploadWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useImageUploadWidget' +import { useIntWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useIntWidget' +import { useMarkdownWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useMarkdownWidget' +import { useStringWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useStringWidget' +import { useTextareaWidget } from '@/renderer/extensions/vueNodes/widgets/composables/useTextareaWidget' +import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration' +import type { InputSpec as InputSpecV2 } from '@/schemas/nodeDef/nodeDefSchemaV2' +import type { InputSpec } from '@/schemas/nodeDefSchema' + +import type { ComfyApp } from './app' +import './domWidget' +import './errorNodeWidgets' + +export type ComfyWidgetConstructorV2 = ( + node: LGraphNode, + inputSpec: InputSpecV2 +) => IBaseWidget + +export type ComfyWidgetConstructor = ( + node: LGraphNode, + inputName: string, + inputData: InputSpec, + app: ComfyApp, + widgetName?: string +) => { widget: IBaseWidget; minWidth?: number; minHeight?: number } + +/** + * Transforms a V2 widget constructor to a V1 widget constructor. + * @param widgetConstructorV2 The V2 widget constructor to transform. + * @returns The transformed V1 widget constructor. + */ +const transformWidgetConstructorV2ToV1 = ( + widgetConstructorV2: ComfyWidgetConstructorV2 +): ComfyWidgetConstructor => { + return (node, inputName, inputData) => { + const inputSpec = transformInputSpecV1ToV2(inputData, { + name: inputName + }) + const widget = widgetConstructorV2(node, inputSpec) + return { + widget, + minWidth: widget.options.minNodeSize?.[0], + minHeight: widget.options.minNodeSize?.[1] + } + } +} + +function controlValueRunBefore() { + return useSettingStore().get('Comfy.WidgetControlMode') === 'before' +} + +export function updateControlWidgetLabel(widget: IBaseWidget) { + if (controlValueRunBefore()) { + widget.label = t('g.control_before_generate') + } else { + widget.label = t('g.control_after_generate') + } +} + +export const IS_CONTROL_WIDGET = Symbol() +const HAS_EXECUTED = Symbol() + +export function addValueControlWidget( + node: LGraphNode, + targetWidget: IBaseWidget, + defaultValue?: string, + _values?: unknown, + widgetName?: string, + inputData?: InputSpec +): IComboWidget { + let name = inputData?.[1]?.control_after_generate + if (typeof name !== 'string') { + name = widgetName + } + const widgets = addValueControlWidgets( + node, + targetWidget, + defaultValue ?? 'randomize', + { + addFilterList: false, + controlAfterGenerateName: name + }, + inputData + ) + return widgets[0] +} + +export function addValueControlWidgets( + node: LGraphNode, + targetWidget: IBaseWidget, + defaultValue?: string, + options?: Record, + inputData?: InputSpec +): [IComboWidget, ...IStringWidget[]] { + if (!defaultValue) defaultValue = 'randomize' + if (!options) options = {} + + const getName = (defaultName: string, optionName: string) => { + let name = defaultName + if (options[optionName]) { + name = options[optionName] + } else if (typeof inputData?.[1]?.[defaultName] === 'string') { + name = inputData?.[1]?.[defaultName] + } else if (inputData?.[1]?.control_prefix) { + name = inputData?.[1]?.control_prefix + ' ' + name + } + return name + } + + const valueControl = node.addWidget( + 'combo', + getName('control_after_generate', 'controlAfterGenerateName'), + defaultValue, + function () {}, + { + values: ['fixed', 'increment', 'decrement', 'randomize'], + serialize: false, // Don't include this in prompt. + canvasOnly: true + } + ) as IComboWidget + + valueControl.tooltip = + 'Allows the linked widget to be changed automatically, for example randomizing the noise seed.' + valueControl[IS_CONTROL_WIDGET] = true + updateControlWidgetLabel(valueControl) + const widgets: [IComboWidget, ...IStringWidget[]] = [valueControl] + + const isCombo = isComboWidget(targetWidget) + let comboFilter: IStringWidget + if (isCombo && valueControl.options.values) { + // @ts-expect-error Combo widget values may be a dictionary or legacy function type + valueControl.options.values.push('increment-wrap') + } + if (isCombo && options.addFilterList !== false) { + comboFilter = node.addWidget( + 'string', + getName('control_filter_list', 'controlFilterListName'), + '', + function () {}, + { + serialize: false // Don't include this in prompt. + } + ) as IStringWidget + updateControlWidgetLabel(comboFilter) + comboFilter.tooltip = + "Allows for filtering the list of values when changing the value via the control generate mode. Allows for RegEx matches in the format /abc/ to only filter to values containing 'abc'." + + widgets.push(comboFilter) + } + + const applyWidgetControl = () => { + var v = valueControl.value + + if (isCombo && v !== 'fixed') { + let values = targetWidget.options.values ?? [] + const filter = comboFilter?.value + if (filter) { + let check + if (filter.startsWith('/') && filter.endsWith('/')) { + try { + const regex = new RegExp(filter.substring(1, filter.length - 1)) + check = (item: string) => regex.test(item) + } catch (error) { + console.error( + 'Error constructing RegExp filter for node ' + node.id, + filter, + error + ) + } + } + if (!check) { + const lower = filter.toLocaleLowerCase() + check = (item: string) => item.toLocaleLowerCase().includes(lower) + } + // @ts-expect-error Combo widget values may be a dictionary or legacy function type + values = values.filter((item: string) => check(item)) + if (!values.length && targetWidget.options.values?.length) { + console.warn( + 'Filter for node ' + node.id + ' has filtered out all items', + filter + ) + } + } + // @ts-expect-error targetWidget.value can be number or string + let current_index = values.indexOf(targetWidget.value) + let current_length = values.length + + switch (v) { + case 'increment': + current_index += 1 + break + case 'increment-wrap': + current_index += 1 + if (current_index >= current_length) { + current_index = 0 + } + break + case 'decrement': + current_index -= 1 + break + case 'randomize': + // @ts-expect-error Combo widget values may be a dictionary or legacy function type + current_index = Math.floor(Math.random() * current_length) + break + default: + break + } + current_index = Math.max(0, current_index) + // @ts-expect-error Combo widget values may be a dictionary or legacy function type + current_index = Math.min(current_length - 1, current_index) + if (current_index >= 0) { + // @ts-expect-error Combo widget values may be a dictionary or legacy function type + let value = values[current_index] + targetWidget.value = value + targetWidget.callback?.(value) + } + } else { + //number + let { min = 0, max = 1, step2 = 1 } = targetWidget.options + // limit to something that javascript can handle + max = Math.min(1125899906842624, max) + min = Math.max(-1125899906842624, min) + let range = (max - min) / step2 + + //adjust values based on valueControl Behaviour + switch (v) { + case 'fixed': + break + case 'increment': + // @ts-expect-error targetWidget.value can be number or string + targetWidget.value += step2 + break + case 'decrement': + // @ts-expect-error targetWidget.value can be number or string + targetWidget.value -= step2 + break + case 'randomize': + targetWidget.value = Math.floor(Math.random() * range) * step2 + min + break + default: + break + } + /*check if values are over or under their respective + * ranges and set them to min or max.*/ + // @ts-expect-error targetWidget.value can be number or string + if (targetWidget.value < min) targetWidget.value = min + // @ts-expect-error targetWidget.value can be number or string + if (targetWidget.value > max) targetWidget.value = max + targetWidget.callback?.(targetWidget.value) + } + } + + valueControl.beforeQueued = () => { + if (controlValueRunBefore()) { + // Don't run on first execution + if (valueControl[HAS_EXECUTED]) { + applyWidgetControl() + } + } + valueControl[HAS_EXECUTED] = true + } + + valueControl.afterQueued = () => { + if (!controlValueRunBefore()) { + applyWidgetControl() + } + } + + return widgets +} + +export const ComfyWidgets = { + INT: transformWidgetConstructorV2ToV1(useIntWidget()), + FLOAT: transformWidgetConstructorV2ToV1(useFloatWidget()), + BOOLEAN: transformWidgetConstructorV2ToV1(useBooleanWidget()), + STRING: transformWidgetConstructorV2ToV1(useStringWidget()), + MARKDOWN: transformWidgetConstructorV2ToV1(useMarkdownWidget()), + COMBO: transformWidgetConstructorV2ToV1(useComboWidget()), + IMAGEUPLOAD: useImageUploadWidget(), + COLOR: transformWidgetConstructorV2ToV1(useColorWidget()), + IMAGECOMPARE: transformWidgetConstructorV2ToV1(useImageCompareWidget()), + CHART: transformWidgetConstructorV2ToV1(useChartWidget()), + GALLERIA: transformWidgetConstructorV2ToV1(useGalleriaWidget()), + TEXTAREA: transformWidgetConstructorV2ToV1(useTextareaWidget()), + ...dynamicWidgets +} as const + +export function isValidWidgetType( + key: unknown +): key is keyof typeof ComfyWidgets { + return ComfyWidgets[key as keyof typeof ComfyWidgets] !== undefined +} diff --git a/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__utils__nodeDefUtil.ts b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__utils__nodeDefUtil.ts new file mode 100644 index 00000000..efd67725 --- /dev/null +++ b/docs/hel-892/structure-reference/ComfyUI_frontend__4bf6a196__src__utils__nodeDefUtil.ts @@ -0,0 +1,140 @@ +import _ from 'es-toolkit/compat' + +import type { + ComboInputSpec, + ComboInputSpecV2, + FloatInputSpec, + InputSpec, + IntInputSpec, + NumericInputOptions +} from '@/schemas/nodeDefSchema' +import { + getComboSpecComboOptions, + getInputSpecType, + isComboInputSpec, + isFloatInputSpec, + isIntInputSpec +} from '@/schemas/nodeDefSchema' + +import { lcm } from './mathUtil' + +const IGNORE_KEYS = new Set([ + 'default', + 'forceInput', + 'defaultInput', + 'control_after_generate', + 'multiline', + 'tooltip', + 'dynamicPrompts' +]) + +const getRange = (options: NumericInputOptions) => { + const min = options.min ?? -Infinity + const max = options.max ?? Infinity + return { min, max } +} + +const mergeNumericInputSpec = ( + spec1: T, + spec2: T +): T | null => { + const type = spec1[0] + const options1 = spec1[1] ?? {} + const options2 = spec2[1] ?? {} + + const range1 = getRange(options1) + const range2 = getRange(options2) + + // If the ranges do not overlap, return null + if (range1.min > range2.max || range1.max < range2.min) { + return null + } + + const step1 = options1.step ?? 1 + const step2 = options2.step ?? 1 + + const mergedOptions = { + // Take intersection of ranges + min: Math.max(range1.min, range2.min), + max: Math.min(range1.max, range2.max), + step: lcm(step1, step2) + } + + return mergeCommonInputSpec( + [type, { ...options1, ...mergedOptions }] as T, + [type, { ...options2, ...mergedOptions }] as T + ) +} + +const mergeComboInputSpec = ( + spec1: T, + spec2: T +): T | null => { + const options1 = spec1[1] ?? {} + const options2 = spec2[1] ?? {} + + const comboOptions1 = getComboSpecComboOptions(spec1) + const comboOptions2 = getComboSpecComboOptions(spec2) + + const intersection = _.intersection(comboOptions1, comboOptions2) + + // If the intersection is empty, return null + if (intersection.length === 0) { + return null + } + + return mergeCommonInputSpec( + ['COMBO', { ...options1, options: intersection }] as T, + ['COMBO', { ...options2, options: intersection }] as T + ) +} + +const mergeCommonInputSpec = ( + spec1: T, + spec2: T +): T | null => { + const type = getInputSpecType(spec1) + const options1 = spec1[1] ?? {} + const options2 = spec2[1] ?? {} + + const compareKeys = _.union(_.keys(options1), _.keys(options2)).filter( + (key) => !IGNORE_KEYS.has(key) + ) + + const mergeIsValid = compareKeys.every((key) => { + const value1 = options1[key] + const value2 = options2[key] + return value1 === value2 || (_.isNil(value1) && _.isNil(value2)) + }) + + return mergeIsValid ? ([type, { ...options1, ...options2 }] as T) : null +} + +/** + * Merges two input specs. + * + * @param spec1 - The first input spec. + * @param spec2 - The second input spec. + * @returns The merged input spec, or null if the specs are not mergeable. + */ +export const mergeInputSpec = ( + spec1: InputSpec, + spec2: InputSpec +): InputSpec | null => { + const type1 = getInputSpecType(spec1) + const type2 = getInputSpecType(spec2) + + if (type1 !== type2) { + return null + } + + if (isIntInputSpec(spec1) || isFloatInputSpec(spec1)) { + return mergeNumericInputSpec(spec1, spec2 as typeof spec1) + } + + if (isComboInputSpec(spec1)) { + return mergeComboInputSpec(spec1, spec2 as typeof spec1) + } + + return mergeCommonInputSpec(spec1, spec2) +} diff --git a/docs/hel-892/structure-reference/core-tag-0.11.0.json b/docs/hel-892/structure-reference/core-tag-0.11.0.json new file mode 100644 index 00000000..737ec003 --- /dev/null +++ b/docs/hel-892/structure-reference/core-tag-0.11.0.json @@ -0,0 +1,10 @@ +{ + "ref": "refs/tags/v0.11.0", + "node_id": "REF_kwDOIygeJrFyZWZzL3RhZ3MvdjAuMTEuMA", + "url": "https://api.github.com/repos/Comfy-Org/ComfyUI/git/refs/tags/v0.11.0", + "object": { + "sha": "09725967cf76304371c390ca1d6483e04061da48", + "type": "commit", + "url": "https://api.github.com/repos/Comfy-Org/ComfyUI/git/commits/09725967cf76304371c390ca1d6483e04061da48" + } +} \ No newline at end of file diff --git a/docs/hel-892/structure-reference/discovery.json b/docs/hel-892/structure-reference/discovery.json new file mode 100644 index 00000000..29dcc528 --- /dev/null +++ b/docs/hel-892/structure-reference/discovery.json @@ -0,0 +1,34 @@ +[ + { + "version": "1.48.6", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "request": "https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/trees/7b4172a243e0d43f1679c0be1c307560cd83c00d?recursive=1", + "response_sha256": "fbf97d9a418c271561117f5a39aa6e5f6deb06cb768358770e1331393a303dbc", + "truncated": false, + "role": "discovery_only; rules use pinned source files in sources.json" + }, + { + "version": "1.53.6", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "request": "https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/trees/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1?recursive=1", + "response_sha256": "05d8f4d77b564d46829bbc258ec0e9d24f2cb38cd97f63f496ea2fe0c4689648", + "truncated": false, + "role": "discovery_only; rules use pinned source files in sources.json" + }, + { + "version": "1.48.7", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "request": "https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/trees/6d6af63c00f132cd25dc29307fc56bd2c094fa22?recursive=1", + "response_sha256": "4f3102fdb7a81e4df1d4a71eed54eaca87cb12e8093c11b8fd3d5ac273f54c73", + "truncated": false, + "role": "discovery_only; rules use pinned source files in sources.json" + }, + { + "version": "1.37.11", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "request": "https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/trees/4bf6a1960028cc5cda57d48f9fb01a74dfaade43?recursive=1", + "response_sha256": "501f8b55d5853c40e91187428a1e8afb19a99d1938ecab6a6303b52037bff4ca", + "truncated": false, + "role": "discovery_only; rules use pinned source files in sources.json" + } +] diff --git a/docs/hel-892/structure-reference/qwen-aaf40688.py b/docs/hel-892/structure-reference/qwen-aaf40688.py new file mode 100644 index 00000000..4be554ff --- /dev/null +++ b/docs/hel-892/structure-reference/qwen-aaf40688.py @@ -0,0 +1,1178 @@ +# ComfyUI-QwenASR +# ComfyUI custom nodes for Qwen3-ASR speech-to-text models. + +import os +import re +import shutil +import sys +import time +from pathlib import Path +from typing import Optional, Tuple, List, Dict, Any, Union + +import numpy as np +import torch +import folder_paths +import comfy.model_management as model_management +from transformers import ( + AutoProcessor, + AutoModelForMultimodalLM, + AutoModelForTokenClassification, +) + +_CURRENT_DIR = Path(__file__).parent + +# ComfyUI model folder registration +QWEN3_ASR_ROOT = os.path.join(folder_paths.models_dir, "Qwen3-ASR") +os.makedirs(QWEN3_ASR_ROOT, exist_ok=True) +folder_paths.add_model_folder_path("Qwen3-ASR", QWEN3_ASR_ROOT) + +SUPPORTED_LANGUAGES = [ + "auto", + "Chinese", "English", "Cantonese", "Arabic", "German", "French", "Spanish", + "Portuguese", "Indonesian", "Italian", "Korean", "Russian", "Thai", + "Vietnamese", "Japanese", "Turkish", "Hindi", "Malay", "Dutch", "Swedish", + "Danish", "Finnish", "Polish", "Czech", "Filipino", "Persian", "Greek", + "Hungarian", "Macedonian", "Romanian", +] + +_ASR_MODEL_CACHE = {} +_ALIGNER_CACHE = {} +_CONFIG_CACHE = {"mtime": None, "data": None} +_EXTRA_MODEL_PATHS = None + + +class WordTimestamp: + def __init__(self, text: str = "", start_time: float = 0.0, end_time: float = 0.0): + self.text = str(text) + self.start_time = float(start_time) + self.end_time = float(end_time) + + def __repr__(self): + return f"WordTimestamp({self.text!r}, {self.start_time:.3f}, {self.end_time:.3f})" + + +class ForcedAlignResult: + def __init__(self, items: List[WordTimestamp]): + self.items = items + + def __iter__(self): + return iter(self.items) + + def __len__(self): + return len(self.items) + + def __getitem__(self, idx): + return self.items[idx] + + +def _default_config(): + return { + "models": { + "Qwen/Qwen3-ASR-1.7B-hf": "Qwen3-ASR-1.7B-hf", + "Qwen/Qwen3-ASR-0.6B-hf": "Qwen3-ASR-0.6B-hf", + }, + "aligners": { + "None": None, + "Qwen/Qwen3-ForcedAligner-0.6B-hf": "Qwen3-ForcedAligner-0.6B-hf", + }, + "sources": ["HuggingFace", "ModelScope"], + "defaults": { + "repo_id": "Qwen/Qwen3-ASR-0.6B-hf", + "source": "HuggingFace", + "precision": "bf16", + "attention": "auto", + "language": "auto", + "forced_aligner": "Qwen/Qwen3-ForcedAligner-0.6B-hf", + }, + } + + +def _load_config(): + path = _CURRENT_DIR / "config.json" + try: + mtime = path.stat().st_mtime + except Exception: + mtime = None + + cache = _CONFIG_CACHE + if cache["data"] is not None and cache["mtime"] == mtime: + return cache["data"] + + data = _default_config() + if mtime is not None: + try: + import json + loaded = json.loads(path.read_text(encoding="utf-8")) + if isinstance(loaded, dict): + data.update(loaded) + except Exception as e: + print(f"[Qwen3ASR] Failed to read config.json: {e}") + + cache["mtime"] = mtime + cache["data"] = data + return data + + +def _get_model_ids(): + models = _load_config().get("models") or {} + if isinstance(models, dict) and models: + return models + return _default_config()["models"] + + +def _get_aligner_ids(): + aligners = _load_config().get("aligners") or {} + if isinstance(aligners, dict) and aligners: + return aligners + return _default_config()["aligners"] + + +def _get_sources(): + sources = _load_config().get("sources") or [] + if isinstance(sources, list) and sources: + return sources + return _default_config()["sources"] + + +def _get_defaults(): + defaults = _load_config().get("defaults") or {} + if isinstance(defaults, dict) and defaults: + return defaults + return _default_config()["defaults"] + + +def _normalize_paths(paths): + normalized = [] + for p in paths: + if not isinstance(p, str): + continue + p = p.strip() + if not p: + continue + normalized.append(os.path.normpath(os.path.expanduser(p))) + return normalized + + +def _extract_yaml_paths(data): + if not isinstance(data, dict): + return [] + + def split_paths(value): + if isinstance(value, str): + lines = [line.strip() for line in value.splitlines()] + return [line for line in lines if line] + if isinstance(value, list): + return [v for v in value if isinstance(v, str) and v.strip()] + return [] + + def is_abs(p): + if not p: + return False + if os.path.isabs(p): + return True + if len(p) > 1 and p[1] == ":": + return True + return False + + def pull(d): + found = [] + for key in ("paths", "roots", "folders", "models", "search_paths"): + value = d.get(key) + found.extend(split_paths(value)) + return found + + paths = [] + paths.extend(pull(data)) + for section in data.values(): + if not isinstance(section, dict): + continue + base_path = section.get("base_path") + if isinstance(base_path, str) and base_path.strip(): + paths.append(base_path) + for key, value in section.items(): + if key in ("base_path", "is_default"): + continue + for item in split_paths(value): + if is_abs(item) or not isinstance(base_path, str): + paths.append(item) + else: + paths.append(os.path.join(base_path, item)) + return paths + + +def _load_extra_model_paths(): + global _EXTRA_MODEL_PATHS + if _EXTRA_MODEL_PATHS is not None: + return _EXTRA_MODEL_PATHS + + candidates = [] + try: + base_path = Path(getattr(folder_paths, "base_path", "")) + if base_path: + candidates.append(base_path / "extra_model_paths.yaml") + except Exception: + pass + + collected = [] + for path in candidates: + if not path.exists(): + continue + try: + import yaml + data = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + except Exception as e: + print(f"[Qwen3ASR] Failed to read {path}: {e}") + continue + collected.extend(_extract_yaml_paths(data)) + + normalized = [] + for p in _normalize_paths(collected): + if os.path.isdir(p) and p not in normalized: + normalized.append(p) + + _EXTRA_MODEL_PATHS = tuple(normalized) + return _EXTRA_MODEL_PATHS + + +def _model_storage_path(repo_id: str) -> str: + name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.split("/")[-1] + return os.path.join(QWEN3_ASR_ROOT, name) + + +def _find_local_model(repo_id: str) -> Optional[str]: + model_name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.split("/")[-1] + candidates = [] + + default_root = _model_storage_path(repo_id) + if os.path.isdir(default_root): + candidates.append(default_root) + + try: + asr_roots = folder_paths.get_folder_paths("Qwen3-ASR") or [] + for root in asr_roots: + candidates.append(os.path.join(root, model_name)) + except Exception: + pass + + for root in _load_extra_model_paths(): + candidates.append(os.path.join(root, model_name)) + candidates.append(os.path.join(root, "Qwen3-ASR", model_name)) + candidates.append(os.path.join(root, "ASR", "Qwen3-ASR", model_name)) + + for path in candidates: + if os.path.isdir(path) and os.listdir(path): + return path + return None + + +def _try_copy_cached(repo_id: str, target_dir: str) -> bool: + if os.path.isdir(target_dir) and os.listdir(target_dir): + return True + + hf_cache = os.path.join(Path.home(), ".cache", "huggingface", "hub") + hf_dir = os.path.join(hf_cache, f"models--{repo_id.replace('/', '--')}") + snapshots = os.path.join(hf_dir, "snapshots") + if os.path.isdir(snapshots): + entries = sorted(os.listdir(snapshots)) + if entries: + source = os.path.join(snapshots, entries[-1]) + try: + shutil.copytree(source, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + ms_cache = os.path.join(Path.home(), ".cache", "modelscope", "hub") + ms_dir = os.path.join(ms_cache, repo_id.replace("/", os.sep)) + if os.path.isdir(ms_dir): + try: + shutil.copytree(ms_dir, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + return False + + +def _download_to_local(repo_id: str, source: str, target_dir: str) -> str: + os.makedirs(target_dir, exist_ok=True) + if source == "ModelScope": + try: + from modelscope import snapshot_download + except Exception as e: + raise RuntimeError("modelscope is required for ModelScope downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + else: + try: + from huggingface_hub import snapshot_download + except Exception as e: + raise RuntimeError("huggingface_hub is required for HuggingFace downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + + return target_dir + + +def _resolve_model_path(repo_id: str, source: str) -> str: + local_path = _find_local_model(repo_id) + if local_path: + return local_path + + target_dir = _model_storage_path(repo_id) + if os.path.isdir(target_dir) and os.listdir(target_dir): + return target_dir + + if _try_copy_cached(repo_id, target_dir): + return target_dir + + return _download_to_local(repo_id, source, target_dir) + + +def _normalize_audio(audio, target_sr: int = 16000) -> Optional[Tuple[np.ndarray, int]]: + if audio is None: + return None + + waveform = audio.get("waveform") + sample_rate = audio.get("sample_rate") + if waveform is None or sample_rate is None: + return None + + wave = waveform[0] + if wave.ndim == 2 and wave.shape[0] > 1: + wave = torch.mean(wave, dim=0) + elif wave.ndim == 2: + wave = wave.squeeze(0) + + if int(sample_rate) != target_sr: + import torchaudio.functional as F + wave = F.resample(wave, int(sample_rate), target_sr) + sample_rate = target_sr + + return (wave.detach().cpu().numpy().astype(np.float32), int(sample_rate)) + + +def _build_dtype(precision: str, device: torch.device) -> torch.dtype: + if precision == "fp16": + return torch.float16 + if precision == "bf16": + if device.type == "mps": + return torch.float16 + return torch.bfloat16 + return torch.float32 + + +def _is_hf_native(repo_id_or_path: str) -> bool: + s = str(repo_id_or_path).lower() + return "-hf" in s + + +# ------------------------------------------------------------------------- +# Native Transformers Engine Implementation +# ------------------------------------------------------------------------- + +class _HFASREngine: + def __init__(self, model_path: str, dtype: torch.dtype, device: torch.device, attention: str): + self.processor = AutoProcessor.from_pretrained(model_path) + kwargs = {"dtype": dtype} + if attention != "auto": + kwargs["attn_implementation"] = attention + if device.type in ("mps", "cpu"): + self.model = AutoModelForMultimodalLM.from_pretrained(model_path, **kwargs).to(device).eval() + else: + kwargs["device_map"] = str(device) + self.model = AutoModelForMultimodalLM.from_pretrained(model_path, **kwargs).eval() + self.device = device + self.dtype = dtype + + def transcribe( + self, + audio_data: Tuple[np.ndarray, int], + language: Optional[str] = None, + context: Optional[str] = None, + max_new_tokens: int = 256, + ) -> Tuple[str, str]: + wave, sr = audio_data + duration = len(wave) / float(sr) + + if duration <= 120.0: + return self._transcribe_chunk(wave, language, context, max_new_tokens) + + chunk_samples = 60 * sr + texts = [] + detected_lang = "" + for start_idx in range(0, len(wave), chunk_samples): + chunk_wave = wave[start_idx : start_idx + chunk_samples] + if len(chunk_wave) < int(0.5 * sr): + continue + sub_text, sub_lang = self._transcribe_chunk(chunk_wave, language, context, max_new_tokens) + if sub_text: + texts.append(sub_text) + if not detected_lang and sub_lang: + detected_lang = sub_lang + + full_text = " ".join(texts) + return full_text, detected_lang + + def _transcribe_chunk(self, wave: np.ndarray, language: Optional[str], context: Optional[str], max_new_tokens: int): + kwargs = {"audio": wave} + if language and language != "auto": + kwargs["language"] = language + if context: + kwargs["prompt"] = context + + inputs = self.processor.apply_transcription_request(**kwargs) + inputs = inputs.to(self.device, self.dtype) + + with torch.inference_mode(): + output_ids = self.model.generate(**inputs, max_new_tokens=max_new_tokens) + + generated_ids = output_ids[:, inputs["input_ids"].shape[1]:] + parsed = self.processor.decode(generated_ids, return_format="parsed")[0] + if isinstance(parsed, dict): + text = parsed.get("transcription", "") or "" + lang = parsed.get("language", "") or "" + else: + text = str(parsed) + lang = "" + return text.strip(), lang + + +class _HFAlignerEngine: + def __init__(self, model_path: str, dtype: torch.dtype, device: torch.device, attention: str): + self.processor = AutoProcessor.from_pretrained(model_path) + kwargs = {"dtype": dtype} + if attention != "auto": + kwargs["attn_implementation"] = attention + if device.type in ("mps", "cpu"): + self.model = AutoModelForTokenClassification.from_pretrained(model_path, **kwargs).to(device).eval() + else: + kwargs["device_map"] = str(device) + self.model = AutoModelForTokenClassification.from_pretrained(model_path, **kwargs).eval() + self.device = device + self.dtype = dtype + + def align( + self, + audio: Union[Tuple[np.ndarray, int], Any], + text: Union[str, List[str]], + language: Union[str, List[str]] = "English", + ) -> List[ForcedAlignResult]: + if isinstance(audio, tuple) and len(audio) == 2: + wave, sr = audio + else: + norm = _normalize_audio(audio) + wave, sr = norm if norm is not None else (np.zeros(16000, dtype=np.float32), 16000) + + transcript = text[0] if isinstance(text, list) else text + lang = language[0] if isinstance(language, list) else language + + aligner_inputs, word_lists = self.processor.prepare_forced_aligner_inputs( + audio=wave, + transcript=transcript, + language=lang, + ) + aligner_inputs = aligner_inputs.to(self.device, self.dtype) + + with torch.inference_mode(): + outputs = self.model(**aligner_inputs) + + timestamp_token_id = getattr(self.model.config, "timestamp_token_id", None) + timestamps = self.processor.decode_forced_alignment( + logits=outputs.logits, + input_ids=aligner_inputs["input_ids"], + word_lists=word_lists, + timestamp_token_id=timestamp_token_id, + )[0] + + items = [ + WordTimestamp( + text=item.get("text", "") if isinstance(item, dict) else getattr(item, "text", ""), + start_time=float(item.get("start_time", 0.0) if isinstance(item, dict) else getattr(item, "start_time", 0.0)), + end_time=float(item.get("end_time", 0.0) if isinstance(item, dict) else getattr(item, "end_time", 0.0)), + ) + for item in timestamps + ] + return [ForcedAlignResult(items=items)] + + +class UnifiedASRModel: + def __init__(self, asr_engine: Any, aligner_engine: Any = None): + self.asr = asr_engine + self.aligner = aligner_engine + + def transcribe( + self, + audio_data: Tuple[np.ndarray, int], + language: Optional[str] = None, + context: Optional[str] = None, + return_time_stamps: bool = False, + max_new_tokens: int = 256, + ) -> Tuple[str, str, Optional[List[WordTimestamp]]]: + text, detected_lang = self.asr.transcribe( + audio_data=audio_data, + language=language, + context=context, + max_new_tokens=max_new_tokens, + ) + + time_stamps = None + if return_time_stamps and self.aligner is not None and text.strip(): + lang_align = detected_lang or language or "English" + align_results = self.aligner.align(audio=audio_data, text=text, language=lang_align) + if align_results and len(align_results) > 0: + time_stamps = list(align_results[0]) + + return text, detected_lang, time_stamps + + +def _load_cached_aligner( + aligner_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str = "auto", +): + key = (aligner_path, str(dtype), str(device), attention) + cached = _ALIGNER_CACHE.get(key) + if cached is not None: + return cached + + if not _is_hf_native(aligner_path): + raise ValueError( + f"Model '{aligner_path}' is not supported. " + "Please use the official native model: 'Qwen/Qwen3-ForcedAligner-0.6B-hf'." + ) + + aligner = _HFAlignerEngine(aligner_path, dtype, device, attention) + _ALIGNER_CACHE[key] = aligner + return aligner + + +def _load_cached_asr( + model_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str = "auto", + forced_aligner_path: str = "", + max_inference_batch_size: int = 32, + max_new_tokens: int = 256, +) -> UnifiedASRModel: + key = ( + model_path, + str(dtype), + str(device), + attention, + forced_aligner_path or "", + int(max_inference_batch_size), + int(max_new_tokens), + ) + cached = _ASR_MODEL_CACHE.get(key) + if cached is not None: + return cached + + if not _is_hf_native(model_path): + raise ValueError( + f"Model '{model_path}' is not supported. " + "Please use official native models: 'Qwen/Qwen3-ASR-0.6B-hf' or 'Qwen/Qwen3-ASR-1.7B-hf'." + ) + + asr_engine = _HFASREngine(model_path, dtype, device, attention) + aligner_engine = None + if forced_aligner_path: + aligner_engine = _load_cached_aligner(forced_aligner_path, dtype, device, attention) + + unified = UnifiedASRModel(asr_engine=asr_engine, aligner_engine=aligner_engine) + _ASR_MODEL_CACHE[key] = unified + return unified + + +# ------------------------------------------------------------------------- +# Subtitle & Text Utilities +# ------------------------------------------------------------------------- + +def _format_srt_time(seconds: float) -> str: + total_ms = max(0, int(round(seconds * 1000))) + ms = total_ms % 1000 + total_s = total_ms // 1000 + s = total_s % 60 + total_m = total_s // 60 + m = total_m % 60 + h = total_m // 60 + return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}" + + +def _build_srt(time_stamps) -> str: + if not time_stamps: + return "" + lines = [] + for idx, item in enumerate(time_stamps, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(item.start_time)} --> {_format_srt_time(item.end_time)}") + lines.append(item.text or "") + lines.append("") + return "\n".join(lines).strip() + + +def _join_tokens(a: str, b: str) -> str: + if not a: + return b + if not b: + return a + for ch in (a[-1], b[0]): + if "\u4e00" <= ch <= "\u9fff": + return f"{a}{b}" + return f"{a} {b}" + + +def _restore_punctuation(time_stamps, full_text: str): + if not time_stamps or not full_text: + return time_stamps + + punct_set = set(".,!?:;—…~。,!?、;:”’'\"()()[]【】《》") + text_len = len(full_text) + text_pos = 0 + + restored = [] + for ts in time_stamps: + raw_word = str(ts.text or "").strip() + if not raw_word: + restored.append(ts) + continue + + pattern = re.escape(raw_word) + m = re.search(pattern, full_text[text_pos:], re.IGNORECASE) + if not m: + restored.append(ts) + continue + + word_start = text_pos + m.start() + word_end = text_pos + m.end() + matched_cased_word = full_text[word_start:word_end] + + trail_pos = word_end + trail_punct = [] + while trail_pos < text_len: + ch = full_text[trail_pos] + if ch in punct_set: + trail_punct.append(ch) + trail_pos += 1 + elif ch.isspace(): + trail_pos += 1 + else: + break + + new_text = matched_cased_word + "".join(trail_punct) + restored.append(type(ts)(text=new_text, start_time=ts.start_time, end_time=ts.end_time)) + text_pos = trail_pos + + return restored + + +_DANGLING_TAILS = { + "for", "to", "of", "in", "on", "at", "with", "by", "from", "about", "into", "through", + "the", "a", "an", + "and", "or", "but", "nor", "so", "yet", + "that", "which", "who", "whom", "whose", + "as", "if", "when", "than", "because", "while", "where" +} + + +def _group_time_stamps(time_stamps, max_gap_sec: float, max_chars: int, split_mode: str): + if not time_stamps: + return [] + groups = [] + cur = None + sentence_punct = ("。", "!", "?", ".", "!", "?") + clause_punct = (",", ";", ":", ",", ";", ":", "、") + all_punct = sentence_punct + clause_punct + + n_items = len(time_stamps) + for idx, item in enumerate(time_stamps): + text = (item.text or "").strip() + if not text: + continue + if cur is None: + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + continue + + gap = float(item.start_time) - float(cur["end"]) + too_far = gap > max_gap_sec + end_sentence = any(cur["text"].endswith(p) for p in sentence_punct) + end_clause = any(cur["text"].endswith(p) for p in clause_punct) + this_word_ends_sentence = any(text.endswith(p) for p in sentence_punct) + this_word_ends_clause = any(text.endswith(p) for p in all_punct) + + # Lookahead: check if the sentence ends in the next 1-3 words (Orphan Protection) + sentence_ends_soon = this_word_ends_sentence + if not sentence_ends_soon: + for lookahead in range(1, 4): + if idx + lookahead < n_items: + next_t = (time_stamps[idx + lookahead].text or "").strip() + if any(next_t.endswith(p) for p in sentence_punct): + sentence_ends_soon = True + break + + # Lookahead: check if a clause punct (comma, etc.) ends on this word or next 1-2 words + clause_ends_soon = this_word_ends_clause + if not clause_ends_soon: + for lookahead in range(1, 3): + if idx + lookahead < n_items: + next_t = (time_stamps[idx + lookahead].text or "").strip() + if any(next_t.endswith(p) for p in all_punct): + clause_ends_soon = True + break + + # Dangling check: does current accumulated text end with a dangling preposition/article/conjunction? + last_word = cur["text"].split()[-1].lower().rstrip(",.?!;:,。!?;:") if cur["text"].split() else "" + is_dangling = last_word in _DANGLING_TAILS + + too_long = False + if max_chars > 0: + projected_len = len(cur["text"]) + 1 + len(text) + # Soft tolerance: if a clause/sentence ends soon or last word is dangling, allow up to 25% overshoot + effective_max = int(max_chars * 1.25) if (sentence_ends_soon or clause_ends_soon or is_dangling) else max_chars + if projected_len > effective_max: + if not sentence_ends_soon: + too_long = True + + split_by_punct = "punctuation" in split_mode + split_by_length = "length" in split_mode + split_by_pause = "pause" in split_mode + + min_clause_len = 10 if any('\u4e00' <= c <= '\u9fff' for c in cur["text"]) else 20 + + should_split = False + if split_by_punct: + if end_sentence: + should_split = True + elif end_clause and (len(cur["text"]) >= min_clause_len or too_long): + should_split = True + if split_by_pause and too_far and not should_split: + should_split = True + if split_by_length and too_long and not should_split: + should_split = True + + if should_split: + groups.append(cur) + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + else: + cur["text"] = _join_tokens(cur["text"], text).strip() + cur["end"] = item.end_time + + if cur is not None: + groups.append(cur) + return groups + + +def _build_srt_from_groups(groups) -> str: + if not groups: + return "" + lines = [] + for idx, g in enumerate(groups, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(g['start'])} --> {_format_srt_time(g['end'])}") + lines.append(g["text"]) + lines.append("") + return "\n".join(lines).strip() + + +def _default_output_dir() -> str: + base = folder_paths.get_output_directory() + return os.path.join(base, "ComfyUI-QwenASR") + + +def _is_dir_path(path: str) -> bool: + if not path: + return False + if path.endswith(("/", "\\")): + return True + return os.path.isdir(path) + + +def _make_default_filename(ext: str) -> str: + stamp = time.strftime("%Y%m%d_%H%M%S") + return f"qwenasr_subtitle_{stamp}{ext}" + + +# ------------------------------------------------------------------------- +# Inverse Text Normalization (ITN) & Text Formatting +# ------------------------------------------------------------------------- + +_CN_NUM = { + '零': 0, '一': 1, '二': 2, '两': 2, '三': 3, '四': 4, + '五': 5, '六': 6, '七': 7, '八': 8, '九': 9, +} +_CN_UNIT = { + '十': 10, '百': 100, '千': 1000, '万': 10000, '亿': 100000000 +} +_ITN_CACHE = {"mtime": None, "data": None} + + +def _default_itn_rules(): + return { + "protected_words": [], + "custom_replacements": {}, + "enable_number_conversion": True, + "enable_acronym_cleanup": True, + } + + +def _load_itn_rules(): + path = _CURRENT_DIR / "itn_rules.json" + try: + mtime = path.stat().st_mtime + except Exception: + mtime = None + + cache = _ITN_CACHE + if cache["data"] is not None and cache["mtime"] == mtime: + return cache["data"] + + data = _default_itn_rules() + if mtime is not None: + try: + import json + loaded = json.loads(path.read_text(encoding="utf-8")) + if isinstance(loaded, dict): + data = { + "protected_words": list(loaded.get("protected_words", [])), + "custom_replacements": dict(loaded.get("custom_replacements", {})), + "enable_number_conversion": bool(loaded.get("enable_number_conversion", True)), + "enable_acronym_cleanup": bool(loaded.get("enable_acronym_cleanup", True)), + } + except Exception as e: + print(f"[Qwen3ASR] Failed to read itn_rules.json: {e}") + + cache["mtime"] = mtime + cache["data"] = data + return data + + +def _parse_cn_int(s: str) -> int: + if not s: + return 0 + if all(c in _CN_NUM for c in s) and not any(u in _CN_UNIT for u in s): + return int(''.join(str(_CN_NUM[c]) for c in s)) + total = 0 + r = 0 + for c in s: + if c in _CN_NUM: + r = _CN_NUM[c] + elif c in _CN_UNIT: + unit = _CN_UNIT[c] + if unit >= 10000: + total = (total + (r if r else 1)) * unit + r = 0 + else: + total += (r if r else 1) * unit + r = 0 + total += r + return total + + +def _convert_cn_number(match): + s = match.group(0) + if s.startswith('百分之'): + val = s[3:] + if '点' in val: + p = val.split('点') + int_p = _parse_cn_int(p[0]) if p[0] else 0 + dec_p = ''.join(str(_CN_NUM.get(c, c)) for c in p[1]) + return f'{int_p}.{dec_p}%' + return f'{_parse_cn_int(val)}%' + + if '点' in s: + parts = s.split('点') + int_part = _parse_cn_int(parts[0]) if parts[0] else 0 + dec_part = ''.join(str(_CN_NUM.get(c, c)) for c in parts[1]) + return f'{int_part}.{dec_part}' + + return str(_parse_cn_int(s)) + + +def _normalize_text(text: str) -> str: + if not text: + return "" + + cfg = _load_itn_rules() + + # 1. Custom user replacements (handles any language or special jargon) + custom_replacements = cfg.get("custom_replacements") or {} + for k, v in custom_replacements.items(): + if k.startswith("_"): + continue + if re.search(r'[a-zA-Z]', k): + text = re.sub(re.escape(k), v, text, flags=re.IGNORECASE) + elif k in text: + text = text.replace(k, v) + + # 2. Mask protected words from conversion + protected = cfg.get("protected_words") or [] + placeholders = {} + for idx, word in enumerate(protected): + if word in text: + key = f"__PROT_{idx}__" + placeholders[key] = word + text = text.replace(word, key) + + # 3. Chinese number conversion + if cfg.get("enable_number_conversion", True): + text = re.sub(r'百分之[零一二两三四五六七八九十百]+(?:点[零一二两三四五六七八九]+)?', _convert_cn_number, text) + text = re.sub(r'[零一二两三四五六七八九十百千万亿]+点[零一二两三四五六七八九]+', _convert_cn_number, text) + text = re.sub(r'[零一二两三四五六七八九十百千万亿]{2,}', _convert_cn_number, text) + + # 4. Spaced Latin acronym cleanup (e.g. 'A S R' -> 'ASR', 'U S B' -> 'USB') + if cfg.get("enable_acronym_cleanup", True): + text = re.sub(r'(?:(?<=[^a-zA-Z])|^)([a-zA-Z])(?:\s+([a-zA-Z]))+(?=[^a-zA-Z]|$)', + lambda m: m.group(0).replace(' ', ''), text) + + # 5. Restore protected words + for key, word in placeholders.items(): + text = text.replace(key, word) + + return text + + +# ------------------------------------------------------------------------- +# ComfyUI Nodes +# ------------------------------------------------------------------------- + +class AILab_Qwen3ASR: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B-hf"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "placeholder": "Optional: Context hotwords, names, or terminology (e.g. Qwen3-ASR)...", "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "normalize_text": ("BOOLEAN", {"default": True, "tooltip": "Normalize spoken numbers ('一百二十八' -> '128') and acronym spacing ('A S R' -> 'ASR')."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("TEXT",) + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B-hf", + precision="bf16", + language="auto", + hints="", + normalize_text=True, + unload_models=True, + ): + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + attention = _get_defaults().get("attention", "auto") + + print(f"[QwenASR] [ASR] Resolving model '{model}' from {source}...") + model_path = _resolve_model_path(model, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + print("[QwenASR] [ASR] Error: Invalid or missing audio input.") + return ("",) + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + print(f"[QwenASR] [ASR] Transcribing audio ({len(audio_data[0]) / float(audio_data[1]):.1f}s, language: {language})...") + model_runner = _load_cached_asr(model_path, dtype, device, attention, "") + text, detected_lang, _ = model_runner.transcribe( + audio_data=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=False, + ) + + if normalize_text: + text = _normalize_text(text) + + print(f"[QwenASR] [ASR] Transcription complete: {len(text)} characters (detected: {detected_lang or 'N/A'}).") + + if unload_models: + _ASR_MODEL_CACHE.clear() + _ALIGNER_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text,) + + +class AILab_Qwen3ASRSubtitle: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B-hf"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "attention": (["auto", "flash_attention_2", "sdpa", "eager"], {"default": defaults.get("attention", "auto"), "tooltip": "Attention backend override."}), + "forced_aligner": (list(_get_aligner_ids().keys()), {"default": defaults.get("forced_aligner", "Qwen/Qwen3-ForcedAligner-0.6B-hf"), "tooltip": "Forced aligner for timestamped subtitles."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "placeholder": "Optional: Context hotwords, names, or terminology (e.g. Qwen3-ASR)...", "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "output_format": (["none", "txt", "srt"], {"default": "none", "tooltip": "File save format only (does not change subtitle output)."}), + "output_path": ("STRING", {"default": "", "multiline": False, "tooltip": "Optional output file path (relative goes to ComfyUI output)."}), + "split_mode": (["split_by_punctuation_or_pause", "split_by_punctuation_or_pause_or_length", "split_by_punctuation_or_length", "split_by_punctuation", "split_by_pause", "split_by_length"], {"default": "split_by_punctuation_or_pause", "tooltip": "Sentence splitting strategy. 'split_by_punctuation_or_pause' is recommended for natural, readable subtitle clauses without arbitrary character slicing."}), + "max_gap_sec": ("FLOAT", {"default": 0.6, "min": 0.0, "max": 8.0, "step": 0.1, "tooltip": "Max silence gap to keep the same sentence."}), + "max_chars": ("INT", {"default": 40, "min": 0, "max": 200, "tooltip": "Optional max characters per line (0 = no limit, 80 recommended if length splitting is enabled)."}), + "max_inference_batch_size": ("INT", {"default": 32, "min": 1, "max": 256, "tooltip": "Batch size for inference/alignment to avoid OOM."}), + "max_new_tokens": ("INT", {"default": 256, "min": 1, "max": 2048, "tooltip": "Max new tokens per chunk."}), + "normalize_text": ("BOOLEAN", {"default": True, "tooltip": "Normalize spoken numbers ('一百二十八' -> '128') and acronym spacing ('A S R' -> 'ASR')."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING") + RETURN_NAMES = ("TEXT", "SUBTITLES", "LANGUAGE", "OUTPUT_PATH") + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B-hf", + precision="bf16", + attention="auto", + forced_aligner="Qwen/Qwen3-ForcedAligner-0.6B-hf", + language="auto", + hints="", + output_format="none", + output_path="", + split_mode="split_by_punctuation_or_pause", + max_gap_sec=0.6, + max_chars=80, + max_inference_batch_size=32, + max_new_tokens=256, + normalize_text=True, + unload_models=True, + ): + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + + print(f"[QwenASR] [Subtitle] Resolving models (ASR: {model}, Aligner: {forced_aligner}) from {source}...") + model_path = _resolve_model_path(model, source) + + forced_aligner_path = "" + if forced_aligner and forced_aligner != "None": + forced_aligner_path = _resolve_model_path(forced_aligner, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + print("[QwenASR] [Subtitle] Error: Invalid or missing audio input.") + return ("", "", "", "") + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + duration = len(audio_data[0]) / float(audio_data[1]) + print(f"[QwenASR] [Subtitle] Transcribing audio ({duration:.1f}s, language: {language})...") + model_runner = _load_cached_asr( + model_path, + dtype, + device, + attention, + forced_aligner_path, + max_inference_batch_size=max_inference_batch_size, + max_new_tokens=max_new_tokens, + ) + text, detected_lang, time_stamps = model_runner.transcribe( + audio_data=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=bool(forced_aligner_path), + max_new_tokens=max_new_tokens, + ) + + if time_stamps and text: + time_stamps = _restore_punctuation(time_stamps, text) + + if normalize_text: + text = _normalize_text(text) + + subtitles = "" + file_path = "" + groups = _group_time_stamps(time_stamps, max_gap_sec=max_gap_sec, max_chars=max_chars, split_mode=split_mode) + + if normalize_text: + for g in groups: + g["text"] = _normalize_text(g["text"]) + + lines = [f"{g['start']:.2f}-{g['end']:.2f}: {g['text']}" for g in groups] + subtitles = "\n".join(lines) if lines else text + + if forced_aligner_path and time_stamps: + print(f"[QwenASR] [Subtitle] Forced alignment generated {len(time_stamps)} word timestamps -> {len(groups)} subtitle lines.") + elif forced_aligner_path: + print("[QwenASR] [Subtitle] Notice: Aligner active but no word timestamps were generated (silence or unaligned speech).") + else: + print("[QwenASR] [Subtitle] Notice: Forced aligner set to 'None'. Outputting plain text.") + + if output_format != "none": + out_path = (output_path or "").strip() + if not os.path.isabs(out_path): + if out_path == "": + out_path = _default_output_dir() + out_path = os.path.join(folder_paths.get_output_directory(), out_path) + + if _is_dir_path(out_path): + ext = ".srt" if output_format == "srt" else ".txt" + out_path = os.path.join(out_path, _make_default_filename(ext)) + else: + root, ext = os.path.splitext(out_path) + if not ext: + ext = ".srt" if output_format == "srt" else ".txt" + out_path = root + ext + os.makedirs(os.path.dirname(out_path), exist_ok=True) + if output_format == "srt": + file_content = _build_srt_from_groups(groups) if groups else text + else: + file_content = subtitles + with open(out_path, "w", encoding="utf-8") as f: + f.write(file_content) + file_path = out_path + + if unload_models: + _ASR_MODEL_CACHE.clear() + _ALIGNER_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text, subtitles, detected_lang, file_path) + + +NODE_CLASS_MAPPINGS = { + "AILab_Qwen3ASR": AILab_Qwen3ASR, + "AILab_Qwen3ASRSubtitle": AILab_Qwen3ASRSubtitle, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "AILab_Qwen3ASR": "ASR (QwenASR)", + "AILab_Qwen3ASRSubtitle": "Subtitle (QwenASR)", +} diff --git a/docs/hel-892/structure-reference/qwen-b037d7be.py b/docs/hel-892/structure-reference/qwen-b037d7be.py new file mode 100644 index 00000000..68563f1e --- /dev/null +++ b/docs/hel-892/structure-reference/qwen-b037d7be.py @@ -0,0 +1,723 @@ +# ComfyUI-QwenASR +# ComfyUI custom nodes for Qwen3-ASR speech-to-text models. +# Models License Notice: +# - Qwen3-ASR: Apache-2.0 License (https://huggingface.co/Qwen/Qwen3-ASR-1.7B) +# This integration script follows GPL-3.0 License. + +import os +import shutil +import sys +import time +from pathlib import Path +from typing import Optional, Tuple, List + +import numpy as np +import torch +import folder_paths +import comfy.model_management as model_management + +_CURRENT_DIR = Path(__file__).parent +_QWEN_ASR_DIR = _CURRENT_DIR / "qwen_asr" +if _QWEN_ASR_DIR.exists() and str(_CURRENT_DIR) not in sys.path: + sys.path.insert(0, str(_CURRENT_DIR)) + +try: + from qwen_asr import Qwen3ASRModel +except Exception as _e: + Qwen3ASRModel = None + _IMPORT_ERROR = _e +else: + _IMPORT_ERROR = None + +# ComfyUI model folder registration +QWEN3_ASR_ROOT = os.path.join(folder_paths.models_dir, "Qwen3-ASR") +os.makedirs(QWEN3_ASR_ROOT, exist_ok=True) +folder_paths.add_model_folder_path("Qwen3-ASR", QWEN3_ASR_ROOT) + +SUPPORTED_LANGUAGES = [ + "auto", + "Chinese", "English", "Cantonese", "Arabic", "German", "French", "Spanish", + "Portuguese", "Indonesian", "Italian", "Korean", "Russian", "Thai", + "Vietnamese", "Japanese", "Turkish", "Hindi", "Malay", "Dutch", "Swedish", + "Danish", "Finnish", "Polish", "Czech", "Filipino", "Persian", "Greek", + "Hungarian", "Macedonian", "Romanian", +] + +_ASR_MODEL_CACHE = {} +_CONFIG_CACHE = {"mtime": None, "data": None} + + +def _default_config(): + return { + "models": { + "Qwen/Qwen3-ASR-1.7B": "Qwen3-ASR-1.7B", + "Qwen/Qwen3-ASR-0.6B": "Qwen3-ASR-0.6B", + }, + "aligners": { + "None": None, + "Qwen/Qwen3-ForcedAligner-0.6B": "Qwen3-ForcedAligner-0.6B", + }, + "sources": ["HuggingFace", "ModelScope"], + "defaults": { + "repo_id": "Qwen/Qwen3-ASR-0.6B", + "source": "HuggingFace", + "precision": "bf16", + "attention": "auto", + "language": "auto", + "forced_aligner": "Qwen/Qwen3-ForcedAligner-0.6B", + }, + } + + +def _load_config(): + path = _CURRENT_DIR / "config.json" + try: + mtime = path.stat().st_mtime + except Exception: + mtime = None + + cache = _CONFIG_CACHE + if cache["data"] is not None and cache["mtime"] == mtime: + return cache["data"] + + data = _default_config() + if mtime is not None: + try: + import json + + loaded = json.loads(path.read_text(encoding="utf-8")) + if isinstance(loaded, dict): + data.update(loaded) + except Exception as e: + print(f"[Qwen3ASR] Failed to read config.json: {e}") + + cache["mtime"] = mtime + cache["data"] = data + return data + + +def _get_model_ids(): + models = _load_config().get("models") or {} + if isinstance(models, dict) and models: + return models + return _default_config()["models"] + + +def _get_aligner_ids(): + aligners = _load_config().get("aligners") or {} + if isinstance(aligners, dict) and aligners: + return aligners + return _default_config()["aligners"] + + +def _get_sources(): + sources = _load_config().get("sources") or [] + if isinstance(sources, list) and sources: + return sources + return _default_config()["sources"] + + +def _get_defaults(): + defaults = _load_config().get("defaults") or {} + if isinstance(defaults, dict) and defaults: + return defaults + return _default_config()["defaults"] +_EXTRA_MODEL_PATHS = None + + +def _normalize_paths(paths): + normalized = [] + for p in paths: + if not isinstance(p, str): + continue + p = p.strip() + if not p: + continue + normalized.append(os.path.normpath(os.path.expanduser(p))) + return normalized + + +def _extract_yaml_paths(data): + if not isinstance(data, dict): + return [] + + def split_paths(value): + if isinstance(value, str): + lines = [line.strip() for line in value.splitlines()] + return [line for line in lines if line] + if isinstance(value, list): + return [v for v in value if isinstance(v, str) and v.strip()] + return [] + + def is_abs(p): + if not p: + return False + if os.path.isabs(p): + return True + if len(p) > 1 and p[1] == ":": + return True + return False + + def pull(d): + found = [] + for key in ("paths", "roots", "folders", "models", "search_paths"): + value = d.get(key) + found.extend(split_paths(value)) + return found + + paths = [] + paths.extend(pull(data)) + for section in data.values(): + if not isinstance(section, dict): + continue + base_path = section.get("base_path") + if isinstance(base_path, str) and base_path.strip(): + paths.append(base_path) + for key, value in section.items(): + if key == "base_path" or key == "is_default": + continue + for item in split_paths(value): + if is_abs(item) or not isinstance(base_path, str): + paths.append(item) + else: + paths.append(os.path.join(base_path, item)) + return paths + + +def _load_extra_model_paths(): + global _EXTRA_MODEL_PATHS + if _EXTRA_MODEL_PATHS is not None: + return _EXTRA_MODEL_PATHS + + candidates = [] + try: + base_path = Path(getattr(folder_paths, "base_path", "")) + if base_path: + candidates.append(base_path / "extra_model_paths.yaml") + except Exception: + pass + + collected = [] + for path in candidates: + if not path.exists(): + continue + try: + import yaml + data = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + except Exception as e: + print(f"[Qwen3ASR] Failed to read {path}: {e}") + continue + collected.extend(_extract_yaml_paths(data)) + + normalized = [] + for p in _normalize_paths(collected): + if os.path.isdir(p) and p not in normalized: + normalized.append(p) + + _EXTRA_MODEL_PATHS = tuple(normalized) + return _EXTRA_MODEL_PATHS + + +def _find_local_model(repo_id: str) -> Optional[str]: + model_name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.split("/")[-1] + candidates = [] + + default_root = _model_storage_path(repo_id) + if os.path.isdir(default_root): + candidates.append(default_root) + + try: + asr_roots = folder_paths.get_folder_paths("Qwen3-ASR") or [] + for root in asr_roots: + candidates.append(os.path.join(root, model_name)) + except Exception: + pass + + for root in _load_extra_model_paths(): + candidates.append(os.path.join(root, model_name)) + candidates.append(os.path.join(root, "Qwen3-ASR", model_name)) + candidates.append(os.path.join(root, "ASR", "Qwen3-ASR", model_name)) + + for path in candidates: + if os.path.isdir(path) and os.listdir(path): + return path + return None + + +def _model_storage_path(repo_id: str) -> str: + name = _get_model_ids().get(repo_id) or _get_aligner_ids().get(repo_id) or repo_id.replace("/", "_") + return os.path.join(QWEN3_ASR_ROOT, name) + + +def _try_copy_cached(repo_id: str, target_dir: str) -> bool: + if os.path.isdir(target_dir) and os.listdir(target_dir): + return True + + hf_cache = os.path.join(Path.home(), ".cache", "huggingface", "hub") + hf_dir = os.path.join(hf_cache, f"models--{repo_id.replace('/', '--')}") + snapshots = os.path.join(hf_dir, "snapshots") + if os.path.isdir(snapshots): + entries = sorted(os.listdir(snapshots)) + if entries: + source = os.path.join(snapshots, entries[-1]) + try: + shutil.copytree(source, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + ms_cache = os.path.join(Path.home(), ".cache", "modelscope", "hub") + ms_dir = os.path.join(ms_cache, repo_id.replace("/", os.sep)) + if os.path.isdir(ms_dir): + try: + shutil.copytree(ms_dir, target_dir, dirs_exist_ok=True) + return True + except Exception: + return False + + return False + + +def _download_to_local(repo_id: str, source: str, target_dir: str) -> str: + os.makedirs(target_dir, exist_ok=True) + if source == "ModelScope": + try: + from modelscope import snapshot_download + except Exception as e: + raise RuntimeError("modelscope is required for ModelScope downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + else: + try: + from huggingface_hub import snapshot_download + except Exception as e: + raise RuntimeError("huggingface_hub is required for HuggingFace downloads") from e + snapshot_download(repo_id, local_dir=target_dir) + + return target_dir + + +def _normalize_audio(audio) -> Optional[Tuple[np.ndarray, int]]: + if audio is None: + return None + + waveform = audio.get("waveform") + sample_rate = audio.get("sample_rate") + if waveform is None or sample_rate is None: + return None + + wave = waveform[0] + if wave.ndim == 2 and wave.shape[0] > 1: + wave = torch.mean(wave, dim=0) + else: + wave = wave.squeeze(0) + + return (wave.detach().cpu().numpy().astype(np.float32), int(sample_rate)) + + +def _resolve_model_path(repo_id: str, source: str) -> str: + local_path = _find_local_model(repo_id) + if local_path: + return local_path + + target_dir = _model_storage_path(repo_id) + if os.path.isdir(target_dir) and os.listdir(target_dir): + return target_dir + + if _try_copy_cached(repo_id, target_dir): + return target_dir + + return _download_to_local(repo_id, source, target_dir) + + +def _build_dtype(precision: str, device: torch.device) -> torch.dtype: + if precision == "fp16": + return torch.float16 + if precision == "bf16": + if device.type == "mps": + return torch.float16 + return torch.bfloat16 + return torch.float32 + + +def _cache_key( + model_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str, + forced_aligner_path: str, + max_inference_batch_size: int, + max_new_tokens: int, +) -> tuple: + return ( + model_path, + str(dtype), + str(device), + attention, + forced_aligner_path or "", + int(max_inference_batch_size), + int(max_new_tokens), + ) + + +def _load_cached_model( + model_path: str, + dtype: torch.dtype, + device: torch.device, + attention: str, + forced_aligner_path: str, + max_inference_batch_size: int = 32, + max_new_tokens: int = 256, +): + key = _cache_key(model_path, dtype, device, attention, forced_aligner_path, max_inference_batch_size, max_new_tokens) + cached = _ASR_MODEL_CACHE.get(key) + if cached is not None: + return cached + + model_kwargs = { + "dtype": dtype, + "device_map": str(device), + "max_inference_batch_size": int(max_inference_batch_size), + "max_new_tokens": int(max_new_tokens), + } + if attention != "auto": + model_kwargs["attn_implementation"] = attention + if forced_aligner_path: + model_kwargs["forced_aligner"] = forced_aligner_path + model_kwargs["forced_aligner_kwargs"] = { + "dtype": dtype, + "device_map": str(device), + } + if attention != "auto": + model_kwargs["forced_aligner_kwargs"]["attn_implementation"] = attention + + model = Qwen3ASRModel.from_pretrained(model_path, **model_kwargs) + _ASR_MODEL_CACHE[key] = model + return model + + +def _format_srt_time(seconds: float) -> str: + total_ms = max(0, int(round(seconds * 1000))) + ms = total_ms % 1000 + total_s = total_ms // 1000 + s = total_s % 60 + total_m = total_s // 60 + m = total_m % 60 + h = total_m // 60 + return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}" + + +def _build_srt(time_stamps) -> str: + if not time_stamps: + return "" + lines = [] + for idx, item in enumerate(time_stamps, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(item.start_time)} --> {_format_srt_time(item.end_time)}") + lines.append(item.text or "") + lines.append("") + return "\n".join(lines).strip() + + +def _join_tokens(a: str, b: str) -> str: + if not a: + return b + if not b: + return a + # If either side contains CJK, join without space. + for ch in (a[-1], b[0]): + if "\u4e00" <= ch <= "\u9fff": + return f"{a}{b}" + return f"{a} {b}" + + +def _group_time_stamps(time_stamps, max_gap_sec: float, max_chars: int, split_mode: str): + if not time_stamps: + return [] + groups = [] + cur = None + punct = ("。", "!", "?", ".", "!", "?") + for item in time_stamps: + text = (item.text or "").strip() + if not text: + continue + if cur is None: + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + continue + + gap = float(item.start_time) - float(cur["end"]) + too_far = gap > max_gap_sec + too_long = max_chars > 0 and (len(cur["text"]) + len(text)) > max_chars + end_sentence = any(cur["text"].endswith(p) for p in punct) + + split_by_punct = split_mode in ("split_by_punctuation", "split_by_punctuation_or_length", "split_by_punctuation_or_pause", "split_by_punctuation_or_pause_or_length") + split_by_length = split_mode in ("split_by_length", "split_by_punctuation_or_length", "split_by_punctuation_or_pause_or_length") + split_by_pause = split_mode in ("split_by_pause", "split_by_punctuation_or_pause", "split_by_punctuation_or_pause_or_length") + + should_split = False + if split_by_punct and end_sentence: + should_split = True + if split_by_length and too_long: + should_split = True + if split_by_pause and too_far: + should_split = True + + if should_split: + groups.append(cur) + cur = { + "start": item.start_time, + "end": item.end_time, + "text": text, + } + else: + cur["text"] = _join_tokens(cur["text"], text).strip() + cur["end"] = item.end_time + + if cur is not None: + groups.append(cur) + return groups + + +def _build_srt_from_groups(groups) -> str: + if not groups: + return "" + lines = [] + for idx, g in enumerate(groups, start=1): + lines.append(str(idx)) + lines.append(f"{_format_srt_time(g['start'])} --> {_format_srt_time(g['end'])}") + lines.append(g["text"]) + lines.append("") + return "\n".join(lines).strip() + + +def _default_output_dir() -> str: + base = folder_paths.get_output_directory() + return os.path.join(base, "ComfyUI-QwenASR") + + +def _is_dir_path(path: str) -> bool: + if not path: + return False + if path.endswith(("/", "\\")): + return True + return os.path.isdir(path) + + +def _make_default_filename(ext: str) -> str: + stamp = time.strftime("%Y%m%d_%H%M%S") + return f"qwenasr_subtitle_{stamp}{ext}" + + +class AILab_Qwen3ASR: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("TEXT",) + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B", + precision="bf16", + language="auto", + hints="", + unload_models=True, + ): + if Qwen3ASRModel is None: + raise RuntimeError(f"qwen-asr not available: {_IMPORT_ERROR}") + + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + model_path = _resolve_model_path(model, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + return ("",) + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + model = _load_cached_model(model_path, dtype, device, "auto", "") + results = model.transcribe( + audio=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=False, + ) + + result = results[0] + text = result.text or "" + + if unload_models: + _ASR_MODEL_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text,) + + +class AILab_Qwen3ASRSubtitle: + @classmethod + def INPUT_TYPES(cls): + defaults = _get_defaults() + return { + "required": { + "audio": ("AUDIO", {"tooltip": "Audio input to transcribe."}), + }, + "optional": { + "model": (list(_get_model_ids().keys()), {"default": defaults.get("repo_id", "Qwen/Qwen3-ASR-0.6B"), "tooltip": "Choose the ASR model size."}), + "precision": (["bf16", "fp16", "fp32"], {"default": defaults.get("precision", "bf16"), "tooltip": "Inference precision."}), + "attention": (["auto", "flash_attention_2", "sdpa", "eager"], {"default": defaults.get("attention", "auto"), "tooltip": "Attention backend override."}), + "forced_aligner": (list(_get_aligner_ids().keys()), {"default": defaults.get("forced_aligner", "Qwen/Qwen3-ForcedAligner-0.6B"), "tooltip": "Forced aligner for timestamped subtitles."}), + "language": (SUPPORTED_LANGUAGES, {"default": defaults.get("language", "auto"), "tooltip": "Force language or auto-detect."}), + "hints": ("STRING", {"default": "", "multiline": True, "tooltip": "Optional hints/keywords (names, terms) to improve recognition."}), + "output_format": (["none", "txt", "srt"], {"default": "none", "tooltip": "File save format only (does not change subtitle output)."}), + "output_path": ("STRING", {"default": "", "multiline": False, "tooltip": "Optional output file path (relative goes to ComfyUI output)."}), + "split_mode": (["split_by_punctuation_or_pause_or_length", "split_by_punctuation_or_pause", "split_by_punctuation_or_length", "split_by_punctuation", "split_by_pause", "split_by_length"], {"default": "split_by_punctuation_or_pause_or_length", "tooltip": "Sentence splitting strategy."}), + "max_gap_sec": ("FLOAT", {"default": 0.6, "min": 0.0, "max": 8.0, "step": 0.1, "tooltip": "Max silence gap to keep the same sentence."}), + "max_chars": ("INT", {"default": 40, "min": 0, "max": 200, "tooltip": "Optional max characters per line (0 = no limit)."}), + "max_inference_batch_size": ("INT", {"default": 32, "min": 1, "max": 256, "tooltip": "Batch size for inference/alignment to avoid OOM."}), + "max_new_tokens": ("INT", {"default": 256, "min": 1, "max": 2048, "tooltip": "Max new tokens per chunk."}), + "unload_models": ("BOOLEAN", {"default": True, "tooltip": "Unload cached model after inference."}), + }, + } + + RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING") + RETURN_NAMES = ("TEXT", "SUBTITLES", "LANUGAGE", "OUTPUT_PATH") + FUNCTION = "transcribe" + CATEGORY = "🧪AILab/🎙️QwenASR" + + def transcribe( + self, + audio, + model="Qwen/Qwen3-ASR-0.6B", + precision="bf16", + attention="auto", + forced_aligner="Qwen/Qwen3-ForcedAligner-0.6B", + language="auto", + hints="", + output_format="none", + output_path="", + split_mode="split_by_punctuation_or_pause_or_length", + max_gap_sec=0.6, + max_chars=60, + max_inference_batch_size=32, + max_new_tokens=256, + unload_models=True, + ): + if Qwen3ASRModel is None: + raise RuntimeError(f"qwen-asr not available: {_IMPORT_ERROR}") + + device = model_management.get_torch_device() + dtype = _build_dtype(precision, device) + + source = _get_defaults().get("source", "HuggingFace") + model_path = _resolve_model_path(model, source) + + forced_aligner_path = "" + if forced_aligner and forced_aligner != "None": + forced_aligner_path = _resolve_model_path(forced_aligner, source) + + audio_data = _normalize_audio(audio) + if audio_data is None: + return ("", "", "") + + lang = None if language == "auto" else language + ctx = hints.strip() if isinstance(hints, str) else "" + + model = _load_cached_model( + model_path, + dtype, + device, + attention, + forced_aligner_path, + max_inference_batch_size=max_inference_batch_size, + max_new_tokens=max_new_tokens, + ) + results = model.transcribe( + audio=audio_data, + language=lang, + context=ctx if ctx else None, + return_time_stamps=True, + ) + + result = results[0] + text = result.text or "" + detected_lang = result.language or "" + subtitles = "" + file_path = "" + time_stamps = getattr(result, "time_stamps", None) + groups = _group_time_stamps(time_stamps, max_gap_sec=max_gap_sec, max_chars=max_chars, split_mode=split_mode) + # Always build subtitle output + lines = [] + for g in groups: + lines.append(f"{g['start']:.2f}-{g['end']:.2f}: {g['text']}") + subtitles = "\n".join(lines) if lines else "" + + # Optional file save + if output_format != "none": + out_path = (output_path or "").strip() + if not os.path.isabs(out_path): + if out_path == "": + out_path = _default_output_dir() + out_path = os.path.join(folder_paths.get_output_directory(), out_path) + + if _is_dir_path(out_path): + ext = ".srt" if output_format == "srt" else ".txt" + out_path = os.path.join(out_path, _make_default_filename(ext)) + else: + root, ext = os.path.splitext(out_path) + if not ext: + ext = ".srt" if output_format == "srt" else ".txt" + out_path = root + ext + os.makedirs(os.path.dirname(out_path), exist_ok=True) + if output_format == "srt": + file_content = _build_srt_from_groups(groups) + else: + file_content = subtitles + with open(out_path, "w", encoding="utf-8") as f: + f.write(file_content) + file_path = out_path + + if unload_models: + _ASR_MODEL_CACHE.clear() + try: + model_management.soft_empty_cache() + except Exception: + pass + + return (text, subtitles, detected_lang, file_path) + + +NODE_CLASS_MAPPINGS = { + "AILab_Qwen3ASR": AILab_Qwen3ASR, + "AILab_Qwen3ASRSubtitle": AILab_Qwen3ASRSubtitle, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "AILab_Qwen3ASR": "ASR (QwenASR)", + "AILab_Qwen3ASRSubtitle": "Subtitle (QwenASR)", +} diff --git a/docs/hel-892/structure-reference/qwen-history.json b/docs/hel-892/structure-reference/qwen-history.json new file mode 100644 index 00000000..2ca01313 --- /dev/null +++ b/docs/hel-892/structure-reference/qwen-history.json @@ -0,0 +1 @@ +[{"sha":"aaf40688c93c8e083f8a47d9107e6f95405ea7c9","node_id":"C_kwDORFFwbNoAKGFhZjQwNjg4YzkzYzhlMDgzZjhhNDdkOTEwN2U2Zjk1NDA1ZWE3Yzk","commit":{"author":{"name":"AI Lab","email":"129358391+1038lab@users.noreply.github.com","date":"2026-09-12T00:32:38Z"},"committer":{"name":"GitHub","email":"noreply@github.com","date":"2026-09-12T00:32:38Z"},"message":"Add files via upload","tree":{"sha":"82a937ccea4ca78baf5de8d59f1848b711ceea29","url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/git/trees/82a937ccea4ca78baf5de8d59f1848b711ceea29"},"url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/git/commits/aaf40688c93c8e083f8a47d9107e6f95405ea7c9","comment_count":0,"verification":{"verified":true,"reason":"valid","signature":"-----BEGIN PGP SIGNATURE-----\n\nwsFcBAABCAAQBQJqpJ2mCRC1aQ7uu5UhlAAALz8QABDDKd4v/a71GUBJbpZ4dM2C\nBczmJO1F/I7jGfz9WDnZO31QGmfqXrVR/hH7BPZrJdhwjTZSfrJO7DJ+Iy6K/t0Y\nlaQz1GPRNnxBDzo13iH9yx5X6PXmYerqMIP4WkuSpvt9B4UURL8l2YNARPwVPutl\nz/QmH9nCX/aGCeAFJJn9zYuGVfMaFYzOzZqopAOu6NXmf/yIFMp8taQCsd3imUMZ\nyL9LpwegsoXKmySm8tXFZqq+1ykWlSkdkln2jLpYvx51j7wSXSbFC4k3twHDwLOb\nhLDc+Wv5H4ZJSzQ58mA/neERPxTIvY3l67Z8qRsYlqwOjdn0pr+p/Ss1aettSIB/\nYqVadYW4R1IMu/31VzF0C3BeVONPPdK2disqTr1V2Zh/uWTbggn2H8S70Rl7qP5Y\nYX1fZ79/1LHZY/HPvxKAzATP/tJq8Y48tmpHtSA2YZzJAKKOMUvZ0eTSWdkIyVhP\n8uH3qXmww/QJH4qRCdiI1YL0opujh3Pl4SJ0k1QW9xVg8nAkmxcZcKzRPKHHBI6P\nhNSVszv0FT6Rhua4ViIvkQLkTdEtmLDI1buqU4ZKTIppiyk63hhQY2XygUTKwmbv\n1Rm9UkK2HX6zML40rW2bMNAH76bEtc4VejgRR5T+FCe9aEoYFw1g7wu5vV/sCzvM\nOQGVF9Gj+9Zdc1eodpyQ\n=d5Qo\n-----END PGP SIGNATURE-----\n","payload":"tree 82a937ccea4ca78baf5de8d59f1848b711ceea29\nparent a180ab2ec4943920472cb4729ce0793fbfb99768\nauthor AI Lab <129358391+1038lab@users.noreply.github.com> 1789173158 -0700\ncommitter GitHub 1789173158 -0700\n\nAdd files via upload","verified_at":"2026-09-12T00:32:42Z"}},"url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/aaf40688c93c8e083f8a47d9107e6f95405ea7c9","html_url":"https://github.com/1038lab/ComfyUI-QwenASR/commit/aaf40688c93c8e083f8a47d9107e6f95405ea7c9","comments_url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/aaf40688c93c8e083f8a47d9107e6f95405ea7c9/comments","author":{"login":"1038lab","id":129358391,"node_id":"U_kgDOB7XaNw","avatar_url":"https://avatars.githubusercontent.com/u/129358391?v=4","gravatar_id":"","url":"https://api.github.com/users/1038lab","html_url":"https://github.com/1038lab","followers_url":"https://api.github.com/users/1038lab/followers","following_url":"https://api.github.com/users/1038lab/following{/other_user}","gists_url":"https://api.github.com/users/1038lab/gists{/gist_id}","starred_url":"https://api.github.com/users/1038lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/1038lab/subscriptions","organizations_url":"https://api.github.com/users/1038lab/orgs","repos_url":"https://api.github.com/users/1038lab/repos","events_url":"https://api.github.com/users/1038lab/events{/privacy}","received_events_url":"https://api.github.com/users/1038lab/received_events","type":"User","user_view_type":"public","site_admin":false},"committer":{"login":"web-flow","id":19864447,"node_id":"MDQ6VXNlcjE5ODY0NDQ3","avatar_url":"https://avatars.githubusercontent.com/u/19864447?v=4","gravatar_id":"","url":"https://api.github.com/users/web-flow","html_url":"https://github.com/web-flow","followers_url":"https://api.github.com/users/web-flow/followers","following_url":"https://api.github.com/users/web-flow/following{/other_user}","gists_url":"https://api.github.com/users/web-flow/gists{/gist_id}","starred_url":"https://api.github.com/users/web-flow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/web-flow/subscriptions","organizations_url":"https://api.github.com/users/web-flow/orgs","repos_url":"https://api.github.com/users/web-flow/repos","events_url":"https://api.github.com/users/web-flow/events{/privacy}","received_events_url":"https://api.github.com/users/web-flow/received_events","type":"User","user_view_type":"public","site_admin":false},"parents":[{"sha":"a180ab2ec4943920472cb4729ce0793fbfb99768","url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/a180ab2ec4943920472cb4729ce0793fbfb99768","html_url":"https://github.com/1038lab/ComfyUI-QwenASR/commit/a180ab2ec4943920472cb4729ce0793fbfb99768"}]},{"sha":"b037d7be121111a1ba6f40a4d99f6b43ac6411b6","node_id":"C_kwDORFFwbNoAKGIwMzdkN2JlMTIxMTExYTFiYTZmNDBhNGQ5OWY2YjQzYWM2NDExYjY","commit":{"author":{"name":"AI Lab","email":"129358391+1038lab@users.noreply.github.com","date":"2026-01-30T23:31:21Z"},"committer":{"name":"GitHub","email":"noreply@github.com","date":"2026-01-30T23:31:21Z"},"message":"Add files via upload","tree":{"sha":"0bfd06c6c6099e7178b41622321e13db86f19f52","url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/git/trees/0bfd06c6c6099e7178b41622321e13db86f19f52"},"url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/git/commits/b037d7be121111a1ba6f40a4d99f6b43ac6411b6","comment_count":0,"verification":{"verified":true,"reason":"valid","signature":"-----BEGIN PGP SIGNATURE-----\n\nwsFcBAABCAAQBQJpfT9KCRC1aQ7uu5UhlAAAcioQAJoztSPElxpfba6EkwsdWaMB\nVLwQNKhvXjSqDWAhyCSbcaZiCCsKKXDQtfkXOoahtLwTIZDmguNNQ9sqGZLvmyEZ\ni/dAV3m9oFGTLIc8sKzZ0dcd1PWiC6xMlWG9l+qCIxfonIgXo4ieOddIyp5t69Bv\nQdaunkwuNGsnOSX0vgqyIQsP/+ujV71OlpJc6yQBmPUt5hGOLGRtuTPeOvl+beWA\n4HQjh8vIcM8TC8brA3DsuSUq68VGOG6Z/WVtdPmRwDTLLN19uhGzlERsQxwPcvBN\nGydD+CTlkInevq4gO3Y+qldxZb9NrputzselHaqo9U4Uu6AAB1kan5mFid1YBKkI\nGo6oBVYjMtgOGMl4g6NUuRJN9Z1v/4afMZ8LAXMSdcyiqWaJTmOY0cKNysE8L4+f\nzKTMgkgjIXIlbY8X9puwIN9KEwK1W8gI0YBLyspX0P/TuEJZmKjCgvFQvsk5KHTk\nVKDdoUUi54smZKl42D+S/brvI5x3wY+jmbmOl2Z+bmlyNWIdb8X91ZepIxVgVY87\n4UbXNhIMG69BjDCevo4Su5RmkxIRodhcFkrn+Xoy7+NK1oh0CFsDuO4yUOvCj9qL\nt9SMHsIWPEfAXFZK7mnt9Iys88zqZqrlPhFHkXtc6zQQKt/nvBYj4MtwHuQdmmoW\ncen0Y1ohPAtaImsnRU6l\n=qMQk\n-----END PGP SIGNATURE-----\n","payload":"tree 0bfd06c6c6099e7178b41622321e13db86f19f52\nparent 0d0e2c3246dda754337c84ee5661ce6469dd000d\nauthor AI Lab <129358391+1038lab@users.noreply.github.com> 1769815881 -0800\ncommitter GitHub 1769815881 -0800\n\nAdd files via upload","verified_at":"2026-01-30T23:31:22Z"}},"url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/b037d7be121111a1ba6f40a4d99f6b43ac6411b6","html_url":"https://github.com/1038lab/ComfyUI-QwenASR/commit/b037d7be121111a1ba6f40a4d99f6b43ac6411b6","comments_url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/comments","author":{"login":"1038lab","id":129358391,"node_id":"U_kgDOB7XaNw","avatar_url":"https://avatars.githubusercontent.com/u/129358391?v=4","gravatar_id":"","url":"https://api.github.com/users/1038lab","html_url":"https://github.com/1038lab","followers_url":"https://api.github.com/users/1038lab/followers","following_url":"https://api.github.com/users/1038lab/following{/other_user}","gists_url":"https://api.github.com/users/1038lab/gists{/gist_id}","starred_url":"https://api.github.com/users/1038lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/1038lab/subscriptions","organizations_url":"https://api.github.com/users/1038lab/orgs","repos_url":"https://api.github.com/users/1038lab/repos","events_url":"https://api.github.com/users/1038lab/events{/privacy}","received_events_url":"https://api.github.com/users/1038lab/received_events","type":"User","user_view_type":"public","site_admin":false},"committer":{"login":"web-flow","id":19864447,"node_id":"MDQ6VXNlcjE5ODY0NDQ3","avatar_url":"https://avatars.githubusercontent.com/u/19864447?v=4","gravatar_id":"","url":"https://api.github.com/users/web-flow","html_url":"https://github.com/web-flow","followers_url":"https://api.github.com/users/web-flow/followers","following_url":"https://api.github.com/users/web-flow/following{/other_user}","gists_url":"https://api.github.com/users/web-flow/gists{/gist_id}","starred_url":"https://api.github.com/users/web-flow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/web-flow/subscriptions","organizations_url":"https://api.github.com/users/web-flow/orgs","repos_url":"https://api.github.com/users/web-flow/repos","events_url":"https://api.github.com/users/web-flow/events{/privacy}","received_events_url":"https://api.github.com/users/web-flow/received_events","type":"User","user_view_type":"public","site_admin":false},"parents":[{"sha":"0d0e2c3246dda754337c84ee5661ce6469dd000d","url":"https://api.github.com/repos/1038lab/ComfyUI-QwenASR/commits/0d0e2c3246dda754337c84ee5661ce6469dd000d","html_url":"https://github.com/1038lab/ComfyUI-QwenASR/commit/0d0e2c3246dda754337c84ee5661ce6469dd000d"}]}] \ No newline at end of file diff --git a/docs/hel-892/structure-reference/sources.json b/docs/hel-892/structure-reference/sources.json new file mode 100644 index 00000000..e017c3eb --- /dev/null +++ b/docs/hel-892/structure-reference/sources.json @@ -0,0 +1,1574 @@ +{ + "authority": "public_reference_only_not_object_info", + "sources": [ + { + "id": "1.37.11:LICENSE", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "LICENSE", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/LICENSE", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:07:21.290052+00:00", + "local_file": "1.37.11__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.37.11:src/extensions/core/widgetInputs.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/extensions/core/widgetInputs.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/widgetInputs.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/widgetInputs.ts", + "sha256": "488d38eb209816778a6da8cb8f734f539e3fbd7f77aae41ec649a52b8764b613", + "retrieved_at": "2026-10-29T16:07:19.603227+00:00", + "local_file": "1.37.11__src__extensions__core__widgetInputs.ts", + "lines": [ + [ + 1, + 614 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 43, + 63 + ], + [ + 165, + 185 + ], + [ + 207, + 227 + ], + [ + 216, + 236 + ], + [ + 283, + 303 + ] + ] + }, + { + "id": "1.37.11:src/utils/executionUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/utils/executionUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/utils/executionUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/utils/executionUtil.ts", + "sha256": "4e51bc54e35cb7ac9bb7cba418a74ccdd5974f640b9b088aa4ae7668f746ab36", + "retrieved_at": "2026-10-29T16:07:19.311746+00:00", + "local_file": "1.37.11__src__utils__executionUtil.ts", + "lines": [ + [ + 1, + 150 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 27, + 47 + ], + [ + 35, + 55 + ], + [ + 66, + 86 + ], + [ + 111, + 131 + ] + ] + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "fd2e19a6b8f4369e6e97d79f407cc1bec130feec9d6d3c979cc03b0a556f249f", + "retrieved_at": "2026-10-29T16:07:19.345109+00:00", + "local_file": "1.37.11__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts", + "lines": [ + [ + 1, + 408 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 113, + 133 + ], + [ + 128, + 148 + ], + [ + 130, + 150 + ], + [ + 142, + 162 + ], + [ + 152, + 172 + ], + [ + 207, + 227 + ], + [ + 216, + 236 + ], + [ + 229, + 249 + ], + [ + 236, + 256 + ], + [ + 250, + 270 + ], + [ + 260, + 280 + ], + [ + 283, + 303 + ], + [ + 302, + 322 + ], + [ + 307, + 327 + ], + [ + 395, + 408 + ], + [ + 402, + 408 + ] + ] + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/Subgraph.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/lib/litegraph/src/subgraph/Subgraph.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/Subgraph.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2", + "retrieved_at": "2026-10-29T16:07:18.500082+00:00", + "local_file": "1.37.11__src__lib__litegraph__src__subgraph__Subgraph.ts", + "lines": [ + [ + 1, + 3 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.37.11:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "d4f1017495158a6133ff770441a4d517dfbf2a328ba42b0405f8729853fe8209", + "retrieved_at": "2026-10-29T16:07:19.709548+00:00", + "local_file": "1.37.11__src__lib__litegraph__src__subgraph__SubgraphNode.ts", + "lines": [ + [ + 1, + 645 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 474, + 494 + ], + [ + 511, + 531 + ] + ] + }, + { + "id": "1.37.11:src/lib/litegraph/src/LLink.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/lib/litegraph/src/LLink.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/LLink.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/LLink.ts", + "sha256": "1d58845322b30f122aeafb23ca286ca7349ca23215469f96afb7a98fd6596af4", + "retrieved_at": "2026-10-29T16:07:18.923708+00:00", + "local_file": "1.37.11__src__lib__litegraph__src__LLink.ts", + "lines": [ + [ + 1, + 491 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 186, + 206 + ], + [ + 351, + 371 + ] + ] + }, + { + "id": "1.48.7:LICENSE", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "LICENSE", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/LICENSE", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:07:19.261645+00:00", + "local_file": "1.48.7__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.48.7:src/extensions/core/widgetInputs.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/extensions/core/widgetInputs.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/extensions/core/widgetInputs.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/extensions/core/widgetInputs.ts", + "sha256": "fdceceedc727e8a696f273a810fc39a075004a09ea793e0df51418f96ac52a61", + "retrieved_at": "2026-10-29T16:07:21.009938+00:00", + "local_file": "1.48.7__src__extensions__core__widgetInputs.ts", + "lines": [ + [ + 1, + 617 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 46, + 66 + ], + [ + 134, + 154 + ], + [ + 286, + 306 + ] + ] + }, + { + "id": "1.48.7:src/utils/executionUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/utils/executionUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/utils/executionUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/utils/executionUtil.ts", + "sha256": "264e11395f28880603e7f9fe36d2e61c74cd59d6d88be990225cce8510e3f816", + "retrieved_at": "2026-10-29T16:07:20.897286+00:00", + "local_file": "1.48.7__src__utils__executionUtil.ts", + "lines": [ + [ + 1, + 160 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 26, + 46 + ], + [ + 34, + 54 + ], + [ + 76, + 96 + ], + [ + 121, + 141 + ] + ] + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "64baa71b46bd67440b032e18e4d9aebb67a6cc135fe7c4509ae1b5bc25acc2a3", + "retrieved_at": "2026-10-29T16:07:19.957713+00:00", + "local_file": "1.48.7__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts", + "lines": [ + [ + 1, + 429 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 113, + 133 + ], + [ + 128, + 148 + ], + [ + 130, + 150 + ], + [ + 142, + 162 + ], + [ + 152, + 172 + ], + [ + 211, + 231 + ], + [ + 220, + 240 + ], + [ + 233, + 253 + ], + [ + 240, + 260 + ], + [ + 254, + 274 + ], + [ + 264, + 284 + ], + [ + 290, + 310 + ], + [ + 295, + 315 + ], + [ + 310, + 330 + ], + [ + 323, + 343 + ], + [ + 328, + 348 + ], + [ + 386, + 406 + ], + [ + 416, + 429 + ], + [ + 423, + 429 + ] + ] + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/Subgraph.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/lib/litegraph/src/subgraph/Subgraph.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/Subgraph.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2", + "retrieved_at": "2026-10-29T16:07:20.030602+00:00", + "local_file": "1.48.7__src__lib__litegraph__src__subgraph__Subgraph.ts", + "lines": [ + [ + 1, + 3 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.48.7:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "822b0cdde3fe6a096f82310075a6285ae967dc58d760f19d743442ea20f4f15f", + "retrieved_at": "2026-10-29T16:07:20.331227+00:00", + "local_file": "1.48.7__src__lib__litegraph__src__subgraph__SubgraphNode.ts", + "lines": [ + [ + 1, + 948 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 284, + 304 + ], + [ + 783, + 803 + ], + [ + 815, + 835 + ] + ] + }, + { + "id": "1.48.7:src/lib/litegraph/src/LLink.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "tag": "v1.48.7", + "file": "src/lib/litegraph/src/LLink.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/LLink.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/6d6af63c00f132cd25dc29307fc56bd2c094fa22/src/lib/litegraph/src/LLink.ts", + "sha256": "9e9c92acacd5edc58a9c1ad2b3ba66679f27ebda28da74765947d88ce11df656", + "retrieved_at": "2026-10-29T16:07:21.404972+00:00", + "local_file": "1.48.7__src__lib__litegraph__src__LLink.ts", + "lines": [ + [ + 1, + 507 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 198, + 218 + ], + [ + 363, + 383 + ] + ] + }, + { + "id": "1.53.6:LICENSE", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "LICENSE", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/LICENSE", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:07:20.729422+00:00", + "local_file": "1.53.6__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.53.6:src/extensions/core/widgetInputs.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/extensions/core/widgetInputs.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/extensions/core/widgetInputs.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/extensions/core/widgetInputs.ts", + "sha256": "f6b3d33b9ffdf4f68136ee0f72d03dabf4affa3292721d1f221b47de792e0daf", + "retrieved_at": "2026-10-29T16:07:21.234026+00:00", + "local_file": "1.53.6__src__extensions__core__widgetInputs.ts", + "lines": [ + [ + 1, + 675 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 55, + 75 + ], + [ + 203, + 223 + ], + [ + 363, + 383 + ] + ] + }, + { + "id": "1.53.6:src/utils/executionUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/utils/executionUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/utils/executionUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/utils/executionUtil.ts", + "sha256": "b29fd312e66c7415fa4c720654ac121dc67600b0c1fedf079b6575a174960698", + "retrieved_at": "2026-10-29T16:07:21.285281+00:00", + "local_file": "1.53.6__src__utils__executionUtil.ts", + "lines": [ + [ + 1, + 192 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 57, + 77 + ], + [ + 65, + 85 + ], + [ + 107, + 127 + ], + [ + 153, + 173 + ] + ] + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "0c0ca487822a9f86324925c2fb4ea59c6c032ad5d042a83ac367cb15196454fe", + "retrieved_at": "2026-10-29T16:07:21.876495+00:00", + "local_file": "1.53.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts", + "lines": [ + [ + 1, + 431 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 113, + 133 + ], + [ + 128, + 148 + ], + [ + 130, + 150 + ], + [ + 142, + 162 + ], + [ + 152, + 172 + ], + [ + 213, + 233 + ], + [ + 222, + 242 + ], + [ + 235, + 255 + ], + [ + 242, + 262 + ], + [ + 256, + 276 + ], + [ + 266, + 286 + ], + [ + 292, + 312 + ], + [ + 297, + 317 + ], + [ + 312, + 332 + ], + [ + 325, + 345 + ], + [ + 330, + 350 + ], + [ + 388, + 408 + ], + [ + 418, + 431 + ], + [ + 425, + 431 + ] + ] + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/Subgraph.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/lib/litegraph/src/subgraph/Subgraph.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/Subgraph.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2", + "retrieved_at": "2026-10-29T16:07:21.660465+00:00", + "local_file": "1.53.6__src__lib__litegraph__src__subgraph__Subgraph.ts", + "lines": [ + [ + 1, + 3 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.53.6:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "29f2da27396bcc426180d819549f654278d65de973ade651d57c4905e319fb9c", + "retrieved_at": "2026-10-29T16:07:22.529324+00:00", + "local_file": "1.53.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts", + "lines": [ + [ + 1, + 1025 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 834, + 854 + ], + [ + 866, + 886 + ] + ] + }, + { + "id": "1.53.6:src/lib/litegraph/src/LLink.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "tag": "v1.53.6", + "file": "src/lib/litegraph/src/LLink.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/LLink.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1/src/lib/litegraph/src/LLink.ts", + "sha256": "562694d5bccb5682222c500a7e7069501eeb94e69eeb1b9a534d1e511902ef57", + "retrieved_at": "2026-10-29T16:07:22.910443+00:00", + "local_file": "1.53.6__src__lib__litegraph__src__LLink.ts", + "lines": [ + [ + 1, + 730 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 308, + 328 + ], + [ + 473, + 493 + ] + ] + }, + { + "id": "1.48.6:LICENSE", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "LICENSE", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/LICENSE", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:07:22.286018+00:00", + "local_file": "1.48.6__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.48.6:src/extensions/core/widgetInputs.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/extensions/core/widgetInputs.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/extensions/core/widgetInputs.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/extensions/core/widgetInputs.ts", + "sha256": "fdceceedc727e8a696f273a810fc39a075004a09ea793e0df51418f96ac52a61", + "retrieved_at": "2026-10-29T16:07:22.623001+00:00", + "local_file": "1.48.6__src__extensions__core__widgetInputs.ts", + "lines": [ + [ + 1, + 617 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 46, + 66 + ], + [ + 134, + 154 + ], + [ + 286, + 306 + ] + ] + }, + { + "id": "1.48.6:src/utils/executionUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/utils/executionUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/utils/executionUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/utils/executionUtil.ts", + "sha256": "264e11395f28880603e7f9fe36d2e61c74cd59d6d88be990225cce8510e3f816", + "retrieved_at": "2026-10-29T16:07:23.370458+00:00", + "local_file": "1.48.6__src__utils__executionUtil.ts", + "lines": [ + [ + 1, + 160 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 26, + 46 + ], + [ + 34, + 54 + ], + [ + 76, + 96 + ], + [ + 121, + 141 + ] + ] + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/ExecutableNodeDTO.ts", + "sha256": "64baa71b46bd67440b032e18e4d9aebb67a6cc135fe7c4509ae1b5bc25acc2a3", + "retrieved_at": "2026-10-29T16:07:22.082570+00:00", + "local_file": "1.48.6__src__lib__litegraph__src__subgraph__ExecutableNodeDTO.ts", + "lines": [ + [ + 1, + 429 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 113, + 133 + ], + [ + 128, + 148 + ], + [ + 130, + 150 + ], + [ + 142, + 162 + ], + [ + 152, + 172 + ], + [ + 211, + 231 + ], + [ + 220, + 240 + ], + [ + 233, + 253 + ], + [ + 240, + 260 + ], + [ + 254, + 274 + ], + [ + 264, + 284 + ], + [ + 290, + 310 + ], + [ + 295, + 315 + ], + [ + 310, + 330 + ], + [ + 323, + 343 + ], + [ + 328, + 348 + ], + [ + 386, + 406 + ], + [ + 416, + 429 + ], + [ + 423, + 429 + ] + ] + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/Subgraph.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/lib/litegraph/src/subgraph/Subgraph.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/Subgraph.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/Subgraph.ts", + "sha256": "321403ca3ba2faa0b448dec6e8bf379e49ddea4bfbe8619547d29926e30d62d2", + "retrieved_at": "2026-10-29T16:07:22.327946+00:00", + "local_file": "1.48.6__src__lib__litegraph__src__subgraph__Subgraph.ts", + "lines": [ + [ + 1, + 3 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1.48.6:src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/subgraph/SubgraphNode.ts", + "sha256": "822b0cdde3fe6a096f82310075a6285ae967dc58d760f19d743442ea20f4f15f", + "retrieved_at": "2026-10-29T16:07:23.017656+00:00", + "local_file": "1.48.6__src__lib__litegraph__src__subgraph__SubgraphNode.ts", + "lines": [ + [ + 1, + 948 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 284, + 304 + ], + [ + 783, + 803 + ], + [ + 815, + 835 + ] + ] + }, + { + "id": "1.48.6:src/lib/litegraph/src/LLink.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "7b4172a243e0d43f1679c0be1c307560cd83c00d", + "tag": "v1.48.6", + "file": "src/lib/litegraph/src/LLink.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/LLink.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/7b4172a243e0d43f1679c0be1c307560cd83c00d/src/lib/litegraph/src/LLink.ts", + "sha256": "9e9c92acacd5edc58a9c1ad2b3ba66679f27ebda28da74765947d88ce11df656", + "retrieved_at": "2026-10-29T16:07:22.817345+00:00", + "local_file": "1.48.6__src__lib__litegraph__src__LLink.ts", + "lines": [ + [ + 1, + 507 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 198, + 218 + ], + [ + 363, + 383 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/extensions/core/previewAny.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/extensions/core/previewAny.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/previewAny.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/previewAny.ts", + "sha256": "2b19989ac8a3c26e198c7db7f7e2210936b0a4f4d3b26183917baafb841c1874", + "retrieved_at": "2026-10-29T16:08:26.105360+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__extensions__core__previewAny.ts", + "lines": [ + [ + 1, + 83 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 14, + 34 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/extensions/core/uploadAudio.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/extensions/core/uploadAudio.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/uploadAudio.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/extensions/core/uploadAudio.ts", + "sha256": "0a11f1ad5651d238130bc06aca2a4b31a41f8bec98d0f8512e02ffb42b262e66", + "retrieved_at": "2026-10-29T16:08:27.591044+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__extensions__core__uploadAudio.ts", + "lines": [ + [ + 1, + 411 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 97, + 117 + ], + [ + 171, + 191 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/widgets.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/scripts/widgets.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/widgets.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/widgets.ts", + "sha256": "e8bb428cbf69635015de43a4ebc89817b3443f876cbed52eeafe67d26f2398d8", + "retrieved_at": "2026-10-29T16:08:32.809386+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__scripts__widgets.ts", + "lines": [ + [ + 1, + 308 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/app.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "tag": "v1.37.11", + "file": "src/scripts/app.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/app.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/app.ts", + "sha256": "e57985f7d365abb035bc2fc755a8f5b10efbca97a7dcb5b2a4a05bcbc78b9d5c", + "retrieved_at": "2026-10-29T16:08:26.344991+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__scripts__app.ts", + "lines": [ + [ + 1, + 1744 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 707, + 727 + ] + ] + }, + { + "id": "1038lab/ComfyUI-QwenASR:AILab_QwenASR.py", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "3f9a652a617e578e4e3bd090e3dbc75274bf4775", + "tag": null, + "file": "AILab_QwenASR.py", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/3f9a652a617e578e4e3bd090e3dbc75274bf4775/AILab_QwenASR.py", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/3f9a652a617e578e4e3bd090e3dbc75274bf4775/AILab_QwenASR.py", + "sha256": "f8cda2d0d39517f93ace1a73263146a4bea59a02604e58919a05393c45ade6b7", + "retrieved_at": "2026-10-29T16:08:27.381292+00:00", + "local_file": "ComfyUI-QwenASR__3f9a652a__AILab_QwenASR.py", + "lines": [ + [ + 1, + 1178 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 1021, + 1041 + ], + [ + 1170, + 1178 + ] + ] + }, + { + "id": "1038lab/ComfyUI-QwenASR:__init__.py", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "3f9a652a617e578e4e3bd090e3dbc75274bf4775", + "tag": null, + "file": "__init__.py", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/3f9a652a617e578e4e3bd090e3dbc75274bf4775/__init__.py", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/3f9a652a617e578e4e3bd090e3dbc75274bf4775/__init__.py", + "sha256": "0919008142c12f8fe9a12671a1ca1de548ded128dd7287a13f6230d9729b47c2", + "retrieved_at": "2026-10-29T16:08:26.416537+00:00", + "local_file": "ComfyUI-QwenASR__3f9a652a____init__.py", + "lines": [ + [ + 1, + 46 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 17, + 37 + ], + [ + 30, + 46 + ], + [ + 31, + 46 + ], + [ + 41, + 46 + ], + [ + 45, + 46 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI:LICENSE", + "repository": "https://github.com/Comfy-Org/ComfyUI", + "commit": "09725967cf76304371c390ca1d6483e04061da48", + "tag": "v0.11.0", + "file": "LICENSE", + "url": "https://github.com/Comfy-Org/ComfyUI/blob/09725967cf76304371c390ca1d6483e04061da48/LICENSE", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI/09725967cf76304371c390ca1d6483e04061da48/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:08:30.364951+00:00", + "local_file": "ComfyUI__09725967__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "Comfy-Org/ComfyUI:comfy_extras/nodes_audio.py", + "repository": "https://github.com/Comfy-Org/ComfyUI", + "commit": "09725967cf76304371c390ca1d6483e04061da48", + "tag": "v0.11.0", + "file": "comfy_extras/nodes_audio.py", + "url": "https://github.com/Comfy-Org/ComfyUI/blob/09725967cf76304371c390ca1d6483e04061da48/comfy_extras/nodes_audio.py", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI/09725967cf76304371c390ca1d6483e04061da48/comfy_extras/nodes_audio.py", + "sha256": "d47eefe226c273f20561545f6a664bfdfa5c193cec7178c925b5dc5ccb642a9c", + "retrieved_at": "2026-10-29T16:08:27.580667+00:00", + "local_file": "ComfyUI__09725967__comfy_extras__nodes_audio.py", + "lines": [ + [ + 1, + 693 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 261, + 281 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI:comfy_extras/nodes_preview_any.py", + "repository": "https://github.com/Comfy-Org/ComfyUI", + "commit": "09725967cf76304371c390ca1d6483e04061da48", + "tag": "v0.11.0", + "file": "comfy_extras/nodes_preview_any.py", + "url": "https://github.com/Comfy-Org/ComfyUI/blob/09725967cf76304371c390ca1d6483e04061da48/comfy_extras/nodes_preview_any.py", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI/09725967cf76304371c390ca1d6483e04061da48/comfy_extras/nodes_preview_any.py", + "sha256": "f8c526dbc4ec512f88a067524865f59eb24db636858f37d601e848885b2d0751", + "retrieved_at": "2026-10-29T16:08:26.942084+00:00", + "local_file": "ComfyUI__09725967__comfy_extras__nodes_preview_any.py", + "lines": [ + [ + 1, + 44 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 38, + 44 + ] + ] + }, + { + "id": "qwen-history:aaf40688c93c8e083f8a47d9107e6f95405ea7c9", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "aaf40688c93c8e083f8a47d9107e6f95405ea7c9", + "file": "AILab_QwenASR.py", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/aaf40688c93c8e083f8a47d9107e6f95405ea7c9/AILab_QwenASR.py", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/aaf40688c93c8e083f8a47d9107e6f95405ea7c9/AILab_QwenASR.py", + "sha256": "f8cda2d0d39517f93ace1a73263146a4bea59a02604e58919a05393c45ade6b7", + "retrieved_at": "2026-10-29T16:10:11.713162+00:00", + "local_file": "qwen-aaf40688.py", + "lines": [ + [ + 1, + 1178 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 1021, + 1041 + ], + [ + 1170, + 1178 + ] + ] + }, + { + "id": "qwen-history:b037d7be121111a1ba6f40a4d99f6b43ac6411b6", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "b037d7be121111a1ba6f40a4d99f6b43ac6411b6", + "file": "AILab_QwenASR.py", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/AILab_QwenASR.py", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/AILab_QwenASR.py", + "sha256": "af7721c1015fef8cb40a724226fb0f720397d70fb1ce367f9145a3b653dd0cd9", + "retrieved_at": "2026-10-29T16:10:12.250828+00:00", + "local_file": "qwen-b037d7be.py", + "lines": [ + [ + 1, + 723 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 582, + 602 + ], + [ + 715, + 723 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/utils/nodeDefUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/utils/nodeDefUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/utils/nodeDefUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/utils/nodeDefUtil.ts", + "sha256": "9c62901804e584a2e9d7e17e7914475113e41993c44df3d063f0027e95735dc1", + "retrieved_at": "2026-10-29T16:13:51.456781+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__utils__nodeDefUtil.ts", + "lines": [ + [ + 1, + 140 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 120, + 140 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/renderer/extensions/vueNodes/widgets/composables/useStringWidget.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/renderer/extensions/vueNodes/widgets/composables/useStringWidget.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/renderer/extensions/vueNodes/widgets/composables/useStringWidget.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/renderer/extensions/vueNodes/widgets/composables/useStringWidget.ts", + "sha256": "b734a2584d558de501150e8011e1c16031f33778c2cd3b4c712f296ce4f05396", + "retrieved_at": "2026-10-29T16:13:51.087516+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useStringWidget.ts", + "lines": [ + [ + 1, + 137 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:packages/shared-frontend-utils/src/formatUtil.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "packages/shared-frontend-utils/src/formatUtil.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/packages/shared-frontend-utils/src/formatUtil.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/packages/shared-frontend-utils/src/formatUtil.ts", + "sha256": "7313418fe3a92aae99f2ef91f081257c2b2162b1578155d7346f2f03ab440039", + "retrieved_at": "2026-10-29T16:13:50.781246+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__packages__shared-frontend-utils__src__formatUtil.ts", + "lines": [ + [ + 1, + 552 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/scripts/domWidget.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/scripts/domWidget.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/domWidget.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/scripts/domWidget.ts", + "sha256": "34ec3c58d6b236f4e99bfa0c82dcab8e15c6a6b51c6dcb9ace30e37d1a395800", + "retrieved_at": "2026-10-29T16:13:50.749834+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__scripts__domWidget.ts", + "lines": [ + [ + 1, + 394 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 142, + 162 + ], + [ + 331, + 351 + ] + ] + }, + { + "id": "Comfy-Org/ComfyUI_frontend:src/lib/litegraph/src/LGraphNode.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/lib/litegraph/src/LGraphNode.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/LGraphNode.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/LGraphNode.ts", + "sha256": "706225a8a06cd7929f9e04fe2388bcdb8f158cdac756c65c45657c020ab7b319", + "retrieved_at": "2026-10-29T16:13:51.698692+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__LGraphNode.ts", + "lines": [ + [ + 1, + 4198 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1038lab/ComfyUI-QwenASR:LICENSE", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "b037d7be121111a1ba6f40a4d99f6b43ac6411b6", + "file": "LICENSE", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/LICENSE", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/LICENSE", + "sha256": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986", + "retrieved_at": "2026-10-29T16:13:51.110734+00:00", + "local_file": "ComfyUI-QwenASR__b037d7be__LICENSE", + "lines": [ + [ + 1, + 674 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "1038lab/ComfyUI-QwenASR:__init__.py", + "repository": "https://github.com/1038lab/ComfyUI-QwenASR", + "commit": "b037d7be121111a1ba6f40a4d99f6b43ac6411b6", + "file": "__init__.py", + "url": "https://github.com/1038lab/ComfyUI-QwenASR/blob/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/__init__.py", + "raw_url": "https://raw.githubusercontent.com/1038lab/ComfyUI-QwenASR/b037d7be121111a1ba6f40a4d99f6b43ac6411b6/__init__.py", + "sha256": "e35f18c3986ee7b00a918ed644e375bc7cee1b88f740cc52fd93b45ace621a41", + "retrieved_at": "2026-10-29T16:13:50.803612+00:00", + "local_file": "ComfyUI-QwenASR__b037d7be____init__.py", + "lines": [ + [ + 1, + 42 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 10, + 30 + ], + [ + 32, + 42 + ], + [ + 33, + 42 + ], + [ + 42, + 42 + ] + ] + }, + { + "id": "ComfyUI_frontend:src/lib/litegraph/src/widgets/BaseWidget.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/lib/litegraph/src/widgets/BaseWidget.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/widgets/BaseWidget.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/widgets/BaseWidget.ts", + "sha256": "6a77b402bbf8c67b9ea2ce58de28c61a1b17da82bb437c29565fb260b721b8c7", + "retrieved_at": "2026-10-29T16:17:10.818937+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__BaseWidget.ts", + "lines": [ + [ + 1, + 349 + ] + ], + "target_version_match": "unknown", + "rule_locations": [ + [ + 100, + 120 + ] + ] + }, + { + "id": "ComfyUI_frontend:src/lib/litegraph/src/widgets/LegacyWidget.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/lib/litegraph/src/widgets/LegacyWidget.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/widgets/LegacyWidget.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/lib/litegraph/src/widgets/LegacyWidget.ts", + "sha256": "05d098254988191736f1c72f7efc57e3f350d97c82267a97f0b8c193d65daa96", + "retrieved_at": "2026-10-29T16:17:10.541363+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__lib__litegraph__src__widgets__LegacyWidget.ts", + "lines": [ + [ + 1, + 40 + ] + ], + "target_version_match": "unknown" + }, + { + "id": "ComfyUI_frontend:src/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget.ts", + "repository": "https://github.com/Comfy-Org/ComfyUI_frontend", + "commit": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "file": "src/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget.ts", + "url": "https://github.com/Comfy-Org/ComfyUI_frontend/blob/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget.ts", + "raw_url": "https://raw.githubusercontent.com/Comfy-Org/ComfyUI_frontend/4bf6a1960028cc5cda57d48f9fb01a74dfaade43/src/renderer/extensions/vueNodes/widgets/composables/useBooleanWidget.ts", + "sha256": "36f477f75561e0c7bfc2c6757906724f8ff2c8660ace26759f3f07493877fece", + "retrieved_at": "2026-10-29T16:17:10.836088+00:00", + "local_file": "ComfyUI_frontend__4bf6a196__src__renderer__extensions__vueNodes__widgets__composables__useBooleanWidget.ts", + "lines": [ + [ + 1, + 31 + ] + ], + "target_version_match": "unknown" + } + ] +} diff --git a/docs/hel-892/structure-reference/tag-1.37.11.json b/docs/hel-892/structure-reference/tag-1.37.11.json new file mode 100644 index 00000000..c3c2b676 --- /dev/null +++ b/docs/hel-892/structure-reference/tag-1.37.11.json @@ -0,0 +1 @@ +{"ref":"refs/tags/v1.37.11","node_id":"REF_kwDOMIrOxrJyZWZzL3RhZ3MvdjEuMzcuMTE","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/refs/tags/v1.37.11","object":{"sha":"4bf6a1960028cc5cda57d48f9fb01a74dfaade43","type":"commit","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/commits/4bf6a1960028cc5cda57d48f9fb01a74dfaade43"}} \ No newline at end of file diff --git a/docs/hel-892/structure-reference/tag-1.48.6.json b/docs/hel-892/structure-reference/tag-1.48.6.json new file mode 100644 index 00000000..1878d0ed --- /dev/null +++ b/docs/hel-892/structure-reference/tag-1.48.6.json @@ -0,0 +1 @@ +{"ref":"refs/tags/v1.48.6","node_id":"REF_kwDOMIrOxrFyZWZzL3RhZ3MvdjEuNDguNg","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/refs/tags/v1.48.6","object":{"sha":"7b4172a243e0d43f1679c0be1c307560cd83c00d","type":"commit","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/commits/7b4172a243e0d43f1679c0be1c307560cd83c00d"}} \ No newline at end of file diff --git a/docs/hel-892/structure-reference/tag-1.48.7.json b/docs/hel-892/structure-reference/tag-1.48.7.json new file mode 100644 index 00000000..42fedfbe --- /dev/null +++ b/docs/hel-892/structure-reference/tag-1.48.7.json @@ -0,0 +1 @@ +{"ref":"refs/tags/v1.48.7","node_id":"REF_kwDOMIrOxrFyZWZzL3RhZ3MvdjEuNDguNw","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/refs/tags/v1.48.7","object":{"sha":"6d6af63c00f132cd25dc29307fc56bd2c094fa22","type":"commit","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/commits/6d6af63c00f132cd25dc29307fc56bd2c094fa22"}} \ No newline at end of file diff --git a/docs/hel-892/structure-reference/tag-1.53.6.json b/docs/hel-892/structure-reference/tag-1.53.6.json new file mode 100644 index 00000000..b3ffe22a --- /dev/null +++ b/docs/hel-892/structure-reference/tag-1.53.6.json @@ -0,0 +1 @@ +{"ref":"refs/tags/v1.53.6","node_id":"REF_kwDOMIrOxrFyZWZzL3RhZ3MvdjEuNTMuNg","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/refs/tags/v1.53.6","object":{"sha":"7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1","type":"commit","url":"https://api.github.com/repos/Comfy-Org/ComfyUI_frontend/git/commits/7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1"}} \ No newline at end of file diff --git a/docs/hel-892/structure-reference/versions.json b/docs/hel-892/structure-reference/versions.json new file mode 100644 index 00000000..626cf2c1 --- /dev/null +++ b/docs/hel-892/structure-reference/versions.json @@ -0,0 +1,6 @@ +{ + "1.37.11": "4bf6a1960028cc5cda57d48f9fb01a74dfaade43", + "1.48.7": "6d6af63c00f132cd25dc29307fc56bd2c094fa22", + "1.53.6": "7d533a4cd4c4904ffdb0537f6b80ae9793dd62f1", + "1.48.6": "7b4172a243e0d43f1679c0be1c307560cd83c00d" +} \ No newline at end of file