comfy-ts 1.1.0 → 1.2.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 (48) hide show
  1. package/README.md +21 -8
  2. package/dist/cli.js +4 -4552
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.cjs +53 -12
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +49 -23
  7. package/dist/index.d.ts +49 -23
  8. package/dist/index.js +53 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-tui-DZ22HDHI.js → run-tui-BAdizWsO.js} +722 -130
  11. package/dist/run-tui-BAdizWsO.js.map +1 -0
  12. package/dist/state-BYbxDgfr.js +5258 -0
  13. package/dist/state-BYbxDgfr.js.map +1 -0
  14. package/examples/README.md +6 -4
  15. package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
  16. package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +1 -1
  17. package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
  18. package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
  19. package/examples/{05-comfy-cloud.cflow.ts → rvion/05-comfy-cloud.cflow.ts} +2 -2
  20. package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
  21. package/package.json +4 -1
  22. package/src/cli/tui/components/CopyOverlay.tsx +25 -0
  23. package/src/cli/tui/components/Header.tsx +9 -4
  24. package/src/cli/tui/components/HostPanel.tsx +3 -2
  25. package/src/cli/tui/components/HostsOverlay.tsx +33 -0
  26. package/src/cli/tui/components/StatusBar.tsx +28 -9
  27. package/src/cli/tui/components/TreePanel.tsx +17 -7
  28. package/src/cli/tui/components/TuiApp.tsx +47 -5
  29. package/src/cli/tui/imagePicker/fsListing.ts +6 -4
  30. package/src/cli/tui/run-tui.tsx +47 -7
  31. package/src/cli/tui/state/DraftsSt.ts +3 -2
  32. package/src/cli/tui/state/ExecSt.ts +108 -12
  33. package/src/cli/tui/state/HostSt.ts +94 -10
  34. package/src/cli/tui/state/PickerSt.ts +8 -2
  35. package/src/cli/tui/state/QueueSt.ts +2 -2
  36. package/src/cli/tui/state/SettingsSt.ts +25 -7
  37. package/src/cli/tui/state/TreeSt.ts +139 -36
  38. package/src/cli/tui/state/TuiSt.ts +47 -6
  39. package/src/cli/tui/state/WorkflowsSt.ts +14 -2
  40. package/src/cli/tui/treeRows.ts +165 -0
  41. package/src/host/ComfyHost.ts +7 -0
  42. package/src/runner/ComfyWorkflowLayout.ts +6 -4
  43. package/src/state.ts +7 -1
  44. package/src/vars/ComfyVars.ts +25 -4
  45. package/src/vars/DefinedWorkflow.ts +21 -8
  46. package/dist/DefinedWorkflow-BYyu5dK9.js +0 -669
  47. package/dist/DefinedWorkflow-BYyu5dK9.js.map +0 -1
  48. package/dist/run-tui-DZ22HDHI.js.map +0 -1
@@ -1,9 +1,11 @@
1
1
  // Vars: the standard "tweak & re-run" contract. A workflow defined via
2
2
  // host.defineWorkflow({ vars, build }) rebuilds its graph from current var
3
3
  // values on every run — drivers (scripts, the TUI) edit vars between runs.
4
+ import { readFileSync } from 'node:fs'
4
5
  import { homedir } from 'node:os'
6
+ import { imageMeta } from 'image-meta'
5
7
  import { action, makeObservable, observable } from 'mobx'
6
- import { isAbsolute, join, resolve } from 'pathe'
8
+ import { basename, isAbsolute, join, resolve } from 'pathe'
7
9
  import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
8
10
 
9
11
  export type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size' | 'image'
@@ -445,17 +447,36 @@ export const DEFAULT_SIZE_PRESETS: SizePreset[] = [
445
447
  { label: '9:16 tall', width: 768, height: 1344 },
446
448
  ]
447
449
 
