comfy-ts 2.16.0 → 2.17.1

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 (71) hide show
  1. package/README.md +23 -0
  2. package/dist/{run-serve-C78hD7t9.js → ServeApp-qXcQfdgT.js} +18 -445
  3. package/dist/ServeApp-qXcQfdgT.js.map +1 -0
  4. package/dist/cli.js +72 -9
  5. package/dist/cli.js.map +1 -1
  6. package/dist/exampleAssets-BfWzygoM.js +38 -0
  7. package/dist/exampleAssets-BfWzygoM.js.map +1 -0
  8. package/dist/{LogsSt-Ct7Le0S_.js → findDefinedWorkflow-0lG-VTEd.js} +201 -201
  9. package/dist/findDefinedWorkflow-0lG-VTEd.js.map +1 -0
  10. package/dist/index.cjs +182 -69
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +61 -8
  13. package/dist/index.d.ts +61 -8
  14. package/dist/index.js +182 -69
  15. package/dist/index.js.map +1 -1
  16. package/dist/run-run-tg82jUIk.js +450 -0
  17. package/dist/run-run-tg82jUIk.js.map +1 -0
  18. package/dist/run-serve-DaXzoVTS.js +464 -0
  19. package/dist/run-serve-DaXzoVTS.js.map +1 -0
  20. package/dist/{run-tui-nPETFRmk.js → run-tui-Bw7BA75d.js} +7 -38
  21. package/dist/run-tui-Bw7BA75d.js.map +1 -0
  22. package/dist/{schemaDrift-wb5XkrHV.js → schemaDrift-CbsABBuk.js} +3 -2
  23. package/dist/{schemaDrift-wb5XkrHV.js.map → schemaDrift-CbsABBuk.js.map} +1 -1
  24. package/dist/serve-web.js +56 -48
  25. package/dist/{state-BMW57_M0.js → state-zTow5ucI.js} +182 -70
  26. package/dist/state-zTow5ucI.js.map +1 -0
  27. package/dist/web.d.ts +61 -8
  28. package/dist/web.js +182 -69
  29. package/dist/web.js.map +1 -1
  30. package/examples/README.md +1 -0
  31. package/examples/rvion/15-tts-voice-clone.cflow.ts +8 -8
  32. package/examples/rvion/16-tts-voice-design.cflow.ts +71 -0
  33. package/guide-for-agents.md +3 -0
  34. package/package.json +2 -2
  35. package/src/cli/bunHop.ts +49 -0
  36. package/src/cli/comfy-ts-cli.ts +18 -5
  37. package/src/cli/run/findModules.ts +36 -0
  38. package/src/cli/run/flagValue.ts +61 -0
  39. package/src/cli/run/outputPaths.ts +41 -0
  40. package/src/cli/run/pickModule.ts +41 -0
  41. package/src/cli/run/run-run.ts +250 -0
  42. package/src/cli/run/runArgs.ts +61 -0
  43. package/src/cli/run/sidecar.ts +27 -0
  44. package/src/cli/serve/ServeApp.ts +13 -39
  45. package/src/cli/serve/run-serve.ts +51 -13
  46. package/src/cli/serve/web/components/App.tsx +2 -0
  47. package/src/cli/serve/web/components/DialogLayer.tsx +55 -0
  48. package/src/cli/serve/web/components/DraftTabs.tsx +16 -5
  49. package/src/cli/serve/web/components/PromptEnhancer.tsx +15 -9
  50. package/src/cli/serve/web/components/SideMenu.tsx +16 -8
  51. package/src/cli/serve/web/state/WebSt.ts +10 -1
  52. package/src/cli/serve/web/state/dialog.ts +59 -0
  53. package/src/cli/serve/web/state/draftTabs.ts +12 -0
  54. package/src/cli/serve/web/state/keptLines.ts +1 -1
  55. package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
  56. package/src/cli/serve/web/styles.ts +8 -0
  57. package/src/coreExports.ts +2 -0
  58. package/src/host/ComfyHost.ts +73 -40
  59. package/src/host/previewMethod.ts +29 -0
  60. package/src/litegraph/convertFlowToLiteGraphJSON.ts +38 -20
  61. package/src/promptEnhancers.ts +1 -1
  62. package/src/runner/ComfyExecution.ts +45 -1
  63. package/src/runner/ComfyWorkflow.ts +6 -1
  64. package/src/runner/ComfyWsApi.ts +1 -1
  65. package/src/runner/wsBinaryFrame.ts +48 -25
  66. package/src/vars/ComfyVars.ts +3 -0
  67. package/src/vars/DefinedWorkflow.ts +1 -0
  68. package/dist/LogsSt-Ct7Le0S_.js.map +0 -1
  69. package/dist/run-serve-C78hD7t9.js.map +0 -1
  70. package/dist/run-tui-nPETFRmk.js.map +0 -1
  71. package/dist/state-BMW57_M0.js.map +0 -1
