OdinSamKit
OdinSamKit — reusable ComfyUI node UI helpers (sections, collapse, dynamic I/O visibility)
OdinSamKit
Reusable ComfyUI node UI toolkit — section collapse, value-based visibility, and dynamic I/O (real add/remove ports).
Business logic does not belong here. Business packs treat this kit as an optional enhancement.
Features (v0.2.2)
| Feature | Strategy | Description |
|--------|----------|-------------|
| Section titles + collapse | hide widgets/inputs | Click header to expand/collapse a group |
| State memory | node.properties | Collapse state saved with the workflow |
| Value visibility | hide | Show/hide by another widget’s value |
| Link-chain inputs | add / remove only | Connect a → then b appears (FormatPaths-style). Not hide. |
| Count-sync outputs | add / remove | Sync path_1…N outputs to a count widget |
| Count-sync widgets | hide | Sync template_1…N visibility (safe for widgets_values) |
| Count buttons | UI only | Declarative + / - that change the count |
| Labels (default) | display only | Static labels map; optional labelFrom: "upstreamTitle" → 定位目录(a) |
| Labels (custom) | override hook | OdinSamKit.registerLabelResolver(type, fn) for special nodes |
| Demo nodes | — | Sections demo + Dynamic I/O demo |
Important: hide vs add/remove
- Link-chain and count-sync outputs use
addInput/removeInput/addOutput/removeOutput. - Do not expect “connect a → show b” to work via
hidden=true. That was explicitly rejected for FormatPaths-like UX (node height must shrink; empty slots must not linger).
Install
cd ComfyUI/custom_nodes
git clone <your-repo-url> OdinSamKit
Restart ComfyUI. Console check:
window.OdinSamKit.version // "0.2.2"
Nodes:
- OdinSamKit Demo (Sections)
- OdinSamKit Demo (Dynamic I/O)
Dynamic I/O quick demo
- Add OdinSamKit Demo (Dynamic I/O).
- Only
ashould exist at first; connect something toa→bis created (not un-hidden). - Use + out / - out →
path_Noutputs andtemplate_Nwidgets followpath_count. - Labels such as
Slot A (a)come from thelabelsmap.
Config schema (new fields)
{
"version": 1,
"labels": {
"a": "Locate dir (a)",
"path_1": "Path 1"
},
"linkChains": [
{
"side": "input",
"letters": "a-z",
"type": "*",
"min": 1,
"labelFrom": "upstreamTitle",
"labelFormat": "{title}({name})"
}
],
"countSync": [
{
"watch": "path_count",
"min": 1,
"max": 16,
"outputs": {
"prefix": "path_",
"type": "STRING",
"start": 1,
"labelPrefix": "path "
},
"widgets": {
"prefix": "template_",
"start": 1,
"labelPrefix": "template "
}
}
],
"countButtons": [
{
"watch": "path_count",
"plusLabel": "+ out",
"minusLabel": "- out",
"hideWatch": true
}
],
"sections": [],
"visibility": []
}
linkChains.names can replace letters if you need non-letter port names.
Sections + countSync
If template_N (or any widget) is listed in both sections[].widgets and countSync[].widgets, visibility is:
section expanded ∧ count allows (not “section expanded ⇒ show all”).
Section header placement
- Has
widgets→ header is inserted before the first existing widget. - Inputs-only section (no widgets) → header is placed at the top of the widget area (after other
osk_*headers/buttons, before business widgets). Declare sections in visual order.
Link-chain inputs + section collapse
If sections[].inputs lists names that also belong to linkChains, collapse uses removeInput (unlinked) / keep+hide (linked)—not unreliable input.hidden alone. Expand runs normal link-chain sync again.
Slot labels (most nodes vs special nodes)
Priority: custom resolver → upstreamTitle (if enabled) → static labels → raw name.
Internal name stays a (templates still use {a}); only the visible label changes.
Most nodes (KIT default):
"labels": { "a": "Part a" },
"linkChains": [{ "letters": "a-z", "labelFrom": "upstreamTitle" }]
- Disconnected: show static label (or
a) - Connected: show
UpstreamTitle(a)
Special nodes (self-controlled):
window.OdinSamKit.registerLabelResolver("FormatPaths", (ctx) => {
// return a string to override; return null to use KIT default
if (ctx.side === "input" && ctx.upstreamTitle) {
return `${ctx.upstreamTitle}(${ctx.slotName})`;
}
return null;
});
Embed with the same markers as v0.1:
@@ODINSAM_KIT@@
{...json...}
@@/ODINSAM_KIT@@
Or from OdinSamKit.kit import embed_kit_config.
Python side tips (for FormatPaths-like nodes)
- Declare chain ports as optional
forceInputinINPUT_TYPES(a–z, etc.). - Pre-declare enough
RETURN_TYPES/template_Nfor the max count. - Let KIT remove unused UI slots; execution still sees optional kwargs only when linked.
- If the node also ships its own dynamic JS, do not manage the same ports twice — prefer KIT or migrate the node JS onto these primitives.
Layout
web/
odinsam_kit.js
core/ # apply_kit, constants, widget utils, global API
convention/ # config parse
sections/ # collapse + state
visibility/ # value-based hide
dynamic/ # link_chain, count_sync, labels, count_buttons
css/
License
MIT (see project metadata).