comfy-ts 1.2.0 → 1.3.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.
- package/README.md +40 -0
- package/dist/DefinedWorkflow-gpknV-5f.js +686 -0
- package/dist/DefinedWorkflow-gpknV-5f.js.map +1 -0
- package/dist/DraftsSt-DmA0jWGl.js +434 -0
- package/dist/DraftsSt-DmA0jWGl.js.map +1 -0
- package/dist/cli.js +15 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +132 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +23 -18
- package/dist/index.js +132 -21
- package/dist/index.js.map +1 -1
- package/dist/run-serve-Bn6yIJB0.js +638 -0
- package/dist/run-serve-Bn6yIJB0.js.map +1 -0
- package/dist/{run-tui-BAdizWsO.js → run-tui-BtjaOXRh.js} +244 -440
- package/dist/run-tui-BtjaOXRh.js.map +1 -0
- package/dist/{state-BYbxDgfr.js → state-DKCPy105.js} +130 -698
- package/dist/state-DKCPy105.js.map +1 -0
- package/package.json +3 -2
- package/src/cli/comfy-ts-cli.ts +15 -5
- package/src/cli/serve/ServeApp.ts +378 -0
- package/src/cli/serve/applyVarPayload.ts +119 -0
- package/src/cli/serve/describeVar.ts +74 -0
- package/src/cli/serve/run-serve.ts +169 -0
- package/src/cli/tui/components/StatusBar.tsx +1 -0
- package/src/cli/tui/components/TreePanel.tsx +17 -3
- package/src/cli/tui/components/TuiApp.tsx +7 -2
- package/src/cli/tui/components/VarsPanel.tsx +67 -34
- package/src/cli/tui/imageClipboard.ts +39 -0
- package/src/cli/tui/listWindow.ts +36 -0
- package/src/cli/tui/state/ExecSt.ts +48 -0
- package/src/cli/tui/state/TreeSt.ts +25 -0
- package/src/cli/tui/state/TuiSt.ts +34 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +11 -7
- package/src/runner/ComfyExecution.ts +21 -4
- package/src/runner/outputPath.ts +75 -0
- package/src/sdk-generator/inputWidgetKind.ts +50 -11
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +14 -7
- package/src/vars/ComfyVars.ts +8 -0
- package/dist/run-tui-BAdizWsO.js.map +0 -1
- package/dist/state-BYbxDgfr.js.map +0 -1
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli/gen.ts","../src/cli/outline.ts","../src/cli/comfy-ts-cli.ts"],"sourcesContent":["// fetch a live host's schema and generate its typed sdk\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, join, resolve } from 'pathe'\nimport { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'\nimport type { ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'\nimport { ComfyTS } from 'src/state.ts'\nimport { readableStringify } from 'src/utils/stringifyReadable.ts'\n\nexport async function runGen(args: string[]): Promise<number> {\n const getFlag = (name: string): string | null => {\n const ix = args.indexOf(`--${name}`)\n return ix >= 0 ? (args[ix + 1] ?? null) : null\n }\n const hostUrl = getFlag('host') ?? 'http://127.0.0.1:8188'\n const id = getFlag('id')\n if (id == null) {\n console.error('[comfy-ts gen] 🔴 --id <host-id> is required (it names .comfy-ts/hosts/<id>/)')\n return 1\n }\n\n // the lib's own authed host.fetch does the /api-first probing + X-API-Key\n const comfy = ComfyTS.create()\n const apiKey = getFlag('api-key') ?? process.env.COMFY_CLOUD_API_KEY\n const host = comfy.host({ id, url: hostUrl, apiKey: apiKey ?? undefined })\n\n const fetchJSON = async <T>(route: string): Promise<T> => {\n console.log(`[comfy-ts gen] fetching ${hostUrl} ${route} …`)\n const res = await host.fetch(route)\n if (!res.ok) throw new Error(`GET ${route} failed on ${hostUrl}: ${res.status}`)\n if (!(res.headers.get('content-type') ?? '').includes('json'))\n throw new Error(`GET ${route} on ${hostUrl} did not answer json`)\n return (await res.json()) as T\n }\n\n const spec = await fetchJSON<ComfySchemaJSON>('/object_info')\n const embeddings = await fetchJSON<string[]>('/embeddings').catch(() => [] as string[])\n\n const dir = join(process.cwd(), '.comfy-ts', 'hosts', id)\n mkdirSync(dir, { recursive: true })\n writeFileSync(join(dir, 'object_info.json'), readableStringify(spec, 4), 'utf8')\n writeFileSync(join(dir, 'embeddings.json'), JSON.stringify(embeddings), 'utf8')\n\n const parsed = new ComfySchema({ spec, embeddings })\n const dts = parsed.codegenDTS({ hostId: id })\n // --out: explicit sdk home (the committed cloud catalog) — the json dumps\n // above still cache under .comfy-ts/hosts/<id>/, but the sdk must exist at\n // ONE tsconfig-visible path only, so it skips the hosts dir entirely\n const out = getFlag('out')\n const outPath = out != null ? resolve(process.cwd(), out) : join(dir, 'sdk.d.ts')\n if (out != null) mkdirSync(dirname(outPath), { recursive: true })\n writeFileSync(outPath, dts, 'utf8')\n console.log(`[comfy-ts gen] 🟢 ${outPath} (${parsed.nodes.length} nodes, ${(dts.length / 1024).toFixed(0)}kB)`)\n if (out == null)\n console.log(`[comfy-ts gen] add \".comfy-ts/hosts/**/sdk.d.ts\" to your tsconfig \"include\" to activate the types`)\n return 0\n}\n","// outline a generated sdk.d.ts without reading 2MB blind\nimport { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport { join } from 'pathe'\n\ntype Section = { name: string; kind: string; start: number; end: number; depth: number }\n\nfunction findDefaultSdk(): string | null {\n const hostsDir = join(process.cwd(), '.comfy-ts', 'hosts')\n if (!existsSync(hostsDir)) return null\n for (const id of readdirSync(hostsDir)) {\n const p = join(hostsDir, id, 'sdk.d.ts')\n if (existsSync(p)) return p\n }\n return null\n}\n\nexport function runOutline(args: string[]): number {\n const linesFlagIx = args.indexOf('--lines')\n const maxLines = linesFlagIx >= 0 ? Number(args[linesFlagIx + 1] ?? 10) : null\n const sectionFlagIx = args.indexOf('--section')\n const wantedSection = sectionFlagIx >= 0 ? args[sectionFlagIx + 1] : null\n const flagValueIxs = new Set([linesFlagIx + 1, sectionFlagIx + 1].filter((ix) => ix > 0))\n const fileArg = args.find((a, ix) => !a.startsWith('--') && !flagValueIxs.has(ix))\n\n const file = fileArg ?? findDefaultSdk()\n if (file == null || !existsSync(file)) {\n console.error('[sdk-outline] 🔴 no sdk.d.ts found; pass a path explicitly')\n return 1\n }\n\n const lines = readFileSync(file, 'utf8').split('\\n')\n\n // scan: track brace depth, record interface/type/namespace declarations up to depth 3\n const sections: Section[] = []\n const stack: Section[] = []\n let depth = 0\n const declRe = /^\\s*(?:export\\s+)?(interface|namespace|type)\\s+([A-Za-z0-9_$]+)/\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? ''\n const m = depth <= 3 ? declRe.exec(line) : null\n const opens = (line.match(/{/g) ?? []).length\n const closes = (line.match(/}/g) ?? []).length\n if (m && (opens > 0 || m[1] === 'type')) {\n const sec: Section = { name: m[2] ?? '?', kind: m[1] ?? '?', start: i + 1, end: i + 1, depth }\n sections.push(sec)\n if (opens > closes) stack.push(sec)\n }\n depth += opens - closes\n while (stack.length > 0 && depth <= (stack[stack.length - 1]?.depth ?? 0)) {\n const closed = stack.pop()\n if (closed) closed.end = i + 1\n }\n // type aliases (no braces): extend until next decl at same depth\n const last = sections[sections.length - 1]\n if (last && last.kind === 'type' && stack[stack.length - 1] !== last) last.end = Math.max(last.end, i)\n }\n\n if (wantedSection) {\n const sec = sections.find((s) => s.name === wantedSection)\n if (sec == null) {\n console.error(\n `[sdk-outline] 🔴 section \"${wantedSection}\" not found. Available: ${sections.map((s) => s.name).join(', ')}`,\n )\n return 1\n }\n const body = lines.slice(sec.start - 1, maxLines ? Math.min(sec.end, sec.start - 1 + maxLines) : sec.end)\n console.log(body.join('\\n'))\n if (maxLines && sec.end - sec.start + 1 > maxLines)\n console.log(`… (${sec.end - sec.start + 1 - maxLines} more lines, ends at line ${sec.end})`)\n } else {\n console.log(`${file} — ${lines.length} lines\\n`)\n for (const s of sections) {\n const indent = ' '.repeat(s.depth)\n console.log(`${indent}${s.kind} ${s.name} [${s.start}-${s.end}] (${s.end - s.start + 1} lines)`)\n if (maxLines) {\n const body = lines.slice(s.start - 1, s.start - 1 + maxLines)\n console.log(body.map((l) => `${indent} │ ${l.trim()}`).join('\\n'))\n }\n }\n }\n return 0\n}\n","#!/usr/bin/env node\n// sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code\nimport { spawnSync } from 'node:child_process'\nimport { fileURLToPath } from 'node:url'\nimport { runGen } from 'src/cli/gen.ts'\nimport { runOutline } from 'src/cli/outline.ts'\n\nconst HELP = `comfy-ts — typed SDK codegen for ComfyUI\n\nUsage:\n comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] [--api-key <key>] [--out <sdk-path>]\n fetch object_info + embeddings from a live ComfyUI host and write\n .comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts}\n (--api-key or COMFY_CLOUD_API_KEY authenticates via X-API-Key;\n --out relocates ONLY the sdk.d.ts, e.g. a committed cloud catalog)\n\n comfy-ts outline [file] [--lines N] [--section Name]\n outline a generated sdk.d.ts (defaults to the first one in .comfy-ts/hosts/)\n\n comfy-ts tui [dir | workflow-module.ts]\n interactive tweak & re-run over **/*.cflow.ts modules (exporting\n host.defineWorkflow(...)); no arg scans cwd + the examples bundled\n with comfy-ts, an explicit dir/file limits to it (file preselected)\n\n comfy-ts help\n`\n\nasync function main(): Promise<number> {\n const [cmd, ...rest] = process.argv.slice(2)\n if (cmd === 'gen') return runGen(rest)\n if (cmd === 'outline') return runOutline(rest)\n if (cmd === 'tui') {\n // .cflow.ts workflow modules need bun: node refuses to strip types under\n // node_modules, exactly where the packaged examples live — and the bin's\n // node shebang means `bunx comfy-ts tui` lands here under NODE. Hop to\n // bun when we are not already in it; without bun, runTui degrades loudly.\n if (process.versions.bun == null) {\n const self = fileURLToPath(import.meta.url)\n const res = spawnSync('bun', [self, 'tui', ...rest], { stdio: 'inherit' })\n if (res.error == null) return res.status ?? 1\n console.error(\n `[comfy-ts tui] 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`,\n )\n }\n // lazy import: keeps ink/react out of the codegen paths\n const { runTui } = await import('src/cli/tui/run-tui.tsx')\n return runTui(rest)\n }\n console.log(HELP)\n return cmd == null || cmd === 'help' ? 0 : 1\n}\n\nprocess.exitCode = await main()\n"],"mappings":";;;;;;;AAQA,eAAsB,OAAO,MAAiC;CAC3D,MAAM,WAAW,SAAgC;EAC9C,MAAM,KAAK,KAAK,QAAQ,KAAK,MAAM;EACnC,OAAO,MAAM,IAAK,KAAK,KAAK,MAAM,OAAQ;CAC7C;CACA,MAAM,UAAU,QAAQ,MAAM,KAAK;CACnC,MAAM,KAAK,QAAQ,IAAI;CACvB,IAAI,MAAM,MAAM;EACb,QAAQ,MAAM,+EAA+E;EAC7F,OAAO;CACV;CAGA,MAAM,QAAQ,QAAQ,OAAO;CAC7B,MAAM,SAAS,QAAQ,SAAS,KAAK,QAAQ,IAAI;CACjD,MAAM,OAAO,MAAM,KAAK;EAAE;EAAI,KAAK;EAAS,QAAQ,UAAU,KAAA;CAAU,CAAC;CAEzE,MAAM,YAAY,OAAU,UAA8B;EACvD,QAAQ,IAAI,2BAA2B,QAAQ,GAAG,MAAM,GAAG;EAC3D,MAAM,MAAM,MAAM,KAAK,MAAM,KAAK;EAClC,IAAI,CAAC,IAAI,IAAI,MAAM,IAAI,MAAM,OAAO,MAAM,aAAa,QAAQ,IAAI,IAAI,QAAQ;EAC/E,IAAI,EAAE,IAAI,QAAQ,IAAI,cAAc,KAAK,GAAA,CAAI,SAAS,MAAM,GACzD,MAAM,IAAI,MAAM,OAAO,MAAM,MAAM,QAAQ,qBAAqB;EACnE,OAAQ,MAAM,IAAI,KAAK;CAC1B;CAEA,MAAM,OAAO,MAAM,UAA2B,cAAc;CAC5D,MAAM,aAAa,MAAM,UAAoB,aAAa,CAAC,CAAC,YAAY,CAAC,CAAa;CAEtF,MAAM,MAAM,KAAK,QAAQ,IAAI,GAAG,aAAa,SAAS,EAAE;CACxD,UAAU,KAAK,EAAE,WA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I;CAC7C,IAAI,QAAQ,OAAO;EAKhB,IAAI,QAAQ,SAAS,OAAO,MAAM;GAE/B,MAAM,MAAM,UAAU,OAAO;IADhB,cAAc,OAAO,KAAK,GACN;IAAG;IAAO,GAAG;GAAI,GAAG,EAAE,OAAO,UAAU,CAAC;GACzE,IAAI,IAAI,SAAS,MAAM,OAAO,IAAI,UAAU;GAC5C,QAAQ,MACL,iCAAiC,IAAI,MAAM,QAAQ,gJACtD;EACH;EAEA,MAAM,EAAE,WAAW,MAAM,OAAO;EAChC,OAAO,OAAO,IAAI;CACrB;CACA,QAAQ,IAAI,IAAI;CAChB,OAAO,OAAO,QAAQ,QAAQ,SAAS,IAAI;AAC9C;AAEA,QAAQ,WAAW,MAAM,KAAK"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli/gen.ts","../src/cli/outline.ts","../src/cli/comfy-ts-cli.ts"],"sourcesContent":["// fetch a live host's schema and generate its typed sdk\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { dirname, join, resolve } from 'pathe'\nimport { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'\nimport type { ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'\nimport { ComfyTS } from 'src/state.ts'\nimport { readableStringify } from 'src/utils/stringifyReadable.ts'\n\nexport async function runGen(args: string[]): Promise<number> {\n const getFlag = (name: string): string | null => {\n const ix = args.indexOf(`--${name}`)\n return ix >= 0 ? (args[ix + 1] ?? null) : null\n }\n const hostUrl = getFlag('host') ?? 'http://127.0.0.1:8188'\n const id = getFlag('id')\n if (id == null) {\n console.error('[comfy-ts gen] 🔴 --id <host-id> is required (it names .comfy-ts/hosts/<id>/)')\n return 1\n }\n\n // the lib's own authed host.fetch does the /api-first probing + X-API-Key\n const comfy = ComfyTS.create()\n const apiKey = getFlag('api-key') ?? process.env.COMFY_CLOUD_API_KEY\n const host = comfy.host({ id, url: hostUrl, apiKey: apiKey ?? undefined })\n\n const fetchJSON = async <T>(route: string): Promise<T> => {\n console.log(`[comfy-ts gen] fetching ${hostUrl} ${route} …`)\n const res = await host.fetch(route)\n if (!res.ok) throw new Error(`GET ${route} failed on ${hostUrl}: ${res.status}`)\n if (!(res.headers.get('content-type') ?? '').includes('json'))\n throw new Error(`GET ${route} on ${hostUrl} did not answer json`)\n return (await res.json()) as T\n }\n\n const spec = await fetchJSON<ComfySchemaJSON>('/object_info')\n const embeddings = await fetchJSON<string[]>('/embeddings').catch(() => [] as string[])\n\n const dir = join(process.cwd(), '.comfy-ts', 'hosts', id)\n mkdirSync(dir, { recursive: true })\n writeFileSync(join(dir, 'object_info.json'), readableStringify(spec, 4), 'utf8')\n writeFileSync(join(dir, 'embeddings.json'), JSON.stringify(embeddings), 'utf8')\n\n const parsed = new ComfySchema({ spec, embeddings })\n const dts = parsed.codegenDTS({ hostId: id })\n // --out: explicit sdk home (the committed cloud catalog) — the json dumps\n // above still cache under .comfy-ts/hosts/<id>/, but the sdk must exist at\n // ONE tsconfig-visible path only, so it skips the hosts dir entirely\n const out = getFlag('out')\n const outPath = out != null ? resolve(process.cwd(), out) : join(dir, 'sdk.d.ts')\n if (out != null) mkdirSync(dirname(outPath), { recursive: true })\n writeFileSync(outPath, dts, 'utf8')\n console.log(`[comfy-ts gen] 🟢 ${outPath} (${parsed.nodes.length} nodes, ${(dts.length / 1024).toFixed(0)}kB)`)\n if (out == null)\n console.log(`[comfy-ts gen] add \".comfy-ts/hosts/**/sdk.d.ts\" to your tsconfig \"include\" to activate the types`)\n return 0\n}\n","// outline a generated sdk.d.ts without reading 2MB blind\nimport { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport { join } from 'pathe'\n\ntype Section = { name: string; kind: string; start: number; end: number; depth: number }\n\nfunction findDefaultSdk(): string | null {\n const hostsDir = join(process.cwd(), '.comfy-ts', 'hosts')\n if (!existsSync(hostsDir)) return null\n for (const id of readdirSync(hostsDir)) {\n const p = join(hostsDir, id, 'sdk.d.ts')\n if (existsSync(p)) return p\n }\n return null\n}\n\nexport function runOutline(args: string[]): number {\n const linesFlagIx = args.indexOf('--lines')\n const maxLines = linesFlagIx >= 0 ? Number(args[linesFlagIx + 1] ?? 10) : null\n const sectionFlagIx = args.indexOf('--section')\n const wantedSection = sectionFlagIx >= 0 ? args[sectionFlagIx + 1] : null\n const flagValueIxs = new Set([linesFlagIx + 1, sectionFlagIx + 1].filter((ix) => ix > 0))\n const fileArg = args.find((a, ix) => !a.startsWith('--') && !flagValueIxs.has(ix))\n\n const file = fileArg ?? findDefaultSdk()\n if (file == null || !existsSync(file)) {\n console.error('[sdk-outline] 🔴 no sdk.d.ts found; pass a path explicitly')\n return 1\n }\n\n const lines = readFileSync(file, 'utf8').split('\\n')\n\n // scan: track brace depth, record interface/type/namespace declarations up to depth 3\n const sections: Section[] = []\n const stack: Section[] = []\n let depth = 0\n const declRe = /^\\s*(?:export\\s+)?(interface|namespace|type)\\s+([A-Za-z0-9_$]+)/\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] ?? ''\n const m = depth <= 3 ? declRe.exec(line) : null\n const opens = (line.match(/{/g) ?? []).length\n const closes = (line.match(/}/g) ?? []).length\n if (m && (opens > 0 || m[1] === 'type')) {\n const sec: Section = { name: m[2] ?? '?', kind: m[1] ?? '?', start: i + 1, end: i + 1, depth }\n sections.push(sec)\n if (opens > closes) stack.push(sec)\n }\n depth += opens - closes\n while (stack.length > 0 && depth <= (stack[stack.length - 1]?.depth ?? 0)) {\n const closed = stack.pop()\n if (closed) closed.end = i + 1\n }\n // type aliases (no braces): extend until next decl at same depth\n const last = sections[sections.length - 1]\n if (last && last.kind === 'type' && stack[stack.length - 1] !== last) last.end = Math.max(last.end, i)\n }\n\n if (wantedSection) {\n const sec = sections.find((s) => s.name === wantedSection)\n if (sec == null) {\n console.error(\n `[sdk-outline] 🔴 section \"${wantedSection}\" not found. Available: ${sections.map((s) => s.name).join(', ')}`,\n )\n return 1\n }\n const body = lines.slice(sec.start - 1, maxLines ? Math.min(sec.end, sec.start - 1 + maxLines) : sec.end)\n console.log(body.join('\\n'))\n if (maxLines && sec.end - sec.start + 1 > maxLines)\n console.log(`… (${sec.end - sec.start + 1 - maxLines} more lines, ends at line ${sec.end})`)\n } else {\n console.log(`${file} — ${lines.length} lines\\n`)\n for (const s of sections) {\n const indent = ' '.repeat(s.depth)\n console.log(`${indent}${s.kind} ${s.name} [${s.start}-${s.end}] (${s.end - s.start + 1} lines)`)\n if (maxLines) {\n const body = lines.slice(s.start - 1, s.start - 1 + maxLines)\n console.log(body.map((l) => `${indent} │ ${l.trim()}`).join('\\n'))\n }\n }\n }\n return 0\n}\n","#!/usr/bin/env node\n// sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code\nimport { spawnSync } from 'node:child_process'\nimport { fileURLToPath } from 'node:url'\nimport { runGen } from 'src/cli/gen.ts'\nimport { runOutline } from 'src/cli/outline.ts'\n\nconst HELP = `comfy-ts — typed SDK codegen for ComfyUI\n\nUsage:\n comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] [--api-key <key>] [--out <sdk-path>]\n fetch object_info + embeddings from a live ComfyUI host and write\n .comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts}\n (--api-key or COMFY_CLOUD_API_KEY authenticates via X-API-Key;\n --out relocates ONLY the sdk.d.ts, e.g. a committed cloud catalog)\n\n comfy-ts outline [file] [--lines N] [--section Name]\n outline a generated sdk.d.ts (defaults to the first one in .comfy-ts/hosts/)\n\n comfy-ts tui [dir | workflow-module.ts]\n interactive tweak & re-run over **/*.cflow.ts modules (exporting\n host.defineWorkflow(...)); no arg scans cwd + the examples bundled\n with comfy-ts, an explicit dir/file limits to it (file preselected)\n\n comfy-ts serve [dir | workflow-module.ts] [--port 8288] [--bind 127.0.0.1]\n drafts as a local HTTP generation API: POST /generate/<module>/<draft>\n with { ...vars } overriding the draft's values (blocking; raw image\n bytes under Accept: image/*), GET /drafts self-describes every var,\n GET /outputs/... serves the results. No bundled examples, no auth.\n\n comfy-ts help\n`\n\nasync function main(): Promise<number> {\n const [cmd, ...rest] = process.argv.slice(2)\n if (cmd === 'gen') return runGen(rest)\n if (cmd === 'outline') return runOutline(rest)\n if (cmd === 'tui' || cmd === 'serve') {\n // .cflow.ts workflow modules need bun: node refuses to strip types under\n // node_modules, exactly where the packaged examples live — and the bin's\n // node shebang means `bunx comfy-ts tui|serve` lands here under NODE. Hop\n // to bun when we are not already in it; without bun, degrade loudly.\n if (process.versions.bun == null) {\n const self = fileURLToPath(import.meta.url)\n const res = spawnSync('bun', [self, cmd, ...rest], { stdio: 'inherit' })\n if (res.error == null) return res.status ?? 1\n console.error(\n `[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`,\n )\n }\n if (cmd === 'serve') {\n const { runServe } = await import('src/cli/serve/run-serve.ts')\n return runServe(rest)\n }\n // lazy import: keeps ink/react out of the codegen paths\n const { runTui } = await import('src/cli/tui/run-tui.tsx')\n return runTui(rest)\n }\n console.log(HELP)\n return cmd == null || cmd === 'help' ? 0 : 1\n}\n\nprocess.exitCode = await main()\n"],"mappings":";;;;;;;AAQA,eAAsB,OAAO,MAAiC;CAC3D,MAAM,WAAW,SAAgC;EAC9C,MAAM,KAAK,KAAK,QAAQ,KAAK,MAAM;EACnC,OAAO,MAAM,IAAK,KAAK,KAAK,MAAM,OAAQ;CAC7C;CACA,MAAM,UAAU,QAAQ,MAAM,KAAK;CACnC,MAAM,KAAK,QAAQ,IAAI;CACvB,IAAI,MAAM,MAAM;EACb,QAAQ,MAAM,+EAA+E;EAC7F,OAAO;CACV;CAGA,MAAM,QAAQ,QAAQ,OAAO;CAC7B,MAAM,SAAS,QAAQ,SAAS,KAAK,QAAQ,IAAI;CACjD,MAAM,OAAO,MAAM,KAAK;EAAE;EAAI,KAAK;EAAS,QAAQ,UAAU,KAAA;CAAU,CAAC;CAEzE,MAAM,YAAY,OAAU,UAA8B;EACvD,QAAQ,IAAI,2BAA2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node:url");
|
|
42
42
|
//#region package.json
|
|
43
|
-
var version = "1.
|
|
43
|
+
var version = "1.3.0";
|
|
44
44
|
//#endregion
|
|
45
45
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
46
46
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -754,6 +754,25 @@ const containerInstanceSlotType = (opts) => {
|
|
|
754
754
|
if (subs.length !== 1 || first == null || typeof first.type !== "string") return null;
|
|
755
755
|
return first.type;
|
|
756
756
|
};
|
|
757
|
+
/**
|
|
758
|
+
* frontend-registered widgets whose object_info opts carry NO config signal —
|
|
759
|
+
* the one exception to config-only classification (architecture.md rule 8).
|
|
760
|
+
* Every entry must quote the frontend widget-creation source.
|
|
761
|
+
*
|
|
762
|
+
* LOAD_3D (ComfyUI_frontend src/extensions/core/load3d.ts, verified
|
|
763
|
+
* 2026-07-31): the LOAD_3D custom widget handler runs
|
|
764
|
+
* node.addWidget('button', 'upload 3d model', 'upload3dmodel', …)
|
|
765
|
+
* node.addWidget('button', 'upload extra resources', 'uploadExtraResources', …)
|
|
766
|
+
* node.addWidget('button', 'clear', 'clear', …)
|
|
767
|
+
* THEN creates the scene widget, so the serialized run is
|
|
768
|
+
* [btn, btn, btn, value] with the real value LAST. Lax domain: '' in saved
|
|
769
|
+
* files, an {image, mask, normal, camera_info, …} dict at queue time.
|
|
770
|
+
*/
|
|
771
|
+
const EMPTY_CONFIG_FRONTEND_WIDGETS = { LOAD_3D: { prefixValues: [
|
|
772
|
+
"upload3dmodel",
|
|
773
|
+
"uploadExtraResources",
|
|
774
|
+
"clear"
|
|
775
|
+
] } };
|
|
757
776
|
const classifyWidgetInput = (p) => {
|
|
758
777
|
const o = isRecord(p.opts) ? p.opts : null;
|
|
759
778
|
if (o?.["forceInput"] === true) return { kind: "slot" };
|
|
@@ -762,7 +781,8 @@ const classifyWidgetInput = (p) => {
|
|
|
762
781
|
return {
|
|
763
782
|
kind: "widget",
|
|
764
783
|
consumes: controlConsumes(o, tn, p.name),
|
|
765
|
-
strictValues: true
|
|
784
|
+
strictValues: true,
|
|
785
|
+
prefixValues: []
|
|
766
786
|
};
|
|
767
787
|
}
|
|
768
788
|
if (typeof p.type !== "string") return { kind: "slot" };
|
|
@@ -770,7 +790,8 @@ const classifyWidgetInput = (p) => {
|
|
|
770
790
|
if (ComfyPrimitiveMapping[widgetTypeName] != null) return {
|
|
771
791
|
kind: "widget",
|
|
772
792
|
consumes: controlConsumes(o, widgetTypeName, p.name),
|
|
773
|
-
strictValues: true
|
|
793
|
+
strictValues: true,
|
|
794
|
+
prefixValues: []
|
|
774
795
|
};
|
|
775
796
|
const options = o?.["options"];
|
|
776
797
|
if (Array.isArray(options)) {
|
|
@@ -787,7 +808,8 @@ const classifyWidgetInput = (p) => {
|
|
|
787
808
|
return {
|
|
788
809
|
kind: "widget",
|
|
789
810
|
consumes: controlConsumes(o, p.type, p.name),
|
|
790
|
-
strictValues: true
|
|
811
|
+
strictValues: true,
|
|
812
|
+
prefixValues: []
|
|
791
813
|
};
|
|
792
814
|
}
|
|
793
815
|
const template = o?.["template"];
|
|
@@ -798,7 +820,15 @@ const classifyWidgetInput = (p) => {
|
|
|
798
820
|
if (o?.["socketless"] === true) return {
|
|
799
821
|
kind: "widget",
|
|
800
822
|
consumes: 1,
|
|
801
|
-
strictValues: false
|
|
823
|
+
strictValues: false,
|
|
824
|
+
prefixValues: []
|
|
825
|
+
};
|
|
826
|
+
const emptyConfigEntry = EMPTY_CONFIG_FRONTEND_WIDGETS[widgetTypeName];
|
|
827
|
+
if (emptyConfigEntry != null) return {
|
|
828
|
+
kind: "widget",
|
|
829
|
+
consumes: emptyConfigEntry.prefixValues.length + 1,
|
|
830
|
+
strictValues: false,
|
|
831
|
+
prefixValues: emptyConfigEntry.prefixValues
|
|
802
832
|
};
|
|
803
833
|
return { kind: "slot" };
|
|
804
834
|
};
|
|
@@ -808,11 +838,6 @@ const classifySchemaInput = (input) => classifyWidgetInput({
|
|
|
808
838
|
opts: input.opts,
|
|
809
839
|
isEnumUnion: input.isEnum
|
|
810
840
|
});
|
|
811
|
-
/** how many widgets_values entries this schema input consumes (export path + positional walks) */
|
|
812
|
-
const howManyWidgetValuesForThisSchemaType = (input) => {
|
|
813
|
-
const kind = classifySchemaInput(input);
|
|
814
|
-
return kind.kind === "widget" ? kind.consumes : 0;
|
|
815
|
-
};
|
|
816
841
|
/**
|
|
817
842
|
* what ComfyUI's frontend gives a widget created with no serialized value
|
|
818
843
|
* (`getWidgetDefaultValue` semantics), used when a positional array is
|
|
@@ -914,15 +939,15 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
914
939
|
if (!p.strict && isRecord(value)) return value;
|
|
915
940
|
throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}) has an invalid widget value for "${p.promptName}": ${JSON.stringify(value)}`, node);
|
|
916
941
|
};
|
|
917
|
-
/** named wins, then positional cursor; filled=true when both miss (caller falls back to the schema default) */
|
|
942
|
+
/** named wins, then positional cursor (+prefixLen skips leading button values, LOAD_3D); filled=true when both miss (caller falls back to the schema default) */
|
|
918
943
|
const resolveWidgetValue = (p) => {
|
|
919
944
|
let value;
|
|
920
945
|
let has = false;
|
|
921
946
|
if (Object.hasOwn(named, p.promptName)) {
|
|
922
947
|
value = named[p.promptName];
|
|
923
948
|
has = true;
|
|
924
|
-
} else if (offset < positional.length) {
|
|
925
|
-
value = positional[offset];
|
|
949
|
+
} else if (offset + p.prefixLen < positional.length) {
|
|
950
|
+
value = positional[offset + p.prefixLen];
|
|
926
951
|
has = true;
|
|
927
952
|
}
|
|
928
953
|
if (positional.length > 0) offset += p.consumes;
|
|
@@ -934,7 +959,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
934
959
|
const consumePlainWidget = (p) => {
|
|
935
960
|
const r = resolveWidgetValue({
|
|
936
961
|
promptName: p.promptName,
|
|
937
|
-
consumes: p.consumes
|
|
962
|
+
consumes: p.consumes,
|
|
963
|
+
prefixLen: p.prefixLen
|
|
938
964
|
});
|
|
939
965
|
const raw = r.filled ? defaultValueForWidget({
|
|
940
966
|
type: p.typeName,
|
|
@@ -953,7 +979,8 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
953
979
|
const consumeDynamicCombo = (p) => {
|
|
954
980
|
const r = resolveWidgetValue({
|
|
955
981
|
promptName: p.path,
|
|
956
|
-
consumes: 1
|
|
982
|
+
consumes: 1,
|
|
983
|
+
prefixLen: 0
|
|
957
984
|
});
|
|
958
985
|
const key = r.filled ? p.defaultKey : r.value;
|
|
959
986
|
if (typeof key !== "string") throw new WorkflowConvertError("invalid-widget-value", `node ${node.id}(${node.type}): dynamic combo "${p.path}" key is not a string: ${JSON.stringify(key)}`, node);
|
|
@@ -981,6 +1008,7 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
981
1008
|
typeName: typeof sub.type === "string" ? sub.type : "COMBO",
|
|
982
1009
|
opts: sub.opts,
|
|
983
1010
|
consumes: kind.consumes,
|
|
1011
|
+
prefixLen: kind.prefixValues.length,
|
|
984
1012
|
strict: kind.strictValues,
|
|
985
1013
|
enumValues: inlineEnum,
|
|
986
1014
|
linkedInput: inputsInNodeJSON.find((i) => i.name === subPath)
|
|
@@ -992,13 +1020,15 @@ const convertLiteGraphToPrompt = (schema, workflow, opts = {}) => {
|
|
|
992
1020
|
if (kind.kind === "slot" && input?.widgetName != null) kind = {
|
|
993
1021
|
kind: "widget",
|
|
994
1022
|
consumes: howManyWidgetValuesForThisInputType(input.type, field.nameInComfy) === 2 ? 2 : 1,
|
|
995
|
-
strictValues: true
|
|
1023
|
+
strictValues: true,
|
|
1024
|
+
prefixValues: []
|
|
996
1025
|
};
|
|
997
1026
|
if (kind.kind === "widget") consumePlainWidget({
|
|
998
1027
|
promptName: field.nameInComfy,
|
|
999
1028
|
typeName: field.typeName,
|
|
1000
1029
|
opts: field.opts,
|
|
1001
1030
|
consumes: kind.consumes,
|
|
1031
|
+
prefixLen: kind.prefixValues.length,
|
|
1002
1032
|
strict: kind.strictValues,
|
|
1003
1033
|
linkedInput: input
|
|
1004
1034
|
});
|
|
@@ -1498,7 +1528,7 @@ const convertNodeToLiteGraphNode = (ctx, node) => {
|
|
|
1498
1528
|
const widgets_values = [];
|
|
1499
1529
|
for (const ipt of node.$schema.inputs) {
|
|
1500
1530
|
const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy]);
|
|
1501
|
-
const
|
|
1531
|
+
const kind = classifySchemaInput(ipt);
|
|
1502
1532
|
if (_isLink(raw)) {
|
|
1503
1533
|
const nodeUidNumber = bang(ctx.graph.nodes.find((n) => n.uid === raw[0])?.uidNumber, `link target node "${raw[0]}" not found in graph`);
|
|
1504
1534
|
inputs.push({
|
|
@@ -1506,9 +1536,10 @@ const convertNodeToLiteGraphNode = (ctx, node) => {
|
|
|
1506
1536
|
type: ipt.typeName,
|
|
1507
1537
|
link: ctx.allocateLink(nodeUidNumber, raw[1], node.uidNumber, asLiteGraphSlotIndex(inputs.length), ipt.typeName)
|
|
1508
1538
|
});
|
|
1509
|
-
} else if (
|
|
1510
|
-
widgets_values.push(raw);
|
|
1511
|
-
|
|
1539
|
+
} else if (kind.kind === "widget") {
|
|
1540
|
+
widgets_values.push(...kind.prefixValues, raw);
|
|
1541
|
+
const phantoms = kind.consumes - 1 - kind.prefixValues.length;
|
|
1542
|
+
for (let i = 0; i < phantoms; i++) widgets_values.push(false);
|
|
1512
1543
|
} else inputs.push({
|
|
1513
1544
|
name: ipt.nameInComfy,
|
|
1514
1545
|
type: ipt.typeName,
|
|
@@ -1554,6 +1585,65 @@ var LiteGraphCtx = class {
|
|
|
1554
1585
|
}
|
|
1555
1586
|
};
|
|
1556
1587
|
//#endregion
|
|
1588
|
+
//#region src/runner/outputPath.ts
|
|
1589
|
+
/**
|
|
1590
|
+
* local output naming, relative to `.comfy-ts/outputs/` (his repro
|
|
1591
|
+
* 2026-07-31): the server filename is NOT unique — cloud hosts reset the
|
|
1592
|
+
* `_00001_` counter every run, so trusting it overwrote the same file — and
|
|
1593
|
+
* a `foo/krea/` prefix means the DIRECTORY foo/krea/, not a `krea_` name
|
|
1594
|
+
* prefix. Local names are ours: dir from the prompt's own filename_prefix
|
|
1595
|
+
* (or an explicit saveFormat.prefix override), then
|
|
1596
|
+
* `<stem>_<timestamp>_<counter><ext>` so every run sorts chronologically
|
|
1597
|
+
* per stem and nothing ever collides.
|
|
1598
|
+
*/
|
|
1599
|
+
const localOutputPath = (p) => {
|
|
1600
|
+
const dot = p.filename.lastIndexOf(".");
|
|
1601
|
+
const ext = dot === -1 ? "" : p.filename.slice(dot);
|
|
1602
|
+
const base = dot === -1 ? p.filename : p.filename.slice(0, dot);
|
|
1603
|
+
const counterMatch = /_(\d+)_$/.exec(base);
|
|
1604
|
+
const counter = counterMatch?.[1];
|
|
1605
|
+
const serverStem = counterMatch != null ? base.slice(0, base.length - counterMatch[0].length) : base;
|
|
1606
|
+
let dir;
|
|
1607
|
+
let stem;
|
|
1608
|
+
if (p.filenamePrefix != null && p.filenamePrefix !== "") {
|
|
1609
|
+
const slash = p.filenamePrefix.lastIndexOf("/");
|
|
1610
|
+
dir = slash === -1 ? "" : p.filenamePrefix.slice(0, slash);
|
|
1611
|
+
stem = slash === -1 ? p.filenamePrefix : p.filenamePrefix.slice(slash + 1);
|
|
1612
|
+
} else {
|
|
1613
|
+
dir = p.subfolder;
|
|
1614
|
+
stem = serverStem;
|
|
1615
|
+
}
|
|
1616
|
+
if (p.localDir != null) dir = p.localDir;
|
|
1617
|
+
const name = [
|
|
1618
|
+
stem === "" ? null : stem,
|
|
1619
|
+
p.timestamp,
|
|
1620
|
+
counter
|
|
1621
|
+
].filter((x) => x != null).join("_") + ext;
|
|
1622
|
+
return dir === "" ? name : `${dir}/${name}`;
|
|
1623
|
+
};
|
|
1624
|
+
/**
|
|
1625
|
+
* never-overwrite guard: bump `-2`, `-3`, … while the path exists on disk OR
|
|
1626
|
+
* was already CLAIMED by a still-downloading retrieval (two same-second runs
|
|
1627
|
+
* on a counter-resetting cloud host compute the same name — reviewer catch).
|
|
1628
|
+
* The chosen path is claimed before returning.
|
|
1629
|
+
*/
|
|
1630
|
+
const uniquifyOutputPath = (p) => {
|
|
1631
|
+
let out = p.path;
|
|
1632
|
+
if (p.exists(out) || p.claimed.has(out)) {
|
|
1633
|
+
const dot = out.lastIndexOf(".");
|
|
1634
|
+
const stem = dot === -1 ? out : out.slice(0, dot);
|
|
1635
|
+
const ext = dot === -1 ? "" : out.slice(dot);
|
|
1636
|
+
for (let n = 2; p.exists(out) || p.claimed.has(out); n++) out = `${stem}-${n}${ext}`;
|
|
1637
|
+
}
|
|
1638
|
+
p.claimed.add(out);
|
|
1639
|
+
return out;
|
|
1640
|
+
};
|
|
1641
|
+
/** YYYYMMDD-HHmmss, local time — sortable, text-encodable, no colons for filesystems */
|
|
1642
|
+
const runTimestamp = (d) => {
|
|
1643
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
1644
|
+
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
1645
|
+
};
|
|
1646
|
+
//#endregion
|
|
1557
1647
|
//#region src/types/index.ts
|
|
1558
1648
|
const asAbsolutePath = (path) => path;
|
|
1559
1649
|
const asRelativePath = (path) => path;
|
|
@@ -1902,6 +1992,9 @@ var MediaImage = class MediaImage {
|
|
|
1902
1992
|
};
|
|
1903
1993
|
//#endregion
|
|
1904
1994
|
//#region src/runner/ComfyExecution.ts
|
|
1995
|
+
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
1996
|
+
* counter-resetting cloud host compute the same name before either writes */
|
|
1997
|
+
const CLAIMED_OUTPUT_PATHS = /* @__PURE__ */ new Set();
|
|
1905
1998
|
var ComfyExecution = class {
|
|
1906
1999
|
get host() {
|
|
1907
2000
|
return this.workflow.host;
|
|
@@ -1967,11 +2060,23 @@ var ComfyExecution = class {
|
|
|
1967
2060
|
if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`);
|
|
1968
2061
|
const imgRoute = "/view?" + new URLSearchParams(comfyImageInfo).toString();
|
|
1969
2062
|
const sf = this.saveFormat;
|
|
1970
|
-
|
|
2063
|
+
const promptPrefix = promptNode.inputs["filename_prefix"];
|
|
2064
|
+
let absPath = comfyts.resolveFromOutput(localOutputPath({
|
|
2065
|
+
localDir: sf?.prefix,
|
|
2066
|
+
filenamePrefix: typeof promptPrefix === "string" ? promptPrefix : void 0,
|
|
2067
|
+
subfolder: comfyImageInfo.subfolder,
|
|
2068
|
+
filename: comfyImageInfo.filename,
|
|
2069
|
+
timestamp: runTimestamp(new Date(this.startedAt))
|
|
2070
|
+
}));
|
|
1971
2071
|
if (sf?.format && sf.format !== "raw") {
|
|
1972
2072
|
const extension = sf.format.split("/")[1];
|
|
1973
2073
|
absPath += "." + extension;
|
|
1974
2074
|
}
|
|
2075
|
+
absPath = uniquifyOutputPath({
|
|
2076
|
+
path: absPath,
|
|
2077
|
+
exists: node_fs.existsSync,
|
|
2078
|
+
claimed: CLAIMED_OUTPUT_PATHS
|
|
2079
|
+
});
|
|
1975
2080
|
(0, node_fs.mkdirSync)((0, pathe.dirname)(absPath), { recursive: true });
|
|
1976
2081
|
let img;
|
|
1977
2082
|
if (sf && sf.format !== "raw") {
|
|
@@ -3725,6 +3830,12 @@ var SeedVar = class extends ComfyVar {
|
|
|
3725
3830
|
afterRun() {
|
|
3726
3831
|
this.advance();
|
|
3727
3832
|
}
|
|
3833
|
+
/** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
|
|
3834
|
+
* ('=' is the construction default; drafts restore their own mode via loadJSON) */
|
|
3835
|
+
reset() {
|
|
3836
|
+
this.setMode("=");
|
|
3837
|
+
return super.reset();
|
|
3838
|
+
}
|
|
3728
3839
|
/** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
|
|
3729
3840
|
parse(raw) {
|
|
3730
3841
|
const m = raw.trim().match(/^([+\-=?])?\s*(\d+)?$/);
|