comfy-ts 1.0.0 → 1.1.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 (124) hide show
  1. package/README.md +42 -6
  2. package/dist/{DefinedWorkflow-O3ynII3Y.js → DefinedWorkflow-BYyu5dK9.js} +76 -5
  3. package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
  4. package/dist/cli.js +421 -308
  5. package/dist/cli.js.map +1 -1
  6. package/dist/index.cjs +394 -162
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +7426 -353
  9. package/dist/index.d.ts +7408 -335
  10. package/dist/index.js +393 -162
  11. package/dist/index.js.map +1 -1
  12. package/dist/{run-tui-BFhba_oG.js → run-tui-DZ22HDHI.js} +529 -78
  13. package/dist/run-tui-DZ22HDHI.js.map +1 -0
  14. package/examples/02-img2img-upload.cflow.ts +6 -17
  15. package/examples/05-comfy-cloud.cflow.ts +19 -35
  16. package/examples/README.md +30 -0
  17. package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
  18. package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
  19. package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
  20. package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
  21. package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
  22. package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
  23. package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
  24. package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
  25. package/examples/comfy-cloud/cloudHost.ts +41 -0
  26. package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
  27. package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
  28. package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
  29. package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
  30. package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
  31. package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
  32. package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
  33. package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
  34. package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
  35. package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
  36. package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
  37. package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
  38. package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
  39. package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
  40. package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
  41. package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
  42. package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
  43. package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
  44. package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
  45. package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
  46. package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
  47. package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
  48. package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
  49. package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
  50. package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
  51. package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
  52. package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
  53. package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
  54. package/examples/comfy-cloud/sdk.d.ts +445 -57
  55. package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
  56. package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
  57. package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
  58. package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
  59. package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
  60. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
  61. package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
  62. package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
  63. package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
  64. package/examples/images/README.md +18 -0
  65. package/examples/images/bear_1024x1024.jpg +0 -0
  66. package/examples/images/deer_768x1344.jpg +0 -0
  67. package/examples/images/dog_512x512.jpg +0 -0
  68. package/examples/images/lioness_768x768.jpg +0 -0
  69. package/examples/images/pug_200x300.jpg +0 -0
  70. package/examples/images/walrus_1344x768.jpg +0 -0
  71. package/guide-for-agents.md +7 -1
  72. package/package.json +15 -4
  73. package/src/cli/tui/components/PreviewPanel.tsx +9 -8
  74. package/src/cli/tui/components/StatusBar.tsx +11 -0
  75. package/src/cli/tui/components/TuiApp.tsx +18 -0
  76. package/src/cli/tui/discoverWorkflows.ts +7 -41
  77. package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
  78. package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
  79. package/src/cli/tui/imagePicker/fsListing.ts +46 -0
  80. package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
  81. package/src/cli/tui/run-tui.tsx +2 -1
  82. package/src/cli/tui/state/LorasSt.ts +14 -36
  83. package/src/cli/tui/state/PreviewSt.ts +28 -2
  84. package/src/cli/tui/state/TuiSt.ts +6 -0
  85. package/src/exampleAssets.ts +56 -0
  86. package/src/graph/ComfyNode.ts +4 -1
  87. package/src/index.ts +7 -0
  88. package/src/manager/ComfyRegistry.ts +37 -9
  89. package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
  90. package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
  91. package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
  92. package/src/manager/generated/KnownModel_Base.ts +23 -7
  93. package/src/manager/generated/KnownModel_FileName.ts +421 -0
  94. package/src/manager/generated/KnownModel_Name.ts +421 -0
  95. package/src/manager/generated/KnownModel_SavePath.ts +34 -8
  96. package/src/manager/generated/KnownModel_Type.ts +18 -14
  97. package/src/manager/json/alter-list.json +221 -221
  98. package/src/manager/json/custom-node-list.json +61020 -21946
  99. package/src/manager/json/extension-node-map.json +81077 -31176
  100. package/src/manager/json/github-stats.json +29321 -12601
  101. package/src/manager/json/model-list.json +5935 -4997
  102. package/src/manager/loaders/parseReport.ts +55 -0
  103. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
  104. package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
  105. package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
  106. package/src/manager/loaders/step4_model-list-loader.ts +25 -36
  107. package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
  108. package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
  109. package/src/manager/script-update-manager.bun.ts +9 -1
  110. package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
  111. package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
  112. package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
  113. package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
  114. package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
  115. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
  116. package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
  117. package/src/sdk-generator/ComfySchema.ts +14 -1
  118. package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
  119. package/src/sdk-generator/inputWidgetKind.ts +17 -0
  120. package/src/vars/ComfyVars.ts +82 -2
  121. package/src/vars/DefinedWorkflow.ts +7 -2
  122. package/dist/DefinedWorkflow-O3ynII3Y.js.map +0 -1
  123. package/dist/run-tui-BFhba_oG.js.map +0 -1
  124. package/src/utils/tryExtracting.ts +0 -41
