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.
- package/README.md +42 -6
- package/dist/{DefinedWorkflow-O3ynII3Y.js → DefinedWorkflow-BYyu5dK9.js} +76 -5
- package/dist/DefinedWorkflow-BYyu5dK9.js.map +1 -0
- package/dist/cli.js +421 -308
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +394 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7426 -353
- package/dist/index.d.ts +7408 -335
- package/dist/index.js +393 -162
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-BFhba_oG.js → run-tui-DZ22HDHI.js} +529 -78
- package/dist/run-tui-DZ22HDHI.js.map +1 -0
- package/examples/02-img2img-upload.cflow.ts +6 -17
- package/examples/05-comfy-cloud.cflow.ts +19 -35
- package/examples/README.md +30 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/cloudHost.ts +41 -0
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
- package/examples/comfy-cloud/sdk.d.ts +445 -57
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
- package/examples/images/README.md +18 -0
- package/examples/images/bear_1024x1024.jpg +0 -0
- package/examples/images/deer_768x1344.jpg +0 -0
- package/examples/images/dog_512x512.jpg +0 -0
- package/examples/images/lioness_768x768.jpg +0 -0
- package/examples/images/pug_200x300.jpg +0 -0
- package/examples/images/walrus_1344x768.jpg +0 -0
- package/guide-for-agents.md +7 -1
- package/package.json +15 -4
- package/src/cli/tui/components/PreviewPanel.tsx +9 -8
- package/src/cli/tui/components/StatusBar.tsx +11 -0
- package/src/cli/tui/components/TuiApp.tsx +18 -0
- package/src/cli/tui/discoverWorkflows.ts +7 -41
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
- package/src/cli/tui/imagePicker/fsListing.ts +46 -0
- package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
- package/src/cli/tui/run-tui.tsx +2 -1
- package/src/cli/tui/state/LorasSt.ts +14 -36
- package/src/cli/tui/state/PreviewSt.ts +28 -2
- package/src/cli/tui/state/TuiSt.ts +6 -0
- package/src/exampleAssets.ts +56 -0
- package/src/graph/ComfyNode.ts +4 -1
- package/src/index.ts +7 -0
- package/src/manager/ComfyRegistry.ts +37 -9
- package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
- package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
- package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
- package/src/manager/generated/KnownModel_Base.ts +23 -7
- package/src/manager/generated/KnownModel_FileName.ts +421 -0
- package/src/manager/generated/KnownModel_Name.ts +421 -0
- package/src/manager/generated/KnownModel_SavePath.ts +34 -8
- package/src/manager/generated/KnownModel_Type.ts +18 -14
- package/src/manager/json/alter-list.json +221 -221
- package/src/manager/json/custom-node-list.json +61020 -21946
- package/src/manager/json/extension-node-map.json +81077 -31176
- package/src/manager/json/github-stats.json +29321 -12601
- package/src/manager/json/model-list.json +5935 -4997
- package/src/manager/loaders/parseReport.ts +55 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
- package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
- package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
- package/src/manager/loaders/step4_model-list-loader.ts +25 -36
- package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
- package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
- package/src/manager/script-update-manager.bun.ts +9 -1
- package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
- package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
- package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
- package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
- package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
- package/src/sdk-generator/ComfySchema.ts +14 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
- package/src/sdk-generator/inputWidgetKind.ts +17 -0
- package/src/vars/ComfyVars.ts +82 -2
- package/src/vars/DefinedWorkflow.ts +7 -2
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +0 -1
- package/dist/run-tui-BFhba_oG.js.map +0 -1
- 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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/guide-for-agents.md
CHANGED
|
@@ -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.
|
|
4
|
-
"description": "
|
|
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
|
-
"
|
|
7
|
+
"generative-ai",
|
|
8
8
|
"typescript",
|
|
9
|
+
"type-safe",
|
|
10
|
+
"sdk",
|
|
9
11
|
"codegen",
|
|
10
|
-
"
|
|
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
|
-
|
|
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 = !
|
|
40
|
-
const label =
|
|
41
|
-
?
|
|
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 =
|
|
48
|
-
? (s.loras
|
|
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
|
-
:
|
|
55
|
-
?
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
9
|
-
* twice, un-deduped, as the user's own files), and
|
|
10
|
-
* shipping *.cflow.ts are not this project's workflows. A
|
|
11
|
-
* ITSELF inside node_modules still works (the filter is
|
|
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
|
+
})
|