448
- /** width/height picker: presets + free `WxH` entry */
450
+ /** width/height picker: presets + free `WxH` entry + optionally the LIVE
451
+ * size of a linked image var (his ask 2026-07-30: the widget shows
452
+ * `WxH size of image '<name>'` as a pickable row) */
449
453
  export class SizeVar extends ComfyVar<SizeValue> {
450
454
  readonly kind = 'size' as const
451
455
  constructor(
452
456
  defaultValue: SizeValue = { width: 1024, height: 1024 },
453
457
  public readonly presets: SizePreset[] = DEFAULT_SIZE_PRESETS,
454
458
  label?: string,
459
+ public readonly imageVar?: ImageVar,
455
460
  ) {
456
461
  super(defaultValue, label)
457
462
  }
458
463
 
464
+ /** current dimensions of the linked image var — null when no link, unset
465
+ * path, or an unreadable/undecodable file (those errors belong to the
466
+ * image var itself, the size row simply disappears) */
467
+ imageSize(): { width: number; height: number; name: string } | null {
468
+ const iv = this.imageVar
469
+ if (iv == null || iv.value === '') return null
470
+ try {
471
+ const abs = iv.absPath()
472
+ const meta = imageMeta(new Uint8Array(readFileSync(abs)))
473
+ if (meta.width == null || meta.height == null) return null
474
+ return { width: meta.width, height: meta.height, name: basename(abs) }
475
+ } catch {
476
+ return null
477
+ }
478
+ }
479
+
459
480
  /** accepts '1024x768' / '1024×768' / a preset label */
460
481
  parse(raw: string): boolean {
461
482
  const m = raw.trim().match(/^(\d+)\s*[x×]\s*(\d+)$/)
@@ -569,8 +590,8 @@ export const v = {
569
590
  initial: Partial<Record<T, LoraStrength>> = {},
570
591
  label?: string,
571
592
  ): LorasVar<T> => new LorasVar(options, initial, label),
572
- size: (defaultValue?: SizeValue, opts: { presets?: SizePreset[]; label?: string } = {}): SizeVar =>
573
- new SizeVar(defaultValue, opts.presets, opts.label),
593
+ size: (defaultValue?: SizeValue, opts: { presets?: SizePreset[]; label?: string; image?: ImageVar } = {}): SizeVar =>
594
+ new SizeVar(defaultValue, opts.presets, opts.label, opts.image),
574
595
  image: (defaultValue: string, opts: ImageVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
575
596
  }
576
597
 
@@ -37,6 +37,9 @@ export type BoundVars<ID extends string> = Omit<typeof v, 'loras'> & {
37
37
  export type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {
38
38
  /** short id; also names the workflow instances */
39
39
  id?: string
40
+ /** optional TUI tree color (ink color name or hex); unset = the tree's
41
+ * per-family palette (first `-` word of the module basename) */
42
+ color?: string
40
43
  /** the tweakable knobs; drivers (scripts, TUI) edit these between runs.
41
44
  * A LAMBDA gives cross-referencing vars a scope (loras + prompt with
42
45
  * loraKeywordsFrom created inline) — resolved ONCE at define time, and it
@@ -94,10 +97,13 @@ export class DefinedWorkflow<ID extends string = string, V extends VarsSpec = Va
94
97
  * (set by run()) fires each var's afterRun() right after snapshotting the
95
98
  * values — atomically, before any await — so the graph uses this run's seed
96
99
  * while the var moves to the next (queued runs get distinct seeds; a bare
97
- * build() for copy/export never advances).
100
+ * build() for copy/export never advances). `p.host` substitutes the host
101
+ * the graph is built against (TUI host override): node/model availability
102
+ * there surfaces as workflow.problems / server validation, by design.
98
103
  */
99
- async build(p: { advance?: boolean } = {}): Promise<ComfyWorkflow<ID>> {
100
- const wf = this.host.workflow({ id: this.spec.id })
104
+ async build(p: { advance?: boolean; host?: ComfyHost<ID> } = {}): Promise<ComfyWorkflow<ID>> {
105
+ const host = p.host ?? this.host
106
+ const wf = host.workflow({ id: this.spec.id })
101
107
  const values = varValues(this.vars)
102
108
  if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun()
103
109
  await this.spec.build(wf.builder, values, wf)
@@ -106,11 +112,18 @@ export class DefinedWorkflow<ID extends string = string, V extends VarsSpec = Va
106
112
  }
107
113
 
108
114
  /** build a fresh graph from the current var values, send it, wait for outputs.
109
- * connects first (idempotent) — modules can import offline from the schema cache */
110
- async run(settings: RunSettings = {}): Promise<ComfyExecution> {
111
- await this.host.connect()
112
- const wf = await this.build({ advance: true })
113
- const execution = await wf.run(settings)
115
+ * connects first (idempotent) — modules can import offline from the schema cache.
116
+ * `settings.host` runs against THAT host instead of the defining one. */
117
+ async run(settings: RunSettings & { host?: ComfyHost<ID> } = {}): Promise<ComfyExecution> {
118
+ const host = settings.host ?? this.host
119
+ await host.connect()
120
+ const wf = await this.build({ advance: true, host })
121
+ const execution = await wf.run({
122
+ saveFormat: settings.saveFormat,
123
+ idMode: settings.idMode,
124
+ log: settings.log,
125
+ onProgress: settings.onProgress,
126
+ })
114
127
  this.lastExecution = execution
115
128
  return execution
116
129
  }