comfy-ts 2.9.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +6 -4
  2. package/dist/{LogsSt-DFxzQfDc.js → LogsSt-qtFzOKpu.js} +2 -2
  3. package/dist/{LogsSt-DFxzQfDc.js.map → LogsSt-qtFzOKpu.js.map} +1 -1
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +102 -3
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +19 -0
  8. package/dist/index.d.ts +19 -0
  9. package/dist/index.js +102 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-_nrvJYyt.js → run-serve-BK7BA2dn.js} +91 -3
  12. package/dist/run-serve-BK7BA2dn.js.map +1 -0
  13. package/dist/{run-tui-BLEdTsOX.js → run-tui-CQyvMf0N.js} +36 -4
  14. package/dist/run-tui-CQyvMf0N.js.map +1 -0
  15. package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-DjjEtwfx.js} +176 -2
  16. package/dist/schemaDrift-DjjEtwfx.js.map +1 -0
  17. package/dist/serve-web.js +32 -16
  18. package/dist/{state-BbgJeCe6.js → state--wrz0BQc.js} +23 -5
  19. package/dist/state--wrz0BQc.js.map +1 -0
  20. package/dist/web.d.ts +19 -0
  21. package/dist/web.js +102 -3
  22. package/dist/web.js.map +1 -1
  23. package/examples/README.md +1 -0
  24. package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
  25. package/examples/comfy-cloud/ltx25-i2v.cflow.ts +152 -0
  26. package/examples/comfy-cloud/ltx25-t2v.cflow.ts +126 -0
  27. package/examples/comfy-cloud/minimax-music3-t2a.cflow.ts +95 -0
  28. package/examples/comfy-cloud/sdk.d.ts +30724 -24404
  29. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
  30. package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
  31. package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
  32. package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -2
  33. package/examples/rvion/08-qwen-image-21-t2i.cflow.ts +64 -0
  34. package/examples/rvion/09-qwen-image-21-edit.cflow.ts +83 -0
  35. package/package.json +4 -2
  36. package/src/cli/serve/ServeApp.ts +94 -0
  37. package/src/cli/serve/describeVar.ts +7 -0
  38. package/src/cli/serve/favicon.ts +3 -0
  39. package/src/cli/serve/web/api.ts +12 -0
  40. package/src/cli/serve/web/components/VarsForm.tsx +18 -7
  41. package/src/cli/serve/web/components/controls/LorasControl.tsx +102 -6
  42. package/src/cli/serve/web/state/WebSt.ts +79 -0
  43. package/src/cli/serve/web/state/loraSort.ts +39 -0
  44. package/src/cli/serve/web/styles.ts +15 -0
  45. package/src/cli/tui/components/Header.tsx +2 -0
  46. package/src/cli/tui/state/HostSt.ts +34 -0
  47. package/src/graph/ComfyNode.ts +19 -3
  48. package/src/host/ComfyHost.ts +15 -0
  49. package/src/host/loraInfoCache.ts +64 -0
  50. package/src/host/loraManagerApi.ts +27 -0
  51. package/src/host/schemaDrift.ts +87 -0
  52. package/dist/DefinedWorkflow-BatWaZO1.js.map +0 -1
  53. package/dist/run-serve-_nrvJYyt.js.map +0 -1
  54. package/dist/run-tui-BLEdTsOX.js.map +0 -1
  55. package/dist/state-BbgJeCe6.js.map +0 -1
package/README.md CHANGED
@@ -448,8 +448,10 @@ Start with the didactic sequence in [`examples/rvion/`](examples/rvion/):
448
448
  | [`05-comfy-cloud`](examples/rvion/05-comfy-cloud.cflow.ts) | the same code on Comfy Cloud: `url` + `apiKey` host, typechecked against the committed catalog SDK |
449
449
  | [`06-qwen-image-edit`](examples/rvion/06-qwen-image-edit.cflow.ts) | Qwen Image Edit 2511, lightning 4-step lora toggle |
450
450
  | [`07-local-llm-text-gen`](examples/rvion/07-local-llm-text-gen.cflow.ts) | a local LLM through core `TextGenerate`, text back in `execution.text`; `--sweep` probes every text encoder on the host |
451
+ | [`08-qwen-image-21-t2i`](examples/rvion/08-qwen-image-21-t2i.cflow.ts) | Qwen Image 2.1 text to image: int8 model, Qwen3-VL 8b encoder |
452
+ | [`09-qwen-image-21-edit`](examples/rvion/09-qwen-image-21-edit.cflow.ts) | Qwen Image 2.1 edit: the reference image feeds an autogrow slot, output keeps its size; a remove-background preset |
451
453
 
452
- ### The model zoo: 46 cloud workflows, 32 model families
454
+ ### The model zoo: 49 cloud workflows, 34 model families
453
455
 
454
456
  [`examples/comfy-cloud/`](examples/comfy-cloud/) holds one runnable example per family × mode (`<family>-<mode>.cflow.ts`), each transcribed from the official ComfyUI template of that model, typechecked against the committed cloud catalog, and runnable on [Comfy Cloud](https://cloud.comfy.org) with one env var (`COMFY_CLOUD_API_KEY`). Image, video and audio:
455
457
 
@@ -457,9 +459,9 @@ Start with the didactic sequence in [`examples/rvion/`](examples/rvion/):
457
459
  | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
458
460
  | **t2i** text→image | sd15 (= example 05), sdxl, sd35, flux1, flux2, qwen-image, z-image, chroma, hidream, omnigen2, kandinsky5, capybara, krea2, lens, ernie, longcat, ovis, pixeldit, anima, newbie, ideogram4 |
459
461
  | **i2i** image edit | flux1, flux2, qwen-image, hidream, omnigen2, capybara, longcat, boogu, firered |
460
- | **t2v** text→video | wan21, wan22, wan22-5b, ltxv, hunyuan-video, kandinsky5 |
461
- | **i2v** image→video | wan21, wan22, ltxv, hunyuan-video, kandinsky5, capybara, svd |
462
- | **t2a** text→audio | ace-step (song), stable-audio (sfx/music), chatterbox (tts) |
462
+ | **t2v** text→video | wan21, wan22, wan22-5b, ltxv, ltx25 (with sound), hunyuan-video, kandinsky5 |
463
+ | **i2v** image→video | wan21, wan22, ltxv, ltx25 (with sound), hunyuan-video, kandinsky5, capybara, svd |
464
+ | **t2a** text→audio | ace-step (song), minimax-music3 (song), stable-audio (sfx/music), chatterbox (tts) |
463
465
 
464
466
  Every zoo file imports offline and headless (no key, no cache needed — CI proves it), builds a validated graph, and doubles as a TUI app with typed knobs: prompt, seed, steps, size, input image, …
465
467
 
@@ -1,4 +1,4 @@
1
- import { B as stripAnsi, V as extractErrorMessage, t as DefinedWorkflow } from "./DefinedWorkflow-BatWaZO1.js";
1
+ import { J as stripAnsi, Y as extractErrorMessage, a as DefinedWorkflow } from "./schemaDrift-DjjEtwfx.js";
2
2
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, join } from "pathe";
4
4
  import { makeAutoObservable, reaction, runInAction } from "mobx";