@@ -0,0 +1,62 @@
1
+ // z-image t2i on Comfy Cloud — Z-Image Turbo bf16, 8-step distilled text to image (cfg 1)
2
+ // source template: image_z_image_turbo.json (official workflow-templates)
3
+ // needs COMFY_CLOUD_API_KEY (https://cloud.comfy.org, paid tiers)
4
+ // run directly: bun examples/comfy-cloud/z-image-t2i.cflow.ts ["prompt"] [seed]
5
+ import { v } from 'comfy-ts'
6
+ import { cloudHost, requireCloudKey } from './cloudHost.ts'
7
+
8
+ const host = await cloudHost()
9
+
10
+ export const zImageT2i = host.defineWorkflow({
11
+ id: 'z-image-t2i',
12
+ vars: {
13
+ // ONE prompt var: `- ` lines are the NEGATIVE prompt, `//` lines are comments
14
+ prompt: v.prompt(
15
+ 'Latina female with thick wavy hair, harbor boats and pastel houses behind. Breezy seaside light, warm tones, cinematic close-up.',
16
+ ),
17
+ seed: v.seed(42),
18
+ steps: v.int(8, { min: 1, max: 40 }),
19
+ size: v.size({ width: 1024, height: 1024 }),
20
+ },
21
+ build: (b, vars) => {
22
+ const model = b.ModelSamplingAuraFlow({
23
+ model: b.UNETLoader({ unet_name: 'z_image_turbo_bf16.safetensors', weight_dtype: 'default' }),
24
+ shift: 3,
25
+ })
26
+ const clip = b.CLIPLoader({ clip_name: 'qwen_3_4b.safetensors', type: 'lumina2', device: 'default' })
27
+ const positive = b.CLIPTextEncode({ clip, text: vars.prompt.positive })
28
+ // turbo distill: no negative lines → zeroed-out conditioning (the template's own default)
29
+ const negative =
30
+ vars.prompt.negative === ''
31
+ ? b.ConditioningZeroOut({ conditioning: positive })
32
+ : b.CLIPTextEncode({ clip, text: vars.prompt.negative })
33
+ const samples = b.KSampler({
34
+ model,
35
+ positive,
36
+ negative,
37
+ latent_image: b.EmptySD3LatentImage({ width: vars.size.width, height: vars.size.height, batch_size: 1 }),
38
+ seed: vars.seed,
39
+ steps: vars.steps,
40
+ cfg: 1,
41
+ sampler_name: 'res_multistep',
42
+ scheduler: 'simple',
43
+ denoise: 1,
44
+ })
45
+ b.SaveImage({
46
+ images: b.VAEDecode({ samples, vae: b.VAELoader({ vae_name: 'ae.safetensors' }) }),
47
+ filename_prefix: 'comfy-ts-zoo/z-image-t2i',
48
+ })
49
+ },
50
+ })
51
+
52
+ export default zImageT2i
53
+
54
+ // standalone run (skipped when another driver — e.g. the TUI — imports this module)
55
+ if (import.meta.main) {
56
+ requireCloudKey()
57
+ if (process.argv[2]) zImageT2i.vars.prompt.set(process.argv[2])
58
+ if (process.argv[3]) zImageT2i.vars.seed.set(Number(process.argv[3]))
59
+ const execution = await zImageT2i.run({ log: true })
60
+ for (const img of execution.images) console.log(`🟢 ${img.absPath}`)
61
+ host.disconnect()
62
+ }
@@ -0,0 +1,18 @@
1
+ # Bundled example input images
2
+
3
+ Default inputs for the i2i/i2v examples — they ship in the npm tarball so
4
+ every example runs out of the box. The exact pixel size is in each filename.
5
+
6
+ Source: [picsum.photos](https://picsum.photos), which serves Unsplash-sourced
7
+ photos, free to use. Fetched and re-encoded (jpeg q80, metadata stripped) by
8
+ `scripts/fetch-example-images.ts` — the manifest in that script is the source
9
+ of truth; regeneration is deliberate (`bun run examples:images`).
10
+
11
+ | file | size | picsum id | author |
12
+ | --------------------- | --------- | ------------------------------------------ | ------------------------------------------------------------ |
13
+ | `dog_512x512.jpg` | 512×512 | [237](https://picsum.photos/id/237/info) | [André Spieker](https://unsplash.com/photos/8wTPqxlnKM4) |
14
+ | `lioness_768x768.jpg` | 768×768 | [1074](https://picsum.photos/id/1074/info) | [Samuel Scrimshaw](https://unsplash.com/photos/sseiVD2XsOk) |
15
+ | `bear_1024x1024.jpg` | 1024×1024 | [433](https://picsum.photos/id/433/info) | [Thomas Lefebvre](https://unsplash.com/photos/aRXPJnXQ9lU) |
16
+ | `walrus_1344x768.jpg` | 1344×768 | [1084](https://picsum.photos/id/1084/info) | [Jay Ruzesky](https://unsplash.com/photos/h13Y8vyIXNU) |
17
+ | `deer_768x1344.jpg` | 768×1344 | [1003](https://picsum.photos/id/1003/info) | [E+N Photographies](https://unsplash.com/photos/GYumuBnTqKc) |
18
+ | `pug_200x300.jpg` | 200×300 | [1025](https://picsum.photos/id/1025/info) | [Matthew Wiebe](https://unsplash.com/photos/U5rMrSI7Pn4) |
Binary file
Binary file
@@ -83,7 +83,7 @@ if (import.meta.main) {
83
83
  ```
84
84
 
85
85
  Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`,
86
- `v.size`, `v.loras`, `v.prompt`. Notes:
86
+ `v.size`, `v.loras`, `v.prompt`, `v.image`. Notes:
87
87
 
88
88
  - `v.loras(/regex/)` resolves against the host's real lora list;
89
89
  `activeLoras(vars.loras)` returns `{ lora_name, strength_model, strength_clip }[]`
@@ -91,6 +91,12 @@ Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`,
91
91
  - `v.prompt` is structured: `//` lines are comments (stripped), `- ` lines go
92
92
  to the negative prompt, `{ loraKeywordsFrom: lorasVar }` prefixes lora
93
93
  trigger keywords. The value is `{ positive, negative }`.
94
+ - `v.image` holds a local image path as a plain string; an empty value throws
95
+ at build time instead of running a silent placeholder. Capture the var in a
96
+ const and call `image.absPath()` in `build`. Default it to a bundled sample
97
+ with `exampleImagePath('bear_1024x1024.jpg')` (ships in the package). In
98
+ the TUI it opens an image picker (browse, favorite folders, recents,
99
+ preview).
94
100
  - `vars` may be a lambda `(v) => ({ ... })` so vars can reference each other.
95
101
  - `build` may be async, for uploads: the third param `wf` feeds `MediaImage`
96
102
  helpers (`new MediaImage({ path }).loadInWorkflow_viaLoadImageNode(wf)`).
package/package.json CHANGED
@@ -1,13 +1,23 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "1.0.0",
4
- "description": "Type-safe generative AI pipeline creation and execution using ComfyUI",
3
+ "version": "1.1.0",
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",
7
- "AI",
7
+ "generative-ai",
8
8
  "typescript",
9
+ "type-safe",
10
+ "sdk",
9
11
  "codegen",
10
- "stable-diffusion"
12
+ "image-generation",
13
+ "video-generation",
14
+ "audio-generation",
15
+ "3d",
16
+ "stable-diffusion",
17
+ "flux",
18
+ "workflow",
19
+ "cli",
20
+ "tui"
11
21
  ],
12
22
  "author": "Rémi Vion <vion.remi@gmail.com>",
13
23
  "license": "MIT",
@@ -67,6 +77,7 @@
67
77
  "gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
68
78
  "gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts && oxfmt examples/comfy-cloud/sdk.d.ts",
69
79
  "sdk:outline": "bun scripts/sdk-outline.ts",
80
+ "examples:images": "bun scripts/fetch-example-images.ts",
70
81
  "templates:fetch": "bun scripts/fetch-templates.ts",
71
82
  "templates:check": "bun scripts/check-templates.ts",
72
83
  "hooks:install": "git config core.hooksPath .githooks",
@@ -33,26 +33,27 @@ export const PreviewPanel = observer((p: { st: TuiSt }) => {
33
33
  )
34
34
  }
35
35
 
36
- const loraMode = s.mode === 'overlay-loras'
36
+ // an overlay owns the vars area (loras / image picker): its slot owns the panel too
37
+ const overlayMode = pv.overlayActive
37
38
  const running = s.exec.running
38
39
  const wantLatent = running && pv.duringRun !== 'last-output'
39
- const showLatent = !loraMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null)
40
- const label = loraMode
41
- ? `lora ${s.loras.previewName ?? 'lora'}`
40
+ const showLatent = !overlayMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null)
41
+ const label = overlayMode
42
+ ? (pv.overlay?.name ?? (s.mode === 'overlay-loras' ? 'lora' : 'image'))
42
43
  : showLatent
43
44
  ? pv.duringRun === 'latent-small'
44
45
  ? 'latent small'
45
46
  : 'latent'
46
47
  : 'output'
47
- const placeholder = loraMode
48
- ? (s.loras.previewNote ?? '(pick a lora)')
48
+ const placeholder = overlayMode
49
+ ? (pv.overlay?.note ?? (s.mode === 'overlay-loras' ? '(pick a lora)' : '(pick an image)'))
49
50
  : pv.latentsMissing
50
51
  ? '(no latents from the server — launch comfy with --preview-method auto)'
51
52
  : '(no image yet)'
52
53
  const content = pv.useNative
53
54
  ? null
54
- : loraMode
55
- ? s.loras.previewAnsi
55
+ : overlayMode
56
+ ? (pv.overlay?.ansi ?? null)
56
57
  : showLatent
57
58
  ? (pv.latentAnsi ?? pv.outputAnsi)
58
59
  : pv.outputAnsi
@@ -65,6 +65,7 @@ const KIND_KEYS: Record<string, Hint[]> = {
65
65
  choice: [['⏎/→', 'pick']],
66
66
  size: [['⏎/→', 'pick']],
67
67
  loras: [['⏎/→', 'select']],
68
+ image: [['⏎/→', 'browse']],
68
69
  }
69
70
 
70
71
  /** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
@@ -118,6 +119,16 @@ const MODE_KEYS: Partial<Record<string, Hint[]>> = {
118
119
  ['⌃N', 'none'],
119
120
  ['esc', 'done'],
120
121
  ],
122
+ 'overlay-image': [
123
+ ['⏎', 'pick / enter dir'],
124
+ ['←', 'parent'],
125
+ ['→', 'enter dir'],
126
+ ['tab', 'pane'],
127
+ ['↑↓', 'move'],
128
+ ['type', 'filter'],
129
+ ['⌃F', 'fav folder'],
130
+ ['esc', 'cancel'],
131
+ ],
121
132
  'overlay-drafts': [['⏎', 'load / new'], ...DRAFT_OP_HINTS, ['↑↓', 'move'], ['esc', 'cancel']],
122
133
  tree: [['⏎', 'load'], ['↑↓', 'move'], ['←', 'fold'], ['→', 'unfold / vars'], ...DRAFT_OP_HINTS, ['t/esc', 'back']],
123
134
  host: [
@@ -9,6 +9,7 @@ import { ChoiceOverlay, SizeOverlay } from 'src/cli/tui/components/PickerOverlay
9
9
  import { PreviewPanel } from 'src/cli/tui/components/PreviewPanel.tsx'
10
10
  import { PromptOverlay } from 'src/cli/tui/components/PromptOverlay.tsx'
11
11
  import { KeyBar, ProgressLine } from 'src/cli/tui/components/StatusBar.tsx'
12
+ import { ImagePickerOverlay } from 'src/cli/tui/imagePicker/ImagePickerOverlay.tsx'
12
13
  import { LogsPanel } from 'src/cli/tui/components/LogsPanel.tsx'
13
14
  import { TextOverlay } from 'src/cli/tui/components/TextOverlay.tsx'
14
15
  import { TreePanel } from 'src/cli/tui/components/TreePanel.tsx'
@@ -97,6 +98,21 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
97
98
  if (input && !key.ctrl && !key.meta) return lo.filterInput(input)
98
99
  return
99
100
  }
101
+ if (s.mode === 'overlay-image') {
102
+ const ip = s.imagePicker
103
+ if (key.escape) return ip.cancel()
104
+ if (key.tab || input === '\t') return ip.cyclePane()
105
+ if (key.ctrl && input === 'f') return ip.toggleFavorite()
106
+ if (key.return) return ip.commit()
107
+ if (key.upArrow) return ip.move(-1)
108
+ if (key.downArrow) return ip.move(1)
109
+ if (key.leftArrow) return ip.goParent()
110
+ if (key.rightArrow) return ip.enter()
111
+ if ((key.meta && (key.backspace || key.delete)) || (key.ctrl && input === 'w')) return ip.filterDeleteWord()
112
+ if (key.backspace || key.delete) return ip.filterBackspace()
113
+ if (input && !key.ctrl && !key.meta) return ip.filterInput(input)
114
+ return
115
+ }
100
116
  if (s.mode === 'tree') {
101
117
  const tr = s.tree
102
118
  if (key.escape || input === 't') return tr.blur()
@@ -218,6 +234,8 @@ export const TuiApp = observer((p: { st: TuiSt }) => {
218
234
  <SizeOverlay st={s} />
219
235
  ) : s.mode === 'overlay-loras' ? (
220
236
  <LorasOverlay st={s} />
237
+ ) : s.mode === 'overlay-image' ? (
238
+ <ImagePickerOverlay st={s} />
221
239
  ) : s.mode === 'overlay-drafts' ? (
222
240
  <DraftsOverlay st={s} />
223
241
  ) : (
@@ -1,14 +1,14 @@
1
- import { existsSync, readdirSync, readFileSync } from 'node:fs'
2
- import { fileURLToPath } from 'node:url'
3
- import { dirname, join } from 'pathe'
1
+ import { readdirSync } from 'node:fs'
2
+ import { join } from 'pathe'
4
3
 
5
4
  /**
6
5
  * recursive scan for the workflow-module naming convention. Entries BELOW a
7
6
  * node_modules segment are skipped: packaged examples arrive via
8
- * bundledExamplesDir (symlinked layouts like pnpm would otherwise list them
9
- * twice, un-deduped, as the user's own files), and third-party packages
10
- * shipping *.cflow.ts are not this project's workflows. A scan root that is
11
- * ITSELF inside node_modules still works (the filter is relative to the root).
7
+ * bundledExamplesDir (src/exampleAssets.ts — symlinked layouts like pnpm would
8
+ * otherwise list them twice, un-deduped, as the user's own files), and
9
+ * third-party packages shipping *.cflow.ts are not this project's workflows. A
10
+ * scan root that is ITSELF inside node_modules still works (the filter is
11
+ * relative to the root).
12
12
  */
13
13
  export function scanCflowFiles(dir: string): string[] {
14
14
  const hits = readdirSync(dir, { recursive: true })
@@ -19,40 +19,6 @@ export function scanCflowFiles(dir: string): string[] {
19
19
  return hits.sort()
20
20
  }
21
21
 
22
- /**
23
- * the examples/ folder shipped in the npm tarball, resolved from THIS module's
24
- * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
25
- * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/cli.js and
26
- * from this repo's src/cli/tui/. Returns null when the examples are absent
27
- * (a consumer may prune the folder) or when the nearest named package is not
28
- * comfy-ts (the lib was inlined into someone else's bundle — its examples are
29
- * not on disk); no package.json all the way up is a broken install and throws.
30
- */
31
- export function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {
32
- let dir = dirname(fileURLToPath(moduleUrl))
33
- let prev = ''
34
- while (dir !== prev) {
35
- const pkgPath = join(dir, 'package.json')
36
- if (existsSync(pkgPath)) {
37
- let pkg: { name?: string } = {}
38
- try {
39
- pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
40
- } catch {
41
- // a malformed package.json on the walk (someone's broken fixture
42
- // dir) must not take the whole TUI down; treat as unnamed
43
- }
44
- if (pkg.name === 'comfy-ts') {
45
- const examples = join(dir, 'examples')
46
- return existsSync(examples) ? examples : null
47
- }
48
- if (pkg.name != null) return null
49
- }
50
- prev = dir
51
- dir = dirname(dir)
52
- }
53
- throw new Error(`[comfy-ts tui] no package.json found walking up from ${fileURLToPath(moduleUrl)}`)
54
- }
55
-
56
22
  export type WorkflowDiscovery = {
57
23
  /** every module the tree lists, user files first, bundled examples last */
58
24
  files: string[]
@@ -0,0 +1,72 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
4
+ import { PICKER_PANES } from 'src/cli/tui/imagePicker/ImagePickerSt.ts'
5
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
+
7
+ /** modal image browser: three panes (tab), dirs enter, ⏎ picks, ★ = favorite folder */
8
+ export const ImagePickerOverlay = observer((p: { st: TuiSt }) => {
9
+ const s = p.st
10
+ const ip = s.imagePicker
11
+ const iv = ip.selectedVar
12
+ if (iv == null) return null
13
+ const rows = ip.rows
14
+ return (
15
+ <OverlayList
16
+ title={
17
+ <>
18
+ {s.selected?.[1].label ?? s.selected?.[0]} <Text color="gray">{iv.display()}</Text>
19
+ </>
20
+ }
21
+ extraHeader={
22
+ <Box flexDirection="column">
23
+ <Text>
24
+ {PICKER_PANES.map((pane, ix) => (
25
+ <Text key={pane}>
26
+ {ix > 0 ? <Text color="gray"> · </Text> : null}
27
+ <Text
28
+ color={pane === ip.pane ? 'cyan' : 'gray'}
29
+ bold={pane === ip.pane}
30
+ underline={pane === ip.pane}
31
+ >
32
+ {pane}
33
+ </Text>
34
+ </Text>
35
+ ))}
36
+ {ip.pane === 'browse' ? <Text color="gray"> {ip.folderDisplay}</Text> : null}
37
+ </Text>
38
+ <Text color="yellow">filter: {ip.filter}▌</Text>
39
+ </Box>
40
+ }
41
+ selectedIx={ip.ix}
42
+ lines={s.overlayLines}
43
+ rows={rows.map((row, ix) => {
44
+ const sel = ix === ip.ix
45
+ const fav = row.kind === 'dir' && ip.isFavorite(row.path)
46
+ const missing = row.kind === 'image' && row.missing
47
+ return {
48
+ key: `${row.kind}:${row.path}`,
49
+ node: (
50
+ <Text
51
+ key={`${row.kind}:${row.path}`}
52
+ inverse={sel}
53
+ color={row.kind === 'dir' ? 'blue' : missing ? 'gray' : undefined}
54
+ dimColor={missing}
55
+ >
56
+ {sel ? '▸ ' : ' '}
57
+ {fav ? '★ ' : ' '}
58
+ {row.name}
59
+ {row.kind === 'dir' ? '/' : ''}
60
+ {missing ? ' (missing)' : ''}
61
+ </Text>
62
+ ),
63
+ }
64
+ })}
65
+ footer={
66
+ rows.length === 0 ? (
67
+ <Text color="red">{ip.listingError ?? (ip.filter !== '' ? 'no match' : 'no images here')}</Text>
68
+ ) : undefined
69
+ }
70
+ />
71
+ )
72
+ })