@@ -9,6 +9,7 @@ Every `*.cflow.ts` file here is a runnable workflow module: run it directly with
9
9
  - `rvion/06-qwen-image-edit.cflow.ts` — image editing (qwen image edit 2511) against the same local host.
10
10
  - `rvion/07-local-llm-text-gen.cflow.ts` — a local LLM, no image: core's `TextGenerate` runs a chat model loaded through `CLIPLoader`, and the text comes back in `execution.text`. `--sweep` reports which text encoders on your host actually generate.
11
11
  - `rvion/08-qwen-image-21-t2i.cflow.ts` / `rvion/09-qwen-image-21-edit.cflow.ts` — Qwen Image 2.1 (ComfyUI ≥ 0.37) against the same local host: text to image, and instruction editing of one reference image (its `remove background` preset is the official background-removal template).
12
+ - `rvion/16-tts-voice-design.cflow.ts`: a new voice from a written description (needs TTS-Audio-Suite, Qwen3-TTS VoiceDesign): it speaks one sample line in that voice, and the clip plus that line are what `15-tts-voice-clone` takes as `voice` and `transcript`. From the command line the flow is two runs: `comfy-ts run tts-voice-design --description "…" --line "…" --out voices/sailor.flac` writes the clip and `voices/sailor.txt`, then `comfy-ts run tts-voice-clone --voice voices/sailor.flac --prompt "…" --out lines/001.flac` speaks any line in it.
12
13
  - `rvion/15-tts-voice-clone.cflow.ts` — text to speech in a cloned voice (needs the [TTS-Audio-Suite](https://github.com/diodiogod/TTS-Audio-Suite) custom node pack on the host): pick an engine (Chatterbox Multilingual v3 by default, Qwen3-TTS, Fish Audio S2 Pro, CosyVoice3, OmniVoice) and a language, drop a voice clip and write its transcript, and the text comes back as audio in `execution.audios`.
13
14
  - `comfy-cloud/<family>-<mode>.cflow.ts` — the model zoo: one clean example per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring an official ComfyUI template (flux, qwen-image, z-image, wan, hidream, ace-step, …). All share `comfy-cloud/cloudHost.ts`.
14
15
 
@@ -27,8 +27,13 @@ const LANGUAGES = [
27
27
  'Chinese',
28
28
  ] as const
29
29
 
30
- // bundled default (examples/media/, ships in the tarball)
31
- const voice = v.audio(exampleMediaPath('voice_en_6s.flac'))
30
+ const transcript = v.text(
31
+ 'This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages.',
32
+ { label: 'transcript of the voice clip' },
33
+ )
34
+ // bundled default (examples/media/, ships in the tarball). A clip's `<clip>.txt` is its
35
+ // transcript when `comfy-ts run` sets the clip and leaves the transcript alone
36
+ const voice = v.audio(exampleMediaPath('voice_en_6s.flac'), { sidecarText: transcript })
32
37
 
33
38
  export const ttsVoiceClone = host.defineWorkflow({
34
39
  id: 'tts-voice-clone',
@@ -41,12 +46,7 @@ export const ttsVoiceClone = host.defineWorkflow({
41
46
  engine: v.choice(ENGINES, 'chatterbox', 'engine'),
42
47
  language: v.choice(LANGUAGES, 'English', 'language'),
43
48
  voice,
44
- transcript: v.text(
45
- 'This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages.',
46
- {
47
- label: 'transcript of the voice clip',
48
- },
49
- ),
49
+ transcript,
50
50
  },
51
51
  // async build: the voice clip is uploaded (hash-named, deduped) per run
52
52
  build: async (b, vars, wf) => {
@@ -0,0 +1,71 @@
1
+ // a new voice from a written description, on windows-1: Qwen3-TTS VoiceDesign speaks one sample
2
+ // line in the voice you describe. The clip and that line are the pair 15-tts-voice-clone takes
3
+ // as `voice` and `transcript`, so every later line keeps the same voice. The line comes back
4
+ // as a text output too: `comfy-ts run` writes it beside the clip as its transcript
5
+ // box inventory: custom node pack TTS-Audio-Suite (github.com/diodiogod/TTS-Audio-Suite); the
6
+ // VoiceDesign checkpoint downloads on first use, which takes minutes
7
+ // run directly: bun examples/rvion/16-tts-voice-design.cflow.ts ["description"] ["line"]
8
+ import { ComfyTS, v } from 'comfy-ts'
9
+
10
+ const comfy = ComfyTS.create()
11
+ const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
12
+ await host.loadSchemaFromCache() // offline import; run() connects lazily
13
+
14
+ const LANGUAGES = [
15
+ 'English',
16
+ 'French',
17
+ 'German',
18
+ 'Spanish',
19
+ 'Italian',
20
+ 'Portuguese',
21
+ 'Russian',
22
+ 'Japanese',
23
+ 'Korean',
24
+ 'Chinese',
25
+ ] as const
26
+
27
+ export const ttsVoiceDesign = host.defineWorkflow({
28
+ id: 'tts-voice-design',
29
+ tags: ['tts', 'voice'],
30
+ vars: {
31
+ description: v.text('An old sailor, gravelly and warm, slow pace, a smile in the voice.', {
32
+ label: 'the voice: age, gender, pitch, texture, accent, pace, mood',
33
+ }),
34
+ line: v.text('Ahoy, and welcome aboard. The sea is calm tonight, so sit down and listen to my story.', {
35
+ label: 'what the sample says (8 to 12 s of speech clones best)',
36
+ }),
37
+ language: v.choice(LANGUAGES, 'English', 'language'),
38
+ seed: v.seed(7),
39
+ },
40
+ build: (b, vars) => {
41
+ const S = 'TTS-Audio-Suite'
42
+ const engine = b[`${S}.Qwen3TTSEngineNode`]({
43
+ model_variant: 'Voice Design - 1.7B VoiceDesign',
44
+ device: 'auto',
45
+ voice_preset: 'None (Zero-shot / Custom)',
46
+ language: vars.language,
47
+ instruct: '',
48
+ })
49
+ const designed = b[`${S}.UnifiedVoiceDesignerNode`]({
50
+ TTS_engine: engine.outputs.TTS_engine,
51
+ reference_text: vars.line,
52
+ voice_instruction: vars.description,
53
+ seed: vars.seed,
54
+ })
55
+ b.PreviewAudio({ audio: designed.outputs.preview_audio })
56
+ // the transcript of the clip: the line itself, as a text output
57
+ b.PreviewAny({ source: vars.line })
58
+ },
59
+ })
60
+
61
+ export default ttsVoiceDesign
62
+
63
+ // standalone run (skipped when another driver, like the TUI, imports this module)
64
+ if (import.meta.main) {
65
+ if (process.argv[2]) ttsVoiceDesign.vars.description.set(process.argv[2])
66
+ if (process.argv[3]) ttsVoiceDesign.vars.line.set(process.argv[3])
67
+
68
+ const execution = await ttsVoiceDesign.run({ log: true, save: { prefix: 'comfy-ts-example/tts-voice-design' } })
69
+ for (const clip of execution.audios) console.log(`🟢 ${clip.absPath}`)
70
+ host.disconnect()
71
+ }
@@ -96,8 +96,11 @@ bunx comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188] # codegen
96
96
  bunx comfy-ts outline [file] [--section Name] [--lines N] # inspect a sdk.d.ts
97
97
  bunx comfy-ts loras [--id <host-id>] [--host http://…] # mirror lora metadata (optional ComfyUI-Lora-Manager extension)
98
98
  bunx comfy-ts tui [dir | module.cflow.ts] # interactive tweak & re-run
99
+ bunx comfy-ts run <name | module.cflow.ts> [--draft <name>] [--<var> <value>…] [--out <path>] [--json] # one generation, headless
99
100
  ```
100
101
 
102
+ `comfy-ts run` is how an agent generates: the module is found in the cwd, then in the bundled examples, by key or a unique part of it (`folder/name` narrows, like `rvion/anima`). Every var is a flag (`--prompt "…" --seed 7 --image in.png`, `--<var>-file` reads a text var from a file), `--out` says where the output goes, and `--json` prints one line with every output path. `comfy-ts run <name> --help` lists the vars. Every flag is a var name the module declares. A media var declared with `sidecarText: someTextVar` fills that text var from `<file>.txt` beside the file it is given (a voice clip's transcript, example 15).
103
+
101
104
  `comfy-ts loras` writes `.comfy-ts/hosts/<id>/loras.json`: per lora, the model's real name, its civitai trigger words, tags, base model and preview url, stored raw. It is what makes `v.prompt(text, { loraKeywordsFrom: lorasVar })` inject a lora's trigger words with nothing typed by hand, and what lets the TUI find a lora by its human name. Read it yourself (`getLoraInfo`, `getLoraTriggerWords`, `getLoraDisplayName`) when a user asks which lora to pick. Absent extension or no sync yet: every getter answers empty, nothing breaks.
102
105
 
103
106
  The TUI scans `**/*.cflow.ts` (no arg: cwd PLUS the examples bundled with the package, grouped apart in the tree; an explicit dir or file limits to that scope), shows vars as editable knobs, runs with live progress and previews, and saves named drafts under `.comfy-ts/drafts/`. It re-execs through bun when launched under node (workflow modules are TypeScript, and node cannot import .ts from node_modules). Point users at it; as an agent you run modules with `bun path/to/module.cflow.ts`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.16.0",
3
+ "version": "2.17.1",
4
4
  "description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -140,7 +140,7 @@
140
140
  "oxfmt": "^0.60.0",
141
141
  "oxlint": "^1.75.0",
142
142
  "oxlint-tsgolint": "^7.0.2001",
143
- "rvlib-shipkit": "^1.7.0",
143
+ "rvlib-shipkit": "^2.6.0",
144
144
  "rvlib-ts-tools": "^0.3.3",
145
145
  "tsdown": "^0.22.14",
146
146
  "typescript": "^7.0.2"
@@ -0,0 +1,49 @@
1
+ // `tui`, `serve` and `run` import .cflow.ts modules, which need bun: the bin's
2
+ // node shebang re-execs the same command line through it. The wrapper is the pid
3
+ // a terminal, a supervisor or an agent holds and stops, so the child must never
4
+ // outlive it (agent/architecture.md item 10)
5
+ import { spawn } from 'node:child_process'
6
+ import { constants } from 'node:os'
7
+
8
+ const HOP_PARENT_ENV = 'COMFY_TS_HOP_PARENT'
9
+ const FORWARDED: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGHUP']
10
+
11
+ /** runs `bun <argv>` with the terminal inherited, forwarding the stop signals;
12
+ * resolves the child's exit code, or `error` when bun cannot start */
13
+ export function hopToBun(argv: string[]): Promise<{ code: number } | { error: Error }> {
14
+ return new Promise((resolve) => {
15
+ const child = spawn('bun', argv, {
16
+ stdio: 'inherit',
17
+ env: { ...process.env, [HOP_PARENT_ENV]: String(process.pid) },
18
+ })
19
+ const forward = (signal: NodeJS.Signals): void => {
20
+ child.kill(signal)
21
+ }
22
+ for (const signal of FORWARDED) process.on(signal, forward)
23
+ const done = (r: { code: number } | { error: Error }): void => {
24
+ for (const signal of FORWARDED) process.off(signal, forward)
25
+ resolve(r)
26
+ }
27
+ child.once('error', (error) => done({ error }))
28
+ child.once('exit', (code, signal) => {
29
+ if (code != null) return done({ code })
30
+ done({ code: signal == null ? 1 : 128 + (constants.signals[signal] ?? 0) })
31
+ })
32
+ })
33
+ }
34
+
35
+ /** in the bun child: exit once the process that started it is gone. A SIGKILL to
36
+ * the wrapper reaches no handler, so the child polls its own ppid, which changes
37
+ * (to 1, or a subreaper) when its parent dies. It watches the ppid it started
38
+ * with, not the wrapper pid: a version manager shim may sit between the two */
39
+ export function armHopChild(p: { intervalMs?: number } = {}): void {
40
+ if (process.env[HOP_PARENT_ENV] == null) return
41
+ // a grandchild has another parent: it must never inherit the watch
42
+ Reflect.deleteProperty(process.env, HOP_PARENT_ENV)
43
+ const parent = process.ppid
44
+ setInterval(() => {
45
+ if (process.ppid === parent) return
46
+ console.error(`[comfy-ts] the process that started this one (pid ${parent}) is gone: exiting`)
47
+ process.exit(1)
48
+ }, p.intervalMs ?? 1000).unref()
49
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  // sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code
3
- import { spawnSync } from 'node:child_process'
3
+ import { armHopChild, hopToBun } from 'src/cli/bunHop.ts'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import { runGen } from 'src/cli/gen.ts'
6
6
  import { runLoras } from 'src/cli/loras.ts'
@@ -39,6 +39,15 @@ Usage:
39
39
  panel. No bundled examples, no auth, and any origin may call it: use
40
40
  --host beyond localhost only on a network you trust.
41
41
 
42
+ comfy-ts run <name | module.cflow.ts> [--draft <name>] [--<var> <value>…] [--out <path>] [--json]
43
+ ONE generation, headless, with live progress: the module is found in cwd,
44
+ then in the examples bundled with comfy-ts, by its key (10-anima-t2i), its
45
+ key without the number (anima-t2i) or a unique part (anima). Each var is a
46
+ flag (--prompt "…" --seed 7 --image in.png), --<var>-file reads a text var
47
+ from a file, --out writes the output there (several: a-1.png, a-2.png; a
48
+ dir keeps the server's names). \`comfy-ts run <name> --help\` lists the vars,
49
+ \`comfy-ts run\` lists the modules. --json prints one line with the paths
50
+
42
51
  comfy-ts help
43
52
  `
44
53
 
@@ -47,19 +56,23 @@ async function main(): Promise<number> {
47
56
  if (cmd === 'gen') return runGen(rest)
48
57
  if (cmd === 'outline') return runOutline(rest)
49
58
  if (cmd === 'loras') return runLoras(rest)
50
- if (cmd === 'tui' || cmd === 'serve') {
59
+ if (cmd === 'tui' || cmd === 'serve' || cmd === 'run') {
51
60
  // .cflow.ts workflow modules need bun: node refuses to strip types under
52
61
  // node_modules, exactly where the packaged examples live — and the bin's
53
62
  // node shebang means `bunx comfy-ts tui|serve` lands here under NODE. Hop
54
63
  // to bun when we are not already in it; without bun, degrade loudly.
55
64
  if (process.versions.bun == null) {
56
- const self = fileURLToPath(import.meta.url)
57
- const res = spawnSync('bun', [self, cmd, ...rest], { stdio: 'inherit' })
58
- if (res.error == null) return res.status ?? 1
65
+ const res = await hopToBun([fileURLToPath(import.meta.url), cmd, ...rest])
66
+ if ('code' in res) return res.code
59
67
  console.error(
60
68
  `[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`,
61
69
  )
62
70
  }
71
+ armHopChild()
72
+ if (cmd === 'run') {
73
+ const { runRun } = await import('src/cli/run/run-run.ts')
74
+ return runRun(rest)
75
+ }
63
76
  if (cmd === 'serve') {
64
77
  const { runServe } = await import('src/cli/serve/run-serve.ts')
65
78
  return runServe(rest)
@@ -0,0 +1,36 @@
1
+ // the `*.cflow.ts` modules under the cwd for `comfy-ts run`, walked with bounds: node_modules
2
+ // and dot dirs are never entered (a recursive readdir reads all of them before any filter,
3
+ // which stalls a run started in a big repo or a temp dir), and the walk stops MAX_DEPTH deep
4
+ import { existsSync, readdirSync } from 'node:fs'
5
+ import { dirname, join } from 'pathe'
6
+
7
+ export const MAX_DEPTH = 5
8
+
9
+ export function findModules(dir: string, depth = 0): string[] {
10
+ let entries: import('node:fs').Dirent[]
11
+ try {
12
+ entries = readdirSync(dir, { withFileTypes: true })
13
+ } catch {
14
+ return []
15
+ }
16
+ const out: string[] = []
17
+ for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
18
+ if (e.isFile() && /\.cflow\.tsx?$/.test(e.name)) out.push(join(dir, e.name))
19
+ else if (e.isDirectory() && depth < MAX_DEPTH && e.name !== 'node_modules' && !e.name.startsWith('.'))
20
+ out.push(...findModules(join(dir, e.name), depth + 1))
21
+ }
22
+ return out
23
+ }
24
+
25
+ /** the workspace a module belongs to: the nearest folder above it holding `.comfy-ts/` (its
26
+ * schema cache and its tuned drafts), or null. A run roots comfy-ts there, so it never writes a
27
+ * `.comfy-ts/` into whatever folder it was started from */
28
+ export function workspaceOf(file: string): string | null {
29
+ let dir = dirname(file)
30
+ while (true) {
31
+ if (existsSync(join(dir, '.comfy-ts'))) return dir
32
+ const up = dirname(dir)
33
+ if (up === dir) return null
34
+ dir = up
35
+ }
36
+ }
@@ -0,0 +1,61 @@
1
+ // one `--<var> <value>` flag, a string on the command line, as the value serve's payload takes
2
+ // for that var kind (applyVarPayload validates it after, so this only shapes, never judges)
3
+ import { isAbsolute, resolve } from 'pathe'
4
+ import type { ChoiceSelect, VarKind } from 'src/vars/ComfyVars.ts'
5
+
6
+ export type FlagSpec = { kind: VarKind; select?: ChoiceSelect }
7
+
8
+ const TRUE = new Set(['true', 'yes', '1', 'on'])
9
+ const FALSE = new Set(['false', 'no', '0', 'off'])
10
+
11
+ /** `raw` is `true` for a bare flag (`--upscale`) */
12
+ export function flagValue(p: {
13
+ name: string
14
+ spec: FlagSpec
15
+ raw: string | true
16
+ cwd: string
17
+ }): { value: unknown } | { error: string } {
18
+ const raw = p.raw
19
+ if (p.spec.kind === 'toggle') {
20
+ if (raw === true) return { value: true }
21
+ const v = raw.toLowerCase()
22
+ if (TRUE.has(v)) return { value: true }
23
+ if (FALSE.has(v)) return { value: false }
24
+ return { error: `--${p.name} is a toggle: true or false` }
25
+ }
26
+ if (raw === true) return { error: `--${p.name} needs a value` }
27
+ switch (p.spec.kind) {
28
+ case 'int':
29
+ case 'float':
30
+ return { value: raw }
31
+ case 'seed': {
32
+ // a random seed as a number: serve rerolls a '?' mode only when the payload leaves the seed out
33
+ if (raw === '?') return { value: Math.floor(Math.random() * 2 ** 32) }
34
+ const n = Number(raw)
35
+ return Number.isFinite(n) ? { value: n } : { error: `--${p.name} is a seed: a number, or ? for a random one` }
36
+ }
37
+ case 'choice':
38
+ if (p.spec.select === 'many')
39
+ return {
40
+ value: raw
41
+ .split(',')
42
+ .map((x) => x.trim())
43
+ .filter((x) => x !== ''),
44
+ }
45
+ if (p.spec.select === 'zero-or-one' && raw === 'none') return { value: null }
46
+ return { value: raw }
47
+ case 'loras':
48
+ try {
49
+ return { value: JSON.parse(raw) }
50
+ } catch {
51
+ return { error: `--${p.name} takes the loras as json, like '{"name.safetensors": 0.8}'` }
52
+ }
53
+ case 'image':
54
+ case 'audio':
55
+ case 'video':
56
+ // a url goes through as is: serve downloads it
57
+ return { value: /^https?:\/\//.test(raw) || isAbsolute(raw) ? raw : resolve(p.cwd, raw) }
58
+ default:
59
+ return { value: raw }
60
+ }
61
+ }
@@ -0,0 +1,41 @@
1
+ // where `comfy-ts run` writes each output. `--out a.png` and one output: exactly there, its
2
+ // extension swapped for the output's own when they differ (said on the line); several outputs
3
+ // are numbered (`a-1.png`); a dir keeps the server's filenames; no --out names them after the
4
+ // module and the prompt in the cwd. Pure: the caller says whether --out is a dir
5
+ import { basename, extname, join, resolve } from 'pathe'
6
+
7
+ export type Produced = { filename: string }
8
+ export type Destination = { path: string; note: string | null }
9
+
10
+ export function outputPaths(p: {
11
+ out: string | null
12
+ outIsDir: boolean
13
+ module: string
14
+ promptId: string
15
+ items: readonly Produced[]
16
+ cwd: string
17
+ }): Destination[] {
18
+ const n = p.items.length
19
+ if (p.out != null && p.outIsDir) {
20
+ const dir = resolve(p.cwd, p.out)
21
+ return p.items.map((it) => ({ path: join(dir, basename(it.filename)), note: null }))
22
+ }
23
+ const base = p.out == null ? join(p.cwd, `${p.module}-${p.promptId.slice(0, 8)}`) : resolve(p.cwd, p.out)
24
+ const asked = p.out == null ? '' : extname(base)
25
+ const stem = asked === '' ? base : base.slice(0, -asked.length)
26
+ return p.items.map((it, ix) => {
27
+ const own = extname(it.filename)
28
+ const path = `${stem}${n > 1 ? `-${ix + 1}` : ''}${own}`
29
+ const note =
30
+ asked !== '' && own !== '' && asked.toLowerCase() !== own.toLowerCase()
31
+ ? `the output is ${own}, not ${asked}`
32
+ : null
33
+ return { path, note }
34
+ })
35
+ }
36
+
37
+ /** the transcript or text beside the first media output: same stem, `.txt` */
38
+ export function sidecarPath(mediaPath: string): string {
39
+ const ext = extname(mediaPath)
40
+ return `${ext === '' ? mediaPath : mediaPath.slice(0, -ext.length)}.txt`
41
+ }
@@ -0,0 +1,41 @@
1
+ // `comfy-ts run <name>`: which module a name means, over the discovered files in their order
2
+ // (cwd first, then the bundled examples). A name may carry its folder (`rvion/anima`,
3
+ // `comfy-cloud/anima`), which narrows to modules in a folder of that name. Tiers, first hit
4
+ // wins: the exact module key, the key without its number (`anima-t2i` → `10-anima-t2i`), a
5
+ // prefix of that, a substring. Two modules on the first tier that hits is ambiguous, and the
6
+ // error names them with their folder
7
+ import { basename, dirname } from 'pathe'
8
+ import { moduleName } from 'src/cli/tui/treeRows.ts'
9
+
10
+ export type Picked = { file: string; key: string } | { error: string }
11
+
12
+ const bare = (key: string): string => key.replace(/^\d+-/, '')
13
+ const qualified = (file: string): string => `${basename(dirname(file))}/${moduleName(file)}`
14
+
15
+ export function pickModule(files: readonly string[], name: string): Picked {
16
+ const cut = name.lastIndexOf('/')
17
+ const folder = cut < 0 ? null : name.slice(0, cut).toLowerCase()
18
+ const n = name.slice(cut + 1).toLowerCase()
19
+ // one file per qualified name, the first one found: a cwd module shadows a bundled one
20
+ const byName = new Map<string, string>()
21
+ for (const f of files) {
22
+ if (folder != null && !qualified(f).toLowerCase().startsWith(`${folder}/`)) continue
23
+ if (!byName.has(qualified(f))) byName.set(qualified(f), f)
24
+ }
25
+ const all = [...byName.values()]
26
+ const tiers: ((k: string) => boolean)[] = [
27
+ (k) => k === n,
28
+ (k) => bare(k) === n,
29
+ (k) => bare(k).startsWith(n),
30
+ (k) => k.includes(n),
31
+ ]
32
+ for (const hit of tiers) {
33
+ const found = all.filter((f) => hit(moduleName(f).toLowerCase()))
34
+ if (found.length === 1) return { file: found[0]!, key: moduleName(found[0]!) }
35
+ if (found.length > 1)
36
+ return {
37
+ error: `'${name}' matches ${found.length} modules: ${found.map(qualified).join(', ')}. Name one, folder included`,
38
+ }
39
+ }
40
+ return { error: `no module matches '${name}'. Modules: ${all.map(qualified).join(', ')}` }
41
+ }