@@ -578,4 +578,4 @@ var LogsSt = class {
578
578
  //#endregion
579
579
  export { draftsDirForFile as a, buildFileRows as c, mergeWorkflowSources as d, scanCflowFiles as f, draftKeyForFile as i, familyOf as l, assembleLogChunks as n, listDraftsForFile as o, DraftsSt as r, assignFamilyColors as s, LogsSt as t, findDefinedWorkflow as u };
580
580
 
581
- //# sourceMappingURL=LogsSt-DFxzQfDc.js.map
581
+ //# sourceMappingURL=LogsSt-qtFzOKpu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LogsSt-DFxzQfDc.js","names":[],"sources":["../src/cli/tui/discoverWorkflows.ts","../src/cli/tui/findDefinedWorkflow.ts","../src/cli/tui/treeRows.ts","../src/cli/tui/state/DraftsSt.ts","../src/utils/mojibake.ts","../src/cli/tui/state/LogsSt.ts"],"sourcesContent":["import { readdirSync } from 'node:fs'\nimport { join } from 'pathe'\n\n/**\n * recursive scan for the workflow-module naming convention. Entries BELOW a\n * node_modules segment are skipped: packaged examples arrive via\n * bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would\n * otherwise list them twice, un-deduped, as the user's own files), and\n * third-party packages shipping *.cflow.ts are not this project's workflows. A\n * scan root that is ITSELF inside node_modules still works (the filter is\n * relative to the root).\n */\nexport function scanCflowFiles(dir: string): string[] {\n const hits = readdirSync(dir, { recursive: true })\n .map((f) => String(f))\n .filter((f) => !f.split('/').includes('node_modules'))\n .map((f) => join(dir, f))\n .filter((f) => f.endsWith('.cflow.ts') || f.endsWith('.cflow.tsx'))\n return hits.sort()\n}\n\nexport type WorkflowDiscovery = {\n /** every module the tree lists, user files first, bundled examples last */\n files: string[]\n /** the subset that came from the PACKAGED examples (grouped apart in the tree) */\n bundled: Set<string>\n}\n\n/**\n * PURE merge of the scan with the packaged examples (headless-tested). An\n * explicit target keeps its scope only. Bundled files ALWAYS group under the\n * bundled section, also when the scan already found them (repo dev: ./examples\n * is under cwd) — dedupe relies on the caller passing realpath-normalized\n * strings on both sides.\n */\nexport function mergeWorkflowSources(p: {\n explicitTarget: boolean\n scanned: string[]\n bundledFiles: string[]\n}): WorkflowDiscovery {\n if (p.explicitTarget) return { files: p.scanned, bundled: new Set() }\n const bundled = new Set(p.bundledFiles)\n const userFiles = p.scanned.filter((f) => !bundled.has(f))\n return { files: [...userFiles, ...p.bundledFiles], bundled }\n}\n","import { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'\n\n/**\n * instanceof first; duck-type fallback covers a second copy of the library in\n * the module graph (linked dev setups, npm dedupe misses)\n */\nexport function findDefinedWorkflow(mod: Record<string, unknown>): DefinedWorkflow | null {\n const isDefined = (x: unknown): x is DefinedWorkflow =>\n x instanceof DefinedWorkflow ||\n (typeof x === 'object' &&\n x != null &&\n 'spec' in x &&\n typeof (x as DefinedWorkflow).run === 'function' &&\n typeof (x as DefinedWorkflow).entries === 'function')\n return [mod.default, ...Object.values(mod)].find(isDefined) ?? null\n}\n","import { basename, dirname } from 'pathe'\n\n/**\n * PURE tree-shaping layer under TreeSt (headless-tested): turns the flat\n * discovered file list into hierarchy rows (directory nodes + files), applies\n * the `/` substring filter, and owns the per-family color assignment.\n */\n\nexport type FileTreeRow =\n | { kind: 'dir'; path: string; label: string; depth: number; expanded: boolean }\n | { kind: 'file'; file: string; name: string; depth: number }\n\n/** module display name — also the drafts folder key (DraftsSt delegates here) */\nexport function moduleName(file: string): string {\n return basename(file).replace(/\\.cflow\\.tsx?$/, '')\n}\n\n/** the color word: everything before the first `-` (`flux1-i2i` → `flux1`) */\nexport function familyOf(name: string): string {\n const dash = name.indexOf('-')\n return dash === -1 ? name : name.slice(0, dash)\n}\n\n/** hue-spread so CONSECUTIVE families land on clearly distinct colors */\nexport const FAMILY_PALETTE: string[] = [\n '#61afef', // blue\n '#e5c07b', // amber\n '#c678dd', // magenta\n '#98c379', // green\n '#e06c75', // rose\n '#56b6c2', // teal\n '#d19a66', // orange\n '#a5b4fc', // lavender\n '#a5e075', // lime\n '#f28fad', // pink\n]\n\n/** family → color, palette cycled in first-appearance order over the FULL\n * (unfiltered) file list — stable while filtering/folding */\nexport function assignFamilyColors(files: string[]): Map<string, string> {\n const colors = new Map<string, string>()\n for (const file of files) {\n const family = familyOf(moduleName(file))\n if (colors.has(family)) continue\n colors.set(family, FAMILY_PALETTE[colors.size % FAMILY_PALETTE.length] ?? '#61afef')\n }\n return colors\n}\n\ntype DirNode = {\n /** deepest real directory path of this node (unique row key) */\n path: string\n label: string\n files: string[]\n dirs: Map<string, DirNode>\n}\n\nfunction commonDir(files: string[]): string {\n const first = files[0]\n if (first == null) return ''\n let prefix = dirname(first).split('/')\n for (const f of files.slice(1)) {\n const segs = dirname(f).split('/')\n let i = 0\n while (i < prefix.length && i < segs.length && prefix[i] === segs[i]) i++\n prefix = prefix.slice(0, i)\n }\n return prefix.join('/')\n}\n\nfunction insert(root: DirNode, rootDir: string, file: string): void {\n const rel = dirname(file).slice(rootDir.length).replace(/^\\//, '')\n const segs = rel === '' ? [] : rel.split('/')\n let node = root\n for (const seg of segs) {\n let child = node.dirs.get(seg)\n if (child == null) {\n child = { path: `${node.path}/${seg}`, label: seg, files: [], dirs: new Map() }\n node.dirs.set(seg, child)\n }\n node = child\n }\n node.files.push(file)\n}\n\n/** a dir holding NOTHING but one subdir shows as one `a/b` row */\nfunction mergeChains(node: DirNode): void {\n // snapshot: the loop rewrites node.dirs entries while iterating\n const entries = [...node.dirs]\n for (const [key, child] of entries) {\n mergeChains(child)\n if (child.files.length === 0 && child.dirs.size === 1) {\n const only = [...child.dirs.values()][0]!\n const label = `${child.label}/${only.label}`\n node.dirs.delete(key)\n // re-key by the MERGED label: keying by only.label could clobber a\n // real sibling dir of the same name (segments never contain '/')\n node.dirs.set(label, { ...only, label })\n }\n }\n}\n\nfunction matches(file: string, rootDir: string, filter: string): boolean {\n if (filter === '') return true\n // dir path + module name, NOT the raw filename: '.cflow.ts' matching\n // everything would make the filter useless for 'ts', 'flow', '.'\n const haystack = `${dirname(file).slice(rootDir.length)}/${moduleName(file)}`.toLowerCase()\n return haystack.includes(filter.toLowerCase())\n}\n\nfunction emit(p: {\n node: DirNode\n depth: number\n rootDir: string\n collapsedDirs: Set<string>\n filter: string\n out: FileTreeRow[]\n}): void {\n for (const file of p.node.files) {\n if (!matches(file, p.rootDir, p.filter)) continue\n p.out.push({ kind: 'file', file, name: moduleName(file), depth: p.depth })\n }\n for (const dir of [...p.node.dirs.values()].sort((a, b) => a.label.localeCompare(b.label))) {\n const kept: FileTreeRow[] = []\n // a collapsed dir still ignores its fold while a filter narrows the tree\n const expanded = p.filter !== '' || !p.collapsedDirs.has(dir.path)\n emit({ ...p, node: dir, depth: p.depth + 1, out: kept })\n if (p.filter !== '' && kept.length === 0) continue // prune filtered-empty dirs\n p.out.push({ kind: 'dir', path: dir.path, label: dir.label, depth: p.depth, expanded })\n if (expanded) p.out.push(...kept)\n }\n}\n\n/**\n * hierarchy rows over the discovered files: user files under their common\n * root, packaged examples LAST under one foldable 'comfy-ts examples' node.\n */\nexport function buildFileRows(p: {\n userFiles: string[]\n bundledFiles: string[]\n collapsedDirs: Set<string>\n filter: string\n}): FileTreeRow[] {\n const out: FileTreeRow[] = []\n if (p.userFiles.length > 0) {\n const rootDir = commonDir(p.userFiles)\n const root: DirNode = { path: rootDir, label: '', files: [], dirs: new Map() }\n for (const f of p.userFiles) insert(root, rootDir, f)\n mergeChains(root)\n emit({ node: root, depth: 0, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out })\n }\n if (p.bundledFiles.length > 0) {\n const rootDir = commonDir(p.bundledFiles)\n const root: DirNode = { path: rootDir, label: 'comfy-ts examples', files: [], dirs: new Map() }\n for (const f of p.bundledFiles) insert(root, rootDir, f)\n mergeChains(root)\n const kept: FileTreeRow[] = []\n const expanded = p.filter !== '' || !p.collapsedDirs.has(rootDir)\n emit({ node: root, depth: 1, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out: kept })\n if (p.filter !== '' && kept.length === 0) return out\n out.push({ kind: 'dir', path: rootDir, label: root.label, depth: 0, expanded })\n if (expanded) out.push(...kept)\n }\n return out\n}\n","import {\n copyFileSync,\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n renameSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { makeAutoObservable, reaction } from 'mobx'\nimport { dirname, join } from 'pathe'\nimport { moduleName } from 'src/cli/tui/treeRows.ts'\nimport { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'\nimport type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'\n\n/** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */\nexport function draftKeyForFile(file: string): string {\n return moduleName(file)\n}\n\nexport function draftsDirForFile(file: string): string {\n return comfyts.resolveFromDrafts(draftKeyForFile(file))\n}\n\nfunction listDraftsInDir(dir: string): string[] {\n if (!existsSync(dir)) return []\n return readdirSync(dir)\n .filter((f) => f.endsWith('.json'))\n .map((f) => f.slice(0, -'.json'.length))\n .sort()\n}\n\n/** draft names stored for a workflow module (fs read — pair with DraftsSt.version for reactivity) */\nexport function listDraftsForFile(file: string): string[] {\n return listDraftsInDir(draftsDirForFile(file))\n}\n\n/**\n * named var-value snapshots at `.comfy-ts/drafts/<module-basename>/<name>.json`\n * (LOCAL state, gitignored). The active draft autosaves debounced; the TUI is\n * ALWAYS in a draft (`default` unless another one is activated).\n */\nexport class DraftsSt {\n constructor(private st: TuiSt) {\n makeAutoObservable<DraftsSt, 'st'>(this, { st: false })\n // active-draft autosave: var values + draft name are observable\n this.st.disposers.push(\n reaction(\n () => (this.active == null ? null : JSON.stringify(this.snapshot())),\n (json) => {\n if (json != null && this.active != null) this.write(this.active, json)\n },\n { delay: 300 },\n ),\n )\n }\n\n /** ALWAYS set after construction; null only transiently while activate() loads values */\n active: string | null = null\n list: string[] = []\n ix: number = 0\n /** bumped on every fs write/rename so fs-derived getters (tree rows) recompute */\n version: number = 0\n\n private get dir(): string {\n const cur = this.st.workflows.currentPath\n return cur != null ? draftsDirForFile(cur) : comfyts.resolveFromDrafts(this.st.wf.spec.id ?? 'workflow')\n }\n\n private snapshot(): Record<string, unknown> {\n // toJSON so seed persists {mode, value}; other vars round-trip their value\n return Object.fromEntries(this.st.entries.map(([k, varDef]) => [k, varDef.toJSON()]))\n }\n\n private write(name: string, json: string): void {\n const path = join(this.dir, `${name}.json`)\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, json)\n this.version++\n }\n\n /** module key of the currently loaded workflow (settings.lastDraft is keyed by it) */\n private get moduleKey(): string {\n return this.st.moduleKey\n }\n\n /** switch to a draft: load its stored values when the file exists, else it starts from current values */\n activate(name: string): void {\n this.active = null // the autosave expression must not see old values under the new name\n const path = join(this.dir, `${name}.json`)\n if (existsSync(path)) {\n try {\n const values: Record<string, unknown> = JSON.parse(readFileSync(path, 'utf8'))\n for (const [k, varDef] of this.st.entries) if (k in values) varDef.loadJSON(values[k])\n } catch (e) {\n this.st.exec.error = extractErrorMessage(e)\n }\n }\n this.active = name\n this.st.settings.rememberDraft(this.moduleKey, name)\n }\n\n /** open the draft this workflow was last in (settings), else 'default' */\n activateRemembered(): void {\n const remembered = this.st.settings.lastDraft[this.moduleKey]\n if (remembered != null && remembered !== 'default' && existsSync(join(this.dir, `${remembered}.json`)))\n this.activate(remembered)\n else this.activate('default')\n }\n\n /** every workflow starts in a draft; kept for callers that want 'default' explicitly */\n activateDefault(): void {\n this.activate('default')\n }\n\n // ---- draft CRUD (also drives the tree's draft rows — `file` overrides the target workflow) ----\n\n private dirFor(file: string | undefined): string {\n return file != null ? draftsDirForFile(file) : this.dir\n }\n\n /** true when ops on `file` touch the ACTIVE draft bookkeeping */\n private isCurrent(file: string | undefined): boolean {\n return file == null || file === this.st.workflows.currentPath\n }\n\n private validName(rawName: string): string | null {\n const name = rawName.trim()\n if (/^[\\w][\\w .-]*$/.test(name)) return name\n this.st.exec.notice = `invalid draft name: '${rawName}'`\n return null\n }\n\n /** create a NEW draft from the current var values (current workflow only) */\n createNamed(rawName: string): boolean {\n const name = this.validName(rawName)\n if (name == null) return false\n if (existsSync(join(this.dir, `${name}.json`))) {\n this.st.exec.notice = `draft '${name}' already exists`\n return false\n }\n this.write(name, JSON.stringify(this.snapshot(), null, 2))\n this.active = name\n this.st.settings.rememberDraft(this.moduleKey, name)\n this.st.exec.notice = `new draft: ${name} (autosaves)`\n return true\n }\n\n rename(oldName: string, rawName: string, file?: string): boolean {\n const newName = this.validName(rawName)\n if (newName == null) return false\n if (newName === oldName) return true\n const dir = this.dirFor(file)\n const to = join(dir, `${newName}.json`)\n if (existsSync(to)) {\n this.st.exec.notice = `draft '${newName}' already exists`\n return false\n }\n const from = join(dir, `${oldName}.json`)\n if (existsSync(from)) renameSync(from, to)\n else if (this.isCurrent(file)) this.write(newName, JSON.stringify(this.snapshot(), null, 2))\n if (this.isCurrent(file) && this.active === oldName) {\n this.active = newName\n this.st.settings.rememberDraft(this.moduleKey, newName)\n }\n this.version++\n this.st.exec.notice = `draft renamed: ${oldName} → ${newName}`\n return true\n }\n\n duplicate(name: string, rawName: string, file?: string): boolean {\n const newName = this.validName(rawName)\n if (newName == null) return false\n const dir = this.dirFor(file)\n const from = join(dir, `${name}.json`)\n const to = join(dir, `${newName}.json`)\n if (!existsSync(from)) {\n this.st.exec.notice = `draft '${name}' has no file yet (edit a var first)`\n return false\n }\n if (existsSync(to)) {\n this.st.exec.notice = `draft '${newName}' already exists`\n return false\n }\n copyFileSync(from, to)\n this.version++\n this.st.exec.notice = `draft duplicated: ${name} → ${newName}`\n return true\n }\n\n deleteDraft(name: string, file?: string): void {\n const path = join(this.dirFor(file), `${name}.json`)\n if (existsSync(path)) rmSync(path)\n this.version++\n // deleting the draft you are IN falls back to default\n if (this.isCurrent(file) && this.active === name) this.activateDefault()\n this.st.exec.notice = `draft deleted: ${name}`\n }\n\n // ---- name prompts (ONE mechanism: EditorSt custom session → PromptOverlay) ----\n\n promptNew(returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: 'new draft (from current values)',\n initial: '',\n onCommit: (raw) => {\n const ok = this.createNamed(raw)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n promptRename(name: string, file?: string, returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: `rename draft '${name}'`,\n initial: name,\n onCommit: (raw) => {\n const ok = this.rename(name, raw, file)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n promptDuplicate(name: string, file?: string, returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: `duplicate draft '${name}'`,\n initial: `${name}-copy`,\n onCommit: (raw) => {\n const ok = this.duplicate(name, raw, file)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n /** f2 in nav: rename the ACTIVE draft */\n beginRename(): void {\n this.promptRename(this.active ?? 'default')\n }\n\n begin(): void {\n this.list = listDraftsInDir(this.dir)\n this.st.mode = 'overlay-drafts'\n const ix = this.active == null ? -1 : this.list.indexOf(this.active)\n // row 0 = \"new draft\", rows 1.. = existing drafts\n this.ix = ix === -1 ? 0 : ix + 1\n }\n\n move(delta: number): void {\n const len = this.list.length + 1\n this.ix = (this.ix + delta + len) % len\n }\n\n /** draft name under the overlay cursor (row 0 is 'new') */\n get selectedName(): string | null {\n return this.ix === 0 ? null : (this.list[this.ix - 1] ?? null)\n }\n\n commit(): void {\n if (this.ix === 0) return this.promptNew('overlay-drafts')\n const name = this.selectedName\n if (name == null) return\n this.activate(name)\n this.st.exec.notice = `draft: ${name} (autosaves)`\n this.st.mode = 'nav'\n }\n}\n","// cp1252's 0x80-0x9F specials, unicode → original byte (the rest is latin1: code = byte)\nconst CP1252_REVERSE: Record<string, number> = {\n '€': 0x80,\n '‚': 0x82,\n ƒ: 0x83,\n '„': 0x84,\n '…': 0x85,\n '†': 0x86,\n '‡': 0x87,\n ˆ: 0x88,\n '‰': 0x89,\n Š: 0x8a,\n '‹': 0x8b,\n Œ: 0x8c,\n Ž: 0x8e,\n '‘': 0x91,\n '’': 0x92,\n '“': 0x93,\n '”': 0x94,\n '•': 0x95,\n '–': 0x96,\n '—': 0x97,\n '˜': 0x98,\n '™': 0x99,\n š: 0x9a,\n '›': 0x9b,\n œ: 0x9c,\n ž: 0x9e,\n Ÿ: 0x9f,\n}\n\n/**\n * repair UTF-8 that was decoded as cp1252 (a Windows server re-reading its own\n * output: `█` E2 96 88 arrives as `â–ˆ`). Reverses the cp1252 map back to\n * bytes and re-decodes as UTF-8; any unmappable char or invalid byte sequence\n * means the text was NOT mojibake — the original is returned untouched.\n */\nexport function repairMojibake(s: string): string {\n let suspicious = false\n for (let i = 0; i < s.length; i++) {\n if (s.charCodeAt(i) > 0x7f) {\n suspicious = true\n break\n }\n }\n if (!suspicious) return s\n const bytes = new Uint8Array(s.length)\n for (let i = 0; i < s.length; i++) {\n const code = s.charCodeAt(i)\n if (code <= 0xff) {\n bytes[i] = code\n continue\n }\n const mapped = CP1252_REVERSE[s[i] ?? '']\n if (mapped == null) return s\n bytes[i] = mapped\n }\n const decoded = Buffer.from(bytes).toString('utf8')\n return decoded.includes('�') ? s : decoded\n}\n","import { makeAutoObservable, runInAction } from 'mobx'\nimport { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'\nimport { stripAnsi } from 'src/utils/ansi.ts'\nimport { repairMojibake } from 'src/utils/mojibake.ts'\nimport type { LogEntry } from 'src/runner/ComfyWsApi.ts'\nimport type { ComfyHost } from 'src/host/ComfyHost.ts'\nimport type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'\n\nconst MAX_LINES = 400\n\n/** fold write chunks into p.lines (mutated), returns the new partial tail.\n * `\\n` commits a line, `\\r` resets the partial (tqdm redraws collapse to\n * their last state), ANSI stripped, blank lines dropped. */\nexport function assembleLogChunks(p: { lines: string[]; partial: string; entries: LogEntry[] }): string {\n let partial = p.partial\n for (const entry of p.entries) {\n for (const piece of stripAnsi(repairMojibake(entry.m)).split(/(\\r\\n|\\n|\\r)/)) {\n if (piece === '\\n' || piece === '\\r\\n') {\n if (partial.trim() !== '') p.lines.push(partial)\n partial = ''\n } else if (piece === '\\r') {\n partial = ''\n } else if (piece !== '') {\n partial += piece\n }\n }\n }\n return partial\n}\n\n/** server console mirror: /internal/logs/raw backfill + ws 'logs' stream.\n * Entries are write CHUNKS, not lines — assembled here (`\\n` commits,\n * `\\r` resets the partial, so tqdm redraws collapse to their last state). */\nexport class LogsSt {\n constructor(private st: TuiSt) {\n makeAutoObservable<LogsSt, 'st'>(this, { st: false })\n this.attach(this.st.wf.host)\n this.st.disposers.push(() => {\n if (this.attached != null) {\n this.attached.onLogs = null\n this.attached.onSession = null\n }\n })\n }\n\n lines: string[] = []\n /** chunk tail not yet closed by \\n — rendered live (tqdm progress) */\n partial: string = ''\n\n private attached: ComfyHost | null = null\n\n /** follow the CURRENT workflow's host (re-called on workflow switch) */\n attach(host: ComfyHost): void {\n if (this.attached === host) return\n if (this.attached != null) {\n this.attached.onLogs = null\n this.attached.onSession = null\n // best-effort: switched-away hosts stay connected (loadedHosts), so\n // without this their ws keeps carrying chunks nobody reads; the\n // server drops the sub on disconnect anyway, hence the swallowed error\n if (this.attached.isConnected && this.attached.comfySessionId !== 'temp') {\n void this.attached.subscribeLogs({ enabled: false, clientId: this.attached.comfySessionId }).catch(() => {})\n }\n }\n this.attached = host\n this.lines = []\n this.partial = ''\n host.onLogs = (p) => this.feed(p.entries)\n // per-sid server state: every (re)connect needs a fresh subscribe\n host.onSession = (sid) => void this.hydrate(host, sid)\n if (host.isConnected && host.comfySessionId !== 'temp') void this.hydrate(host, host.comfySessionId)\n }\n\n /** backfill BEFORE subscribe: entries emitted in the gap are lost, which is\n * the right trade — the reverse order would clobber streamed entries at the\n * reset, and the backfill re-covers the recent past anyway */\n private async hydrate(host: ComfyHost, sid: string): Promise<void> {\n try {\n const raw = await host.fetchRawLogs()\n // attach() switched hosts or the sid rolled again mid-fetch: stale snapshot\n if (this.attached !== host || host.comfySessionId !== sid) return\n runInAction(() => {\n this.lines = []\n this.partial = ''\n })\n this.feed(raw.entries)\n await host.subscribeLogs({ enabled: true, clientId: sid })\n } catch (e) {\n if (this.attached !== host) return\n // the panel is the loud surface: stream failures land as a log line\n this.feed([{ t: '', m: `[comfy-ts] server log stream unavailable: ${extractErrorMessage(e)}\\n` }])\n }\n }\n\n feed(entries: LogEntry[]): void {\n runInAction(() => {\n this.partial = assembleLogChunks({ lines: this.lines, partial: this.partial, entries })\n if (this.lines.length > MAX_LINES) this.lines.splice(0, this.lines.length - MAX_LINES)\n })\n }\n\n /** last rows to render, live partial included */\n tail(n: number): string[] {\n const rows = this.partial.trim() !== '' ? [...this.lines, this.partial] : this.lines\n return rows.slice(-n)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,eAAe,KAAuB;CAMnD,OALa,YAAY,KAAK,EAAE,WAAW,KAAK,CAAC,CAAC,CAC9C,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC,CACrB,QAAQ,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,CAAC,CAAC,CACrD,KAAK,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CACxB,QAAQ,MAAM,EAAE,SAAS,WAAW,KAAK,EAAE,SAAS,YAAY,CAC1D,CAAC,CAAC,KAAK;AACpB;;;;;;;;AAgBA,SAAgB,qBAAqB,GAIf;CACnB,IAAI,EAAE,gBAAgB,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QAAQ,MAAiB,KAA4B;EAChE,IAAI;GACD,MAAM,MAAM,MAAM,KAAK,aAAa;GAEpC,IAAI,KAAK,aAAa,QAAQ,KAAK,mBAAmB,KAAK;GAC3D,kBAAkB;IACf,KAAK,QAAQ,CAAC;IACd,KAAK,UAAU;GAClB,CAAC;GACD,KAAK,KAAK,IAAI,OAAO;GACrB,MAAM,KAAK,cAAc;IAAE,SAAS;IAAM,UAAU;GAAI,CAAC;EAC5D,SAAS,GAAG;GACT,IAAI,KAAK,aAAa,MAAM;GAE5B,KAAK,KAAK,CAAC;IAAE,GAAG;IAAI,GAAG,6CAA6C,oBAAoB,CAAC,EAAE;GAAI,CAAC,CAAC;EACpG;CACH;CAEA,KAAK,SAA2B;EAC7B,kBAAkB;GACf,KAAK,UAAU,kBAAkB;IAAE,OAAO,KAAK;IAAO,SAAS,KAAK;IAAS;GAAQ,CAAC;GACtF,IAAI,KAAK,MAAM,SAAS,WAAW,KAAK,MAAM,OAAO,GAAG,KAAK,MAAM,SAAS,SAAS;EACxF,CAAC;CACJ;;CAGA,KAAK,GAAqB;EAEvB,QADa,KAAK,QAAQ,KAAK,MAAM,KAAK,CAAC,GAAG,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,MAAA,CACnE,MAAM,CAAC,CAAC;CACvB;AACH"}
1
+ {"version":3,"file":"LogsSt-qtFzOKpu.js","names":[],"sources":["../src/cli/tui/discoverWorkflows.ts","../src/cli/tui/findDefinedWorkflow.ts","../src/cli/tui/treeRows.ts","../src/cli/tui/state/DraftsSt.ts","../src/utils/mojibake.ts","../src/cli/tui/state/LogsSt.ts"],"sourcesContent":["import { readdirSync } from 'node:fs'\nimport { join } from 'pathe'\n\n/**\n * recursive scan for the workflow-module naming convention. Entries BELOW a\n * node_modules segment are skipped: packaged examples arrive via\n * bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would\n * otherwise list them twice, un-deduped, as the user's own files), and\n * third-party packages shipping *.cflow.ts are not this project's workflows. A\n * scan root that is ITSELF inside node_modules still works (the filter is\n * relative to the root).\n */\nexport function scanCflowFiles(dir: string): string[] {\n const hits = readdirSync(dir, { recursive: true })\n .map((f) => String(f))\n .filter((f) => !f.split('/').includes('node_modules'))\n .map((f) => join(dir, f))\n .filter((f) => f.endsWith('.cflow.ts') || f.endsWith('.cflow.tsx'))\n return hits.sort()\n}\n\nexport type WorkflowDiscovery = {\n /** every module the tree lists, user files first, bundled examples last */\n files: string[]\n /** the subset that came from the PACKAGED examples (grouped apart in the tree) */\n bundled: Set<string>\n}\n\n/**\n * PURE merge of the scan with the packaged examples (headless-tested). An\n * explicit target keeps its scope only. Bundled files ALWAYS group under the\n * bundled section, also when the scan already found them (repo dev: ./examples\n * is under cwd) — dedupe relies on the caller passing realpath-normalized\n * strings on both sides.\n */\nexport function mergeWorkflowSources(p: {\n explicitTarget: boolean\n scanned: string[]\n bundledFiles: string[]\n}): WorkflowDiscovery {\n if (p.explicitTarget) return { files: p.scanned, bundled: new Set() }\n const bundled = new Set(p.bundledFiles)\n const userFiles = p.scanned.filter((f) => !bundled.has(f))\n return { files: [...userFiles, ...p.bundledFiles], bundled }\n}\n","import { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'\n\n/**\n * instanceof first; duck-type fallback covers a second copy of the library in\n * the module graph (linked dev setups, npm dedupe misses)\n */\nexport function findDefinedWorkflow(mod: Record<string, unknown>): DefinedWorkflow | null {\n const isDefined = (x: unknown): x is DefinedWorkflow =>\n x instanceof DefinedWorkflow ||\n (typeof x === 'object' &&\n x != null &&\n 'spec' in x &&\n typeof (x as DefinedWorkflow).run === 'function' &&\n typeof (x as DefinedWorkflow).entries === 'function')\n return [mod.default, ...Object.values(mod)].find(isDefined) ?? null\n}\n","import { basename, dirname } from 'pathe'\n\n/**\n * PURE tree-shaping layer under TreeSt (headless-tested): turns the flat\n * discovered file list into hierarchy rows (directory nodes + files), applies\n * the `/` substring filter, and owns the per-family color assignment.\n */\n\nexport type FileTreeRow =\n | { kind: 'dir'; path: string; label: string; depth: number; expanded: boolean }\n | { kind: 'file'; file: string; name: string; depth: number }\n\n/** module display name — also the drafts folder key (DraftsSt delegates here) */\nexport function moduleName(file: string): string {\n return basename(file).replace(/\\.cflow\\.tsx?$/, '')\n}\n\n/** the color word: everything before the first `-` (`flux1-i2i` → `flux1`) */\nexport function familyOf(name: string): string {\n const dash = name.indexOf('-')\n return dash === -1 ? name : name.slice(0, dash)\n}\n\n/** hue-spread so CONSECUTIVE families land on clearly distinct colors */\nexport const FAMILY_PALETTE: string[] = [\n '#61afef', // blue\n '#e5c07b', // amber\n '#c678dd', // magenta\n '#98c379', // green\n '#e06c75', // rose\n '#56b6c2', // teal\n '#d19a66', // orange\n '#a5b4fc', // lavender\n '#a5e075', // lime\n '#f28fad', // pink\n]\n\n/** family → color, palette cycled in first-appearance order over the FULL\n * (unfiltered) file list — stable while filtering/folding */\nexport function assignFamilyColors(files: string[]): Map<string, string> {\n const colors = new Map<string, string>()\n for (const file of files) {\n const family = familyOf(moduleName(file))\n if (colors.has(family)) continue\n colors.set(family, FAMILY_PALETTE[colors.size % FAMILY_PALETTE.length] ?? '#61afef')\n }\n return colors\n}\n\ntype DirNode = {\n /** deepest real directory path of this node (unique row key) */\n path: string\n label: string\n files: string[]\n dirs: Map<string, DirNode>\n}\n\nfunction commonDir(files: string[]): string {\n const first = files[0]\n if (first == null) return ''\n let prefix = dirname(first).split('/')\n for (const f of files.slice(1)) {\n const segs = dirname(f).split('/')\n let i = 0\n while (i < prefix.length && i < segs.length && prefix[i] === segs[i]) i++\n prefix = prefix.slice(0, i)\n }\n return prefix.join('/')\n}\n\nfunction insert(root: DirNode, rootDir: string, file: string): void {\n const rel = dirname(file).slice(rootDir.length).replace(/^\\//, '')\n const segs = rel === '' ? [] : rel.split('/')\n let node = root\n for (const seg of segs) {\n let child = node.dirs.get(seg)\n if (child == null) {\n child = { path: `${node.path}/${seg}`, label: seg, files: [], dirs: new Map() }\n node.dirs.set(seg, child)\n }\n node = child\n }\n node.files.push(file)\n}\n\n/** a dir holding NOTHING but one subdir shows as one `a/b` row */\nfunction mergeChains(node: DirNode): void {\n // snapshot: the loop rewrites node.dirs entries while iterating\n const entries = [...node.dirs]\n for (const [key, child] of entries) {\n mergeChains(child)\n if (child.files.length === 0 && child.dirs.size === 1) {\n const only = [...child.dirs.values()][0]!\n const label = `${child.label}/${only.label}`\n node.dirs.delete(key)\n // re-key by the MERGED label: keying by only.label could clobber a\n // real sibling dir of the same name (segments never contain '/')\n node.dirs.set(label, { ...only, label })\n }\n }\n}\n\nfunction matches(file: string, rootDir: string, filter: string): boolean {\n if (filter === '') return true\n // dir path + module name, NOT the raw filename: '.cflow.ts' matching\n // everything would make the filter useless for 'ts', 'flow', '.'\n const haystack = `${dirname(file).slice(rootDir.length)}/${moduleName(file)}`.toLowerCase()\n return haystack.includes(filter.toLowerCase())\n}\n\nfunction emit(p: {\n node: DirNode\n depth: number\n rootDir: string\n collapsedDirs: Set<string>\n filter: string\n out: FileTreeRow[]\n}): void {\n for (const file of p.node.files) {\n if (!matches(file, p.rootDir, p.filter)) continue\n p.out.push({ kind: 'file', file, name: moduleName(file), depth: p.depth })\n }\n for (const dir of [...p.node.dirs.values()].sort((a, b) => a.label.localeCompare(b.label))) {\n const kept: FileTreeRow[] = []\n // a collapsed dir still ignores its fold while a filter narrows the tree\n const expanded = p.filter !== '' || !p.collapsedDirs.has(dir.path)\n emit({ ...p, node: dir, depth: p.depth + 1, out: kept })\n if (p.filter !== '' && kept.length === 0) continue // prune filtered-empty dirs\n p.out.push({ kind: 'dir', path: dir.path, label: dir.label, depth: p.depth, expanded })\n if (expanded) p.out.push(...kept)\n }\n}\n\n/**\n * hierarchy rows over the discovered files: user files under their common\n * root, packaged examples LAST under one foldable 'comfy-ts examples' node.\n */\nexport function buildFileRows(p: {\n userFiles: string[]\n bundledFiles: string[]\n collapsedDirs: Set<string>\n filter: string\n}): FileTreeRow[] {\n const out: FileTreeRow[] = []\n if (p.userFiles.length > 0) {\n const rootDir = commonDir(p.userFiles)\n const root: DirNode = { path: rootDir, label: '', files: [], dirs: new Map() }\n for (const f of p.userFiles) insert(root, rootDir, f)\n mergeChains(root)\n emit({ node: root, depth: 0, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out })\n }\n if (p.bundledFiles.length > 0) {\n const rootDir = commonDir(p.bundledFiles)\n const root: DirNode = { path: rootDir, label: 'comfy-ts examples', files: [], dirs: new Map() }\n for (const f of p.bundledFiles) insert(root, rootDir, f)\n mergeChains(root)\n const kept: FileTreeRow[] = []\n const expanded = p.filter !== '' || !p.collapsedDirs.has(rootDir)\n emit({ node: root, depth: 1, rootDir, collapsedDirs: p.collapsedDirs, filter: p.filter, out: kept })\n if (p.filter !== '' && kept.length === 0) return out\n out.push({ kind: 'dir', path: rootDir, label: root.label, depth: 0, expanded })\n if (expanded) out.push(...kept)\n }\n return out\n}\n","import {\n copyFileSync,\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n renameSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport { makeAutoObservable, reaction } from 'mobx'\nimport { dirname, join } from 'pathe'\nimport { moduleName } from 'src/cli/tui/treeRows.ts'\nimport { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'\nimport type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'\n\n/** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */\nexport function draftKeyForFile(file: string): string {\n return moduleName(file)\n}\n\nexport function draftsDirForFile(file: string): string {\n return comfyts.resolveFromDrafts(draftKeyForFile(file))\n}\n\nfunction listDraftsInDir(dir: string): string[] {\n if (!existsSync(dir)) return []\n return readdirSync(dir)\n .filter((f) => f.endsWith('.json'))\n .map((f) => f.slice(0, -'.json'.length))\n .sort()\n}\n\n/** draft names stored for a workflow module (fs read — pair with DraftsSt.version for reactivity) */\nexport function listDraftsForFile(file: string): string[] {\n return listDraftsInDir(draftsDirForFile(file))\n}\n\n/**\n * named var-value snapshots at `.comfy-ts/drafts/<module-basename>/<name>.json`\n * (LOCAL state, gitignored). The active draft autosaves debounced; the TUI is\n * ALWAYS in a draft (`default` unless another one is activated).\n */\nexport class DraftsSt {\n constructor(private st: TuiSt) {\n makeAutoObservable<DraftsSt, 'st'>(this, { st: false })\n // active-draft autosave: var values + draft name are observable\n this.st.disposers.push(\n reaction(\n () => (this.active == null ? null : JSON.stringify(this.snapshot())),\n (json) => {\n if (json != null && this.active != null) this.write(this.active, json)\n },\n { delay: 300 },\n ),\n )\n }\n\n /** ALWAYS set after construction; null only transiently while activate() loads values */\n active: string | null = null\n list: string[] = []\n ix: number = 0\n /** bumped on every fs write/rename so fs-derived getters (tree rows) recompute */\n version: number = 0\n\n private get dir(): string {\n const cur = this.st.workflows.currentPath\n return cur != null ? draftsDirForFile(cur) : comfyts.resolveFromDrafts(this.st.wf.spec.id ?? 'workflow')\n }\n\n private snapshot(): Record<string, unknown> {\n // toJSON so seed persists {mode, value}; other vars round-trip their value\n return Object.fromEntries(this.st.entries.map(([k, varDef]) => [k, varDef.toJSON()]))\n }\n\n private write(name: string, json: string): void {\n const path = join(this.dir, `${name}.json`)\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, json)\n this.version++\n }\n\n /** module key of the currently loaded workflow (settings.lastDraft is keyed by it) */\n private get moduleKey(): string {\n return this.st.moduleKey\n }\n\n /** switch to a draft: load its stored values when the file exists, else it starts from current values */\n activate(name: string): void {\n this.active = null // the autosave expression must not see old values under the new name\n const path = join(this.dir, `${name}.json`)\n if (existsSync(path)) {\n try {\n const values: Record<string, unknown> = JSON.parse(readFileSync(path, 'utf8'))\n for (const [k, varDef] of this.st.entries) if (k in values) varDef.loadJSON(values[k])\n } catch (e) {\n this.st.exec.error = extractErrorMessage(e)\n }\n }\n this.active = name\n this.st.settings.rememberDraft(this.moduleKey, name)\n }\n\n /** open the draft this workflow was last in (settings), else 'default' */\n activateRemembered(): void {\n const remembered = this.st.settings.lastDraft[this.moduleKey]\n if (remembered != null && remembered !== 'default' && existsSync(join(this.dir, `${remembered}.json`)))\n this.activate(remembered)\n else this.activate('default')\n }\n\n /** every workflow starts in a draft; kept for callers that want 'default' explicitly */\n activateDefault(): void {\n this.activate('default')\n }\n\n // ---- draft CRUD (also drives the tree's draft rows — `file` overrides the target workflow) ----\n\n private dirFor(file: string | undefined): string {\n return file != null ? draftsDirForFile(file) : this.dir\n }\n\n /** true when ops on `file` touch the ACTIVE draft bookkeeping */\n private isCurrent(file: string | undefined): boolean {\n return file == null || file === this.st.workflows.currentPath\n }\n\n private validName(rawName: string): string | null {\n const name = rawName.trim()\n if (/^[\\w][\\w .-]*$/.test(name)) return name\n this.st.exec.notice = `invalid draft name: '${rawName}'`\n return null\n }\n\n /** create a NEW draft from the current var values (current workflow only) */\n createNamed(rawName: string): boolean {\n const name = this.validName(rawName)\n if (name == null) return false\n if (existsSync(join(this.dir, `${name}.json`))) {\n this.st.exec.notice = `draft '${name}' already exists`\n return false\n }\n this.write(name, JSON.stringify(this.snapshot(), null, 2))\n this.active = name\n this.st.settings.rememberDraft(this.moduleKey, name)\n this.st.exec.notice = `new draft: ${name} (autosaves)`\n return true\n }\n\n rename(oldName: string, rawName: string, file?: string): boolean {\n const newName = this.validName(rawName)\n if (newName == null) return false\n if (newName === oldName) return true\n const dir = this.dirFor(file)\n const to = join(dir, `${newName}.json`)\n if (existsSync(to)) {\n this.st.exec.notice = `draft '${newName}' already exists`\n return false\n }\n const from = join(dir, `${oldName}.json`)\n if (existsSync(from)) renameSync(from, to)\n else if (this.isCurrent(file)) this.write(newName, JSON.stringify(this.snapshot(), null, 2))\n if (this.isCurrent(file) && this.active === oldName) {\n this.active = newName\n this.st.settings.rememberDraft(this.moduleKey, newName)\n }\n this.version++\n this.st.exec.notice = `draft renamed: ${oldName} → ${newName}`\n return true\n }\n\n duplicate(name: string, rawName: string, file?: string): boolean {\n const newName = this.validName(rawName)\n if (newName == null) return false\n const dir = this.dirFor(file)\n const from = join(dir, `${name}.json`)\n const to = join(dir, `${newName}.json`)\n if (!existsSync(from)) {\n this.st.exec.notice = `draft '${name}' has no file yet (edit a var first)`\n return false\n }\n if (existsSync(to)) {\n this.st.exec.notice = `draft '${newName}' already exists`\n return false\n }\n copyFileSync(from, to)\n this.version++\n this.st.exec.notice = `draft duplicated: ${name} → ${newName}`\n return true\n }\n\n deleteDraft(name: string, file?: string): void {\n const path = join(this.dirFor(file), `${name}.json`)\n if (existsSync(path)) rmSync(path)\n this.version++\n // deleting the draft you are IN falls back to default\n if (this.isCurrent(file) && this.active === name) this.activateDefault()\n this.st.exec.notice = `draft deleted: ${name}`\n }\n\n // ---- name prompts (ONE mechanism: EditorSt custom session → PromptOverlay) ----\n\n promptNew(returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: 'new draft (from current values)',\n initial: '',\n onCommit: (raw) => {\n const ok = this.createNamed(raw)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n promptRename(name: string, file?: string, returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: `rename draft '${name}'`,\n initial: name,\n onCommit: (raw) => {\n const ok = this.rename(name, raw, file)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n promptDuplicate(name: string, file?: string, returnMode: TuiMode = 'nav'): void {\n this.st.editor.beginCustom({\n title: `duplicate draft '${name}'`,\n initial: `${name}-copy`,\n onCommit: (raw) => {\n const ok = this.duplicate(name, raw, file)\n if (ok && returnMode === 'overlay-drafts') this.begin()\n return ok\n },\n returnMode,\n })\n }\n\n /** f2 in nav: rename the ACTIVE draft */\n beginRename(): void {\n this.promptRename(this.active ?? 'default')\n }\n\n begin(): void {\n this.list = listDraftsInDir(this.dir)\n this.st.mode = 'overlay-drafts'\n const ix = this.active == null ? -1 : this.list.indexOf(this.active)\n // row 0 = \"new draft\", rows 1.. = existing drafts\n this.ix = ix === -1 ? 0 : ix + 1\n }\n\n move(delta: number): void {\n const len = this.list.length + 1\n this.ix = (this.ix + delta + len) % len\n }\n\n /** draft name under the overlay cursor (row 0 is 'new') */\n get selectedName(): string | null {\n return this.ix === 0 ? null : (this.list[this.ix - 1] ?? null)\n }\n\n commit(): void {\n if (this.ix === 0) return this.promptNew('overlay-drafts')\n const name = this.selectedName\n if (name == null) return\n this.activate(name)\n this.st.exec.notice = `draft: ${name} (autosaves)`\n this.st.mode = 'nav'\n }\n}\n","// cp1252's 0x80-0x9F specials, unicode → original byte (the rest is latin1: code = byte)\nconst CP1252_REVERSE: Record<string, number> = {\n '€': 0x80,\n '‚': 0x82,\n ƒ: 0x83,\n '„': 0x84,\n '…': 0x85,\n '†': 0x86,\n '‡': 0x87,\n ˆ: 0x88,\n '‰': 0x89,\n Š: 0x8a,\n '‹': 0x8b,\n Œ: 0x8c,\n Ž: 0x8e,\n '‘': 0x91,\n '’': 0x92,\n '“': 0x93,\n '”': 0x94,\n '•': 0x95,\n '–': 0x96,\n '—': 0x97,\n '˜': 0x98,\n '™': 0x99,\n š: 0x9a,\n '›': 0x9b,\n œ: 0x9c,\n ž: 0x9e,\n Ÿ: 0x9f,\n}\n\n/**\n * repair UTF-8 that was decoded as cp1252 (a Windows server re-reading its own\n * output: `█` E2 96 88 arrives as `â–ˆ`). Reverses the cp1252 map back to\n * bytes and re-decodes as UTF-8; any unmappable char or invalid byte sequence\n * means the text was NOT mojibake — the original is returned untouched.\n */\nexport function repairMojibake(s: string): string {\n let suspicious = false\n for (let i = 0; i < s.length; i++) {\n if (s.charCodeAt(i) > 0x7f) {\n suspicious = true\n break\n }\n }\n if (!suspicious) return s\n const bytes = new Uint8Array(s.length)\n for (let i = 0; i < s.length; i++) {\n const code = s.charCodeAt(i)\n if (code <= 0xff) {\n bytes[i] = code\n continue\n }\n const mapped = CP1252_REVERSE[s[i] ?? '']\n if (mapped == null) return s\n bytes[i] = mapped\n }\n const decoded = Buffer.from(bytes).toString('utf8')\n return decoded.includes('�') ? s : decoded\n}\n","import { makeAutoObservable, runInAction } from 'mobx'\nimport { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'\nimport { stripAnsi } from 'src/utils/ansi.ts'\nimport { repairMojibake } from 'src/utils/mojibake.ts'\nimport type { LogEntry } from 'src/runner/ComfyWsApi.ts'\nimport type { ComfyHost } from 'src/host/ComfyHost.ts'\nimport type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'\n\nconst MAX_LINES = 400\n\n/** fold write chunks into p.lines (mutated), returns the new partial tail.\n * `\\n` commits a line, `\\r` resets the partial (tqdm redraws collapse to\n * their last state), ANSI stripped, blank lines dropped. */\nexport function assembleLogChunks(p: { lines: string[]; partial: string; entries: LogEntry[] }): string {\n let partial = p.partial\n for (const entry of p.entries) {\n for (const piece of stripAnsi(repairMojibake(entry.m)).split(/(\\r\\n|\\n|\\r)/)) {\n if (piece === '\\n' || piece === '\\r\\n') {\n if (partial.trim() !== '') p.lines.push(partial)\n partial = ''\n } else if (piece === '\\r') {\n partial = ''\n } else if (piece !== '') {\n partial += piece\n }\n }\n }\n return partial\n}\n\n/** server console mirror: /internal/logs/raw backfill + ws 'logs' stream.\n * Entries are write CHUNKS, not lines — assembled here (`\\n` commits,\n * `\\r` resets the partial, so tqdm redraws collapse to their last state). */\nexport class LogsSt {\n constructor(private st: TuiSt) {\n makeAutoObservable<LogsSt, 'st'>(this, { st: false })\n this.attach(this.st.wf.host)\n this.st.disposers.push(() => {\n if (this.attached != null) {\n this.attached.onLogs = null\n this.attached.onSession = null\n }\n })\n }\n\n lines: string[] = []\n /** chunk tail not yet closed by \\n — rendered live (tqdm progress) */\n partial: string = ''\n\n private attached: ComfyHost | null = null\n\n /** follow the CURRENT workflow's host (re-called on workflow switch) */\n attach(host: ComfyHost): void {\n if (this.attached === host) return\n if (this.attached != null) {\n this.attached.onLogs = null\n this.attached.onSession = null\n // best-effort: switched-away hosts stay connected (loadedHosts), so\n // without this their ws keeps carrying chunks nobody reads; the\n // server drops the sub on disconnect anyway, hence the swallowed error\n if (this.attached.isConnected && this.attached.comfySessionId !== 'temp') {\n void this.attached.subscribeLogs({ enabled: false, clientId: this.attached.comfySessionId }).catch(() => {})\n }\n }\n this.attached = host\n this.lines = []\n this.partial = ''\n host.onLogs = (p) => this.feed(p.entries)\n // per-sid server state: every (re)connect needs a fresh subscribe\n host.onSession = (sid) => void this.hydrate(host, sid)\n if (host.isConnected && host.comfySessionId !== 'temp') void this.hydrate(host, host.comfySessionId)\n }\n\n /** backfill BEFORE subscribe: entries emitted in the gap are lost, which is\n * the right trade — the reverse order would clobber streamed entries at the\n * reset, and the backfill re-covers the recent past anyway */\n private async hydrate(host: ComfyHost, sid: string): Promise<void> {\n try {\n const raw = await host.fetchRawLogs()\n // attach() switched hosts or the sid rolled again mid-fetch: stale snapshot\n if (this.attached !== host || host.comfySessionId !== sid) return\n runInAction(() => {\n this.lines = []\n this.partial = ''\n })\n this.feed(raw.entries)\n await host.subscribeLogs({ enabled: true, clientId: sid })\n } catch (e) {\n if (this.attached !== host) return\n // the panel is the loud surface: stream failures land as a log line\n this.feed([{ t: '', m: `[comfy-ts] server log stream unavailable: ${extractErrorMessage(e)}\\n` }])\n }\n }\n\n feed(entries: LogEntry[]): void {\n runInAction(() => {\n this.partial = assembleLogChunks({ lines: this.lines, partial: this.partial, entries })\n if (this.lines.length > MAX_LINES) this.lines.splice(0, this.lines.length - MAX_LINES)\n })\n }\n\n /** last rows to render, live partial included */\n tail(n: number): string[] {\n const rows = this.partial.trim() !== '' ? [...this.lines, this.partial] : this.lines\n return rows.slice(-n)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,eAAe,KAAuB;CAMnD,OALa,YAAY,KAAK,EAAE,WAAW,KAAK,CAAC,CAAC,CAC9C,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC,CACrB,QAAQ,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,CAAC,CAAC,CACrD,KAAK,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,CACxB,QAAQ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K,aAAa,QAAQ,KAAK,KAAK,QAAQ,MAAM,GAAG;EACrD,IAAI,KAAK,eAAe,KAAK,mBAAmB,QAAQ,KAAU,QAAQ,MAAM,KAAK,cAAc;CACtG;;;;CAKA,MAAc,QAAQ,MAAiB,KAA4B;EAChE,IAAI;GACD,MAAM,MAAM,MAAM,KAAK,aAAa;GAEpC,IAAI,KAAK,aAAa,QAAQ,KAAK,mBAAmB,KAAK;GAC3D,kBAAkB;IACf,KAAK,QAAQ,CAAC;IACd,KAAK,UAAU;GAClB,CAAC;GACD,KAAK,KAAK,IAAI,OAAO;GACrB,MAAM,KAAK,cAAc;IAAE,SAAS;IAAM,UAAU;GAAI,CAAC;EAC5D,SAAS,GAAG;GACT,IAAI,KAAK,aAAa,MAAM;GAE5B,KAAK,KAAK,CAAC;IAAE,GAAG;IAAI,GAAG,6CAA6C,oBAAoB,CAAC,EAAE;GAAI,CAAC,CAAC;EACpG;CACH;CAEA,KAAK,SAA2B;EAC7B,kBAAkB;GACf,KAAK,UAAU,kBAAkB;IAAE,OAAO,KAAK;IAAO,SAAS,KAAK;IAAS;GAAQ,CAAC;GACtF,IAAI,KAAK,MAAM,SAAS,WAAW,KAAK,MAAM,OAAO,GAAG,KAAK,MAAM,SAAS,SAAS;EACxF,CAAC;CACJ;;CAGA,KAAK,GAAqB;EAEvB,QADa,KAAK,QAAQ,KAAK,MAAM,KAAK,CAAC,GAAG,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,MAAA,CACnE,MAAM,CAAC,CAAC;CACvB;AACH"}
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { A as lmModelName, C as fetchLoraList, P as lmTrainedWords, _ as readLoraMirror, b as writeLoraMirror, u as buildLoraMirror } from "./DefinedWorkflow-BatWaZO1.js";
3
- import { a as ComfySchema, r as readableStringify, t as ComfyTS } from "./state-BbgJeCe6.js";
2
+ import { C as readLoraMirror, D as writeLoraMirror, H as lmTrainedWords, R as lmModelName, j as fetchLoraList, m as buildLoraMirror } from "./schemaDrift-DjjEtwfx.js";
3
+ import { a as ComfySchema, r as readableStringify, t as ComfyTS } from "./state--wrz0BQc.js";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, rmdirSync, writeFileSync } from "node:fs";
@@ -278,10 +278,10 @@ async function main() {
278
278
  console.error(`[comfy-ts ${cmd}] bun not found (${res.error.message}) — continuing under node: the examples packaged in node_modules cannot load here, and your own .cflow.ts modules rely on node's type stripping`);
279
279
  }
280
280
  if (cmd === "serve") {
281
- const { runServe } = await import("./run-serve-_nrvJYyt.js");
281
+ const { runServe } = await import("./run-serve-BK7BA2dn.js");
282
282
  return runServe(rest);
283
283
  }
284
- const { runTui } = await import("./run-tui-BLEdTsOX.js");
284
+ const { runTui } = await import("./run-tui-CQyvMf0N.js");
285
285
  return runTui(rest);
286
286
  }
287
287
  console.log(HELP);
package/dist/index.cjs CHANGED
@@ -134,7 +134,7 @@ function createNodeStorage() {
134
134
  }
135
135
  //#endregion
136
136
  //#region package.json
137
- var version = "2.9.0";
137
+ var version = "2.11.0";
138
138
  //#endregion
139
139
  //#region src/litegraph/LiteGraphLinkID.ts
140
140
  const asLiteGraphLinkID = (id) => id;
@@ -1611,8 +1611,15 @@ var ComfyNode = class ComfyNode {
1611
1611
  }
1612
1612
  _getExpectedTypeForField(name) {
1613
1613
  const input = this.$schema.inputs.find((i) => i.nameInComfy === name);
1614
- if (input == null) throw new Error("🔴 input not found asdf");
1615
- return input.typeName;
1614
+ if (input != null) return input.typeName;
1615
+ const dot = name.indexOf(".");
1616
+ const decl = dot > 0 ? this.$schema.inputs.find((i) => i.nameInComfy === name.slice(0, dot)) : void 0;
1617
+ if (decl != null) {
1618
+ const kind = classifySchemaInput(decl);
1619
+ const slotType = containerInstanceSlotType(decl.opts);
1620
+ if (kind.kind === "dynamic-container" && kind.instanceNames.includes(name.slice(dot + 1)) && slotType != null) return slotType;
1621
+ }
1622
+ throw new Error(`🔴 no input "${name}" on ${this.$schema.nodeKey}: cannot tell which output of the linked node to use`);
1616
1623
  }
1617
1624
  _getOutputForTypeOrCrash(type) {
1618
1625
  const i = this.$schema.outputs.find((i) => i.typeName === type);
@@ -5029,6 +5036,87 @@ var DefinedWorkflow = class {
5029
5036
  }
5030
5037
  };
5031
5038
  //#endregion
5039
+ //#region src/host/schemaDrift.ts
5040
+ /**
5041
+ * what changed on a host since a schema was loaded: node types, and the model files each loader
5042
+ * lists. ComfyUI exposes no boot time, so staleness is decided by CONTENT: a restart that changed
5043
+ * nothing stays quiet, a new lora shows even when nobody knows when the box rebooted.
5044
+ * A light check asks only the loaders (`/object_info/<node>`, a few KB); a full one compares every
5045
+ * node type (`/object_info`, megabytes).
5046
+ */
5047
+ /** the loader inputs whose combo IS a model folder listing */
5048
+ const MODEL_LISTS = [
5049
+ {
5050
+ noun: "lora",
5051
+ node: "LoraLoader",
5052
+ input: "lora_name"
5053
+ },
5054
+ {
5055
+ noun: "checkpoint",
5056
+ node: "CheckpointLoaderSimple",
5057
+ input: "ckpt_name"
5058
+ },
5059
+ {
5060
+ noun: "unet",
5061
+ node: "UNETLoader",
5062
+ input: "unet_name"
5063
+ },
5064
+ {
5065
+ noun: "text encoder",
5066
+ node: "CLIPLoader",
5067
+ input: "clip_name"
5068
+ },
5069
+ {
5070
+ noun: "vae",
5071
+ node: "VAELoader",
5072
+ input: "vae_name"
5073
+ }
5074
+ ];
5075
+ /** a combo's options in both object_info spellings: `[[...options]]` and `['COMBO', { options }]` */
5076
+ function comboOptions(spec, node, input) {
5077
+ const def = spec[node];
5078
+ if (!isRecord(def) || !isRecord(def["input"])) return null;
5079
+ const sections = def["input"];
5080
+ for (const section of ["required", "optional"]) {
5081
+ const sec = sections[section];
5082
+ if (!isRecord(sec)) continue;
5083
+ const slot = sec[input];
5084
+ if (!Array.isArray(slot)) continue;
5085
+ const first = slot[0];
5086
+ if (Array.isArray(first)) return first.filter((x) => typeof x === "string");
5087
+ const opts = slot[1];
5088
+ if (first === "COMBO" && isRecord(opts) && Array.isArray(opts["options"])) return opts["options"].filter((x) => typeof x === "string");
5089
+ }
5090
+ return null;
5091
+ }
5092
+ function delta(before, after) {
5093
+ const was = new Set(before);
5094
+ const now = new Set(after);
5095
+ return {
5096
+ added: after.filter((x) => !was.has(x)),
5097
+ removed: before.filter((x) => !now.has(x))
5098
+ };
5099
+ }
5100
+ /** `live` may be PARTIAL (a light check holds only the loaders): a list is compared only where both
5101
+ * sides have the loader, and node types only when `full` */
5102
+ function diffSchemas(p) {
5103
+ const models = [];
5104
+ for (const m of MODEL_LISTS) {
5105
+ const before = comboOptions(p.loaded, m.node, m.input);
5106
+ const after = comboOptions(p.live, m.node, m.input);
5107
+ if (before == null || after == null) continue;
5108
+ const d = delta(before, after);
5109
+ if (d.added.length > 0 || d.removed.length > 0) models.push({
5110
+ noun: m.noun,
5111
+ ...d
5112
+ });
5113
+ }
5114
+ return {
5115
+ nodes: p.full ? delta(Object.keys(p.loaded), Object.keys(p.live)) : null,
5116
+ models
5117
+ };
5118
+ }
5119
+ //#endregion
5032
5120
  //#region src/host/ComfyHost.ts
5033
5121
  /** the host never came up within ConnectOptions.timeoutMs */
5034
5122
  var ComfyHostUnreachableError = class extends Error {
@@ -5254,6 +5342,17 @@ var ComfyHost = class {
5254
5342
  }, { apiPrefix: false });
5255
5343
  if (!res.ok) throw new Error(`PATCH /internal/logs/subscribe failed: ${res.status}`);
5256
5344
  };
5345
+ this.checkSchemaDrift = async (p) => {
5346
+ const loaded = this.schema.data.spec;
5347
+ const live = {};
5348
+ if (p.full) Object.assign(live, await this.fetchJSON_("/object_info"));
5349
+ else for (const m of MODEL_LISTS) if (loaded[m.node] != null) Object.assign(live, await this.fetchJSON_(`/object_info/${m.node}`));
5350
+ return diffSchemas({
5351
+ loaded,
5352
+ live,
5353
+ full: p.full
5354
+ });
5355
+ };
5257
5356
  this.fetchJSON_ = async (route) => {
5258
5357
  const base = this.getServerHostHTTP();
5259
5358
  const res = await this.fetch(route);