comfy-ts 2.20.2 → 2.22.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 (89) hide show
  1. package/README.md +17 -1
  2. package/dist/{ServeApp-B469W26E.js → ServeApp-DuxYdaZZ.js} +142 -7
  3. package/dist/ServeApp-DuxYdaZZ.js.map +1 -0
  4. package/dist/cli.js +5 -5
  5. package/dist/{exampleAssets-yBLaKXLq.js → exampleAssets-1NHndnNB.js} +59 -17
  6. package/dist/exampleAssets-1NHndnNB.js.map +1 -0
  7. package/dist/{findDefinedWorkflow-B90-xFxX.js → findDefinedWorkflow-CRsBTTJK.js} +2 -2
  8. package/dist/{findDefinedWorkflow-B90-xFxX.js.map → findDefinedWorkflow-CRsBTTJK.js.map} +1 -1
  9. package/dist/index.cjs +118 -19
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +90 -9
  12. package/dist/index.d.ts +90 -9
  13. package/dist/index.js +117 -20
  14. package/dist/index.js.map +1 -1
  15. package/dist/{run-run-C-dDD9Dc.js → run-run-Y5ZI48vV.js} +5 -5
  16. package/dist/{run-run-C-dDD9Dc.js.map → run-run-Y5ZI48vV.js.map} +1 -1
  17. package/dist/{run-serve-CsEYPGm9.js → run-serve-CICU_wTL.js} +4 -4
  18. package/dist/{run-serve-CsEYPGm9.js.map → run-serve-CICU_wTL.js.map} +1 -1
  19. package/dist/{run-tui-bsmja4hi.js → run-tui-CViJXsHL.js} +4 -4
  20. package/dist/{run-tui-bsmja4hi.js.map → run-tui-CViJXsHL.js.map} +1 -1
  21. package/dist/{schemaDrift-DaWsE-mt.js → schemaDrift-CzjaIwZX.js} +53 -20
  22. package/dist/schemaDrift-CzjaIwZX.js.map +1 -0
  23. package/dist/serve-web.js +204 -47
  24. package/dist/web.d.ts +90 -9
  25. package/dist/web.js +117 -20
  26. package/dist/web.js.map +1 -1
  27. package/examples/README.md +2 -0
  28. package/examples/depth-explorer/models.ts +722 -0
  29. package/examples/depth-explorer/serve.ts +140 -0
  30. package/examples/depth-explorer/thumbs/bae.webp +0 -0
  31. package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
  32. package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
  33. package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
  34. package/examples/depth-explorer/thumbs/dsine.webp +0 -0
  35. package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
  36. package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
  37. package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
  38. package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
  39. package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
  40. package/examples/depth-explorer/thumbs/leres.webp +0 -0
  41. package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
  42. package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
  43. package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
  44. package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
  45. package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
  46. package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
  47. package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
  48. package/examples/depth-explorer/thumbs/midas.webp +0 -0
  49. package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
  50. package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
  51. package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
  52. package/examples/depth-explorer/thumbs/zoe.webp +0 -0
  53. package/examples/depth-explorer/web/App.tsx +457 -0
  54. package/examples/depth-explorer/web/gl.ts +202 -0
  55. package/examples/depth-explorer/web/index.html +14 -0
  56. package/examples/depth-explorer/web/main.tsx +19 -0
  57. package/examples/depth-explorer/web/pixels.ts +86 -0
  58. package/examples/depth-explorer/web/state.ts +329 -0
  59. package/examples/depth-explorer/web/styles.css +366 -0
  60. package/examples/depth-explorer/web/tsconfig.json +16 -0
  61. package/examples/rvion/17-relight.cflow.ts +110 -0
  62. package/package.json +3 -2
  63. package/src/cli/serve/ServeApp.ts +79 -4
  64. package/src/cli/serve/describeVar.ts +12 -1
  65. package/src/cli/serve/resultHistory.ts +6 -1
  66. package/src/cli/serve/thumbs.ts +66 -0
  67. package/src/cli/serve/web/api.ts +5 -1
  68. package/src/cli/serve/web/components/Gallery.tsx +2 -0
  69. package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
  70. package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
  71. package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
  72. package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
  73. package/src/cli/serve/web/state/choiceButtons.ts +26 -2
  74. package/src/cli/serve/web/styles.ts +39 -0
  75. package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
  76. package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
  77. package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
  78. package/src/cli/serve/web/widgets/relightGl.ts +305 -0
  79. package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
  80. package/src/coreExports.ts +9 -0
  81. package/src/host/ComfyHost.ts +21 -0
  82. package/src/host/leastBusy.ts +37 -0
  83. package/src/state.ts +6 -0
  84. package/src/vars/ComfyVars.ts +32 -2
  85. package/src/vars/DefinedWorkflow.ts +42 -21
  86. package/src/vars/outputWidgets.ts +47 -0
  87. package/dist/ServeApp-B469W26E.js.map +0 -1
  88. package/dist/exampleAssets-yBLaKXLq.js.map +0 -1
  89. package/dist/schemaDrift-DaWsE-mt.js.map +0 -1
@@ -0,0 +1,366 @@
1
+ :root {
2
+ --bg: #111316;
3
+ --panel: #181b20;
4
+ --card: #1d2127;
5
+ --line: #2a2f37;
6
+ --text: #e6e8eb;
7
+ --dim: #8a929c;
8
+ --accent: #6aa8ff;
9
+ --err: #ff7a7a;
10
+ /* the panel's tokens, which the shared widget rules read */
11
+ --panel-2: var(--card);
12
+ --border: var(--line);
13
+ --hairline: var(--line);
14
+ --sel-bg: #2c3542;
15
+ --sel-border: var(--accent);
16
+ --sel-text: #c3d3fb;
17
+ --amber: #e0af68;
18
+ color-scheme: dark;
19
+ }
20
+ .relightWrap {
21
+ padding: 10px;
22
+ display: flex;
23
+ flex-direction: column;
24
+ gap: 8px;
25
+ }
26
+ * {
27
+ box-sizing: border-box;
28
+ }
29
+ body {
30
+ margin: 0;
31
+ background: var(--bg);
32
+ color: var(--text);
33
+ font:
34
+ 13px/1.4 ui-sans-serif,
35
+ system-ui,
36
+ -apple-system,
37
+ sans-serif;
38
+ }
39
+ button,
40
+ select,
41
+ a.ghost {
42
+ font: inherit;
43
+ color: var(--text);
44
+ background: var(--card);
45
+ border: 1px solid var(--line);
46
+ border-radius: 6px;
47
+ padding: 5px 10px;
48
+ cursor: pointer;
49
+ text-decoration: none;
50
+ }
51
+ button:disabled {
52
+ opacity: 0.45;
53
+ cursor: default;
54
+ }
55
+ button.primary {
56
+ background: var(--accent);
57
+ border-color: var(--accent);
58
+ color: #0b1220;
59
+ font-weight: 600;
60
+ width: 100%;
61
+ padding: 8px;
62
+ margin-top: 14px;
63
+ }
64
+ .ghost {
65
+ background: transparent;
66
+ }
67
+ .dim {
68
+ color: var(--dim);
69
+ }
70
+ .small {
71
+ font-size: 12px;
72
+ margin-top: 6px;
73
+ }
74
+ .err {
75
+ color: var(--err);
76
+ display: flex;
77
+ flex-direction: column;
78
+ gap: 6px;
79
+ padding: 10px;
80
+ font-size: 12px;
81
+ overflow: auto;
82
+ }
83
+ .app {
84
+ min-height: 100vh;
85
+ display: flex;
86
+ flex-direction: column;
87
+ }
88
+ header {
89
+ display: flex;
90
+ align-items: baseline;
91
+ gap: 14px;
92
+ padding: 12px 20px;
93
+ border-bottom: 1px solid var(--line);
94
+ }
95
+ h1 {
96
+ font-size: 16px;
97
+ margin: 0;
98
+ }
99
+ h2 {
100
+ font-size: 12px;
101
+ text-transform: uppercase;
102
+ letter-spacing: 0.08em;
103
+ color: var(--dim);
104
+ margin: 4px 0 10px;
105
+ }
106
+ .body {
107
+ display: flex;
108
+ flex: 1;
109
+ min-height: 0;
110
+ }
111
+ aside {
112
+ width: 280px;
113
+ flex-shrink: 0;
114
+ padding: 16px;
115
+ border-right: 1px solid var(--line);
116
+ background: var(--panel);
117
+ }
118
+ aside label {
119
+ display: block;
120
+ color: var(--dim);
121
+ margin: 14px 0 6px;
122
+ }
123
+ label.check {
124
+ display: flex;
125
+ gap: 8px;
126
+ align-items: center;
127
+ color: var(--text);
128
+ margin: 10px 0 0;
129
+ cursor: pointer;
130
+ }
131
+ .drop {
132
+ border: 1px dashed var(--line);
133
+ border-radius: 8px;
134
+ min-height: 140px;
135
+ display: grid;
136
+ place-items: center;
137
+ cursor: pointer;
138
+ overflow: hidden;
139
+ }
140
+ .drop.over {
141
+ border-color: var(--accent);
142
+ }
143
+ .drop img {
144
+ display: block;
145
+ width: 100%;
146
+ }
147
+ .samples {
148
+ display: flex;
149
+ gap: 6px;
150
+ flex-wrap: wrap;
151
+ margin-top: 10px;
152
+ }
153
+ .samples img {
154
+ width: 40px;
155
+ height: 40px;
156
+ object-fit: cover;
157
+ border-radius: 4px;
158
+ cursor: pointer;
159
+ opacity: 0.8;
160
+ }
161
+ .samples img:hover {
162
+ opacity: 1;
163
+ }
164
+ .seg {
165
+ display: flex;
166
+ }
167
+ .seg button {
168
+ flex: 1;
169
+ border-radius: 0;
170
+ }
171
+ .seg button:first-child {
172
+ border-radius: 6px 0 0 6px;
173
+ }
174
+ .seg button:last-child {
175
+ border-radius: 0 6px 6px 0;
176
+ }
177
+ .seg button.on {
178
+ background: #2c3542;
179
+ border-color: var(--accent);
180
+ }
181
+ main {
182
+ flex: 1;
183
+ padding: 16px 20px 40px;
184
+ overflow: auto;
185
+ }
186
+ section + section {
187
+ margin-top: 24px;
188
+ }
189
+ .grid {
190
+ display: grid;
191
+ grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
192
+ gap: 14px;
193
+ }
194
+ .card {
195
+ background: var(--card);
196
+ border: 1px solid var(--line);
197
+ border-radius: 8px;
198
+ overflow: hidden;
199
+ }
200
+ .card.off {
201
+ opacity: 0.6;
202
+ }
203
+ .cardHead {
204
+ display: flex;
205
+ justify-content: space-between;
206
+ gap: 8px;
207
+ padding: 8px 10px;
208
+ }
209
+ .name {
210
+ font-weight: 600;
211
+ }
212
+ .fam {
213
+ font-weight: 400;
214
+ color: var(--dim);
215
+ }
216
+ .meta {
217
+ color: var(--dim);
218
+ white-space: nowrap;
219
+ }
220
+ .frame {
221
+ background: #0c0d0f;
222
+ display: grid;
223
+ place-items: center;
224
+ position: relative;
225
+ overflow: hidden;
226
+ }
227
+ .card.done .frame {
228
+ cursor: zoom-in;
229
+ }
230
+ .frame > img,
231
+ .frame > canvas {
232
+ width: 100%;
233
+ height: 100%;
234
+ object-fit: contain;
235
+ display: block;
236
+ }
237
+ .frame .dim {
238
+ display: flex;
239
+ flex-direction: column;
240
+ align-items: center;
241
+ gap: 4px;
242
+ }
243
+ .blurb {
244
+ padding: 8px 10px;
245
+ color: var(--dim);
246
+ font-size: 12px;
247
+ }
248
+ .missing {
249
+ display: flex;
250
+ flex-direction: column;
251
+ gap: 4px;
252
+ padding: 10px;
253
+ font-size: 11px;
254
+ word-break: break-all;
255
+ }
256
+ .missing a {
257
+ color: var(--accent);
258
+ }
259
+ .spin {
260
+ display: inline-block;
261
+ width: 12px;
262
+ height: 12px;
263
+ border: 2px solid var(--line);
264
+ border-top-color: var(--accent);
265
+ border-radius: 50%;
266
+ animation: spin 0.8s linear infinite;
267
+ vertical-align: -2px;
268
+ }
269
+ @keyframes spin {
270
+ to {
271
+ transform: rotate(360deg);
272
+ }
273
+ }
274
+ .focus {
275
+ position: fixed;
276
+ inset: 0;
277
+ background: rgba(0, 0, 0, 0.75);
278
+ display: grid;
279
+ place-items: center;
280
+ padding: 24px;
281
+ z-index: 10;
282
+ }
283
+ .focusBox {
284
+ background: var(--panel);
285
+ border: 1px solid var(--line);
286
+ border-radius: 10px;
287
+ width: min(1200px, 100%);
288
+ max-height: 100%;
289
+ display: flex;
290
+ flex-direction: column;
291
+ overflow: hidden;
292
+ }
293
+ .focusBar {
294
+ display: flex;
295
+ align-items: center;
296
+ gap: 10px;
297
+ padding: 10px 14px;
298
+ border-bottom: 1px solid var(--line);
299
+ }
300
+ .focusBar b {
301
+ margin-right: auto;
302
+ }
303
+ .wipe {
304
+ position: relative;
305
+ flex-shrink: 0;
306
+ margin: 0 auto;
307
+ cursor: ew-resize;
308
+ user-select: none;
309
+ overflow: hidden;
310
+ }
311
+ .wipe .layer {
312
+ position: absolute;
313
+ inset: 0;
314
+ width: 100%;
315
+ height: 100%;
316
+ object-fit: contain;
317
+ display: block;
318
+ }
319
+ .handle {
320
+ position: absolute;
321
+ top: 0;
322
+ bottom: 0;
323
+ width: 2px;
324
+ background: #fff;
325
+ box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
326
+ pointer-events: none;
327
+ }
328
+ .tag {
329
+ position: absolute;
330
+ top: 8px;
331
+ background: rgba(0, 0, 0, 0.6);
332
+ padding: 2px 8px;
333
+ border-radius: 4px;
334
+ font-size: 12px;
335
+ }
336
+ .tag.l {
337
+ left: 8px;
338
+ }
339
+ .tag.r {
340
+ right: 8px;
341
+ }
342
+ .glWrap {
343
+ display: flex;
344
+ flex-direction: column;
345
+ }
346
+ canvas.gl {
347
+ width: 100%;
348
+ height: calc(100vh - 200px);
349
+ min-height: 320px;
350
+ display: block;
351
+ cursor: grab;
352
+ touch-action: none;
353
+ }
354
+ .glControls {
355
+ display: flex;
356
+ gap: 18px;
357
+ align-items: center;
358
+ padding: 10px 14px;
359
+ border-top: 1px solid var(--line);
360
+ }
361
+ .glControls label {
362
+ display: flex;
363
+ gap: 8px;
364
+ align-items: center;
365
+ margin: 0;
366
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ // the depth explorer page: dom-typed like examples/web, so it keeps its own config. It renders
3
+ // the panel's relight widget, so it checks src/ too, like src/cli/serve/web does
4
+ "extends": "../../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
+ "paths": {
8
+ "src/*": ["../../../src/*"],
9
+ "comfy-ts": ["../../../src/index.ts"]
10
+ },
11
+ "tsBuildInfoFile": "../../../node_modules/.cache/tsbuildinfo-depth-explorer-web.json"
12
+ },
13
+ // MUST override the root's exclude, which lists this directory
14
+ "exclude": ["../../web"],
15
+ "include": [".", "../../../src"]
16
+ }
@@ -0,0 +1,110 @@
1
+ // relight a photo: one depth model, one normal model and the Marigold IID material maps, drawn
2
+ // by the serve panel's relight widget (a point light you move over the image in 3D: drag for
3
+ // left/right and up/down, wheel for nearer/farther, plus shadows and drifting light motes).
4
+ // The models are the depth explorer's catalog (examples/depth-explorer/models.ts): one choice per
5
+ // map lists the ones this host can run, each option with its picture, date, weights and quality
6
+ // (a choice of one still says what it is). Every material map can be « none ». The image presets
7
+ // are the example animals (a url works too, see the commented ones). Outside the panel (CLI,
8
+ // TUI) each map is a plain output image.
9
+ //
10
+ // run directly: bun examples/rvion/17-relight.cflow.ts [path/to/image.png]
11
+ import { asAbsolutePath, type BaseNodeInputs, ComfyTS, exampleImagePath, MediaImage, v, widget } from 'comfy-ts'
12
+ import { availability, MODELS, optionLook, type ModelEntry } from '../depth-explorer/models.ts'
13
+
14
+ const comfy = ComfyTS.create()
15
+ const host = comfy.host({ id: 'windows-1' })
16
+ await host.loadSchemaFromCache()
17
+
18
+ /** the catalog entries for one map this host can run (by its cached schema) */
19
+ function runnable(which: (m: ModelEntry) => boolean): string[] {
20
+ return MODELS.filter((m) => which(m) && availability(host.schema.data.spec, m).ok).map((m) => m.id)
21
+ }
22
+ const looks = (ids: string[]) => ({ options: Object.fromEntries(ids.map((id) => [id, optionLook(entry(id))])) })
23
+ function entry(id: string): ModelEntry {
24
+ const m = MODELS.find((x) => x.id === id)
25
+ if (m == null) throw new Error(`no model '${id}' in the depth explorer catalog`)
26
+ return m
27
+ }
28
+ const pick = (ids: string[], preferred: string): string => (ids.includes(preferred) ? preferred : (ids[0] ?? preferred))
29
+
30
+ type MapName = NonNullable<ModelEntry['map']>
31
+ const ofMap = (map: MapName): string[] => runnable((m) => m.map === map)
32
+ const ids = {
33
+ depth: runnable((m) => m.kind === 'depth'),
34
+ normal: runnable((m) => m.kind === 'normal'),
35
+ albedo: ofMap('albedo'),
36
+ roughness: ofMap('roughness'),
37
+ metalness: ofMap('metalness'),
38
+ specular: ofMap('specular'),
39
+ shading: ofMap('shading'),
40
+ }
41
+
42
+ /** a material map: its models, the preferred one picked, or none */
43
+ const material = (map: MapName, preferred: string, label: string) =>
44
+ v.choice(ids[map], pick(ids[map], preferred), { label, select: 'zero-or-one' }).ui(looks(ids[map]))
45
+
46
+ const image = v.image(exampleImagePath('lioness_768x768.jpg'), {
47
+ presets: {
48
+ lioness: exampleImagePath('lioness_768x768.jpg'),
49
+ bear: exampleImagePath('bear_1024x1024.jpg'),
50
+ walrus: exampleImagePath('walrus_1344x768.jpg'),
51
+ deer: exampleImagePath('deer_768x1344.jpg'),
52
+ // a preset can be a url, fetched once when a run uses it:
53
+ // 'genomea cover': 'https://www.bifocalfiction.com/images/genomea-cover-cn1.png',
54
+ // 'dead city 1': 'https://www.bifocalfiction.com/generated/la-ville-morte-chapitre-3/horizontal/strip-01.webp',
55
+ // 'dead city 2': 'https://www.bifocalfiction.com/generated/la-ville-morte-chapitre-3/horizontal/strip-02.webp',
56
+ // 'dead city 3': 'https://www.bifocalfiction.com/generated/la-ville-morte-chapitre-3/horizontal/strip-03.webp',
57
+ },
58
+ })
59
+
60
+ export const relight = host.defineWorkflow({
61
+ id: 'relight',
62
+ vars: {
63
+ image,
64
+ depth: v.choice(ids.depth, pick(ids.depth, 'da3-mono-large')).ui(looks(ids.depth)),
65
+ normal: v.choice(ids.normal, pick(ids.normal, 'moge2-normal'), 'normals').ui(looks(ids.normal)),
66
+ albedo: material('albedo', 'iid-albedo', 'albedo'),
67
+ roughness: material('roughness', 'iid-roughness', 'roughness'),
68
+ metalness: material('metalness', 'iid-metalness', 'metalness'),
69
+ /** the non diffuse light: what shines */
70
+ specular: material('specular', 'iid-specular', 'specular'),
71
+ /** the diffuse light and the cast shadows: an output to look at, the widget lights without it */
72
+ shading: material('shading', 'iid-shading', 'shadows'),
73
+ detail: v.int(768, { min: 384, max: 1536 }),
74
+ },
75
+ widgets: [
76
+ widget.relight({
77
+ image: 'source',
78
+ depth: 'depth',
79
+ normal: 'normal',
80
+ albedo: 'albedo',
81
+ roughness: 'roughness',
82
+ metalness: 'metalness',
83
+ specular: 'specular',
84
+ }),
85
+ ],
86
+ build: async (b, vars, wf) => {
87
+ const loaded = await new MediaImage({ path: asAbsolutePath(image.absPath()) }).loadInWorkflow_viaLoadImageNode(wf)
88
+ const saveNode = wf.builderBase.SaveImageWebsocket
89
+ if (saveNode == null) throw new Error('this host has no SaveImageWebsocket node')
90
+ const save = (images: BaseNodeInputs[string], tag: string): void => void saveNode({ images }, { tag })
91
+ const p = { detail: vars.detail, wf }
92
+ save(loaded, 'source')
93
+ save(entry(vars.depth).build(b, loaded, p), 'depth')
94
+ save(entry(vars.normal).build(b, loaded, p), 'normal')
95
+ for (const map of ['albedo', 'roughness', 'metalness', 'specular', 'shading'] as const) {
96
+ const id = vars[map]
97
+ if (id != null) save(entry(id).build(b, loaded, p), map)
98
+ }
99
+ },
100
+ })
101
+
102
+ export default relight
103
+
104
+ // standalone run (skipped when another driver, e.g. the TUI, imports this module)
105
+ if (import.meta.main) {
106
+ if (process.argv[2]) relight.vars.image.set(process.argv[2])
107
+ const execution = await relight.run({ log: true, save: { prefix: 'comfy-ts-example/relight' } })
108
+ for (const out of execution.images) console.log(`🟢 ${out.tags.join(',')} ${out.absPath}`)
109
+ host.disconnect()
110
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.20.2",
3
+ "version": "2.22.0",
4
4
  "description": "An efficient way to create, run, maintain and operate your ComfyUI workflows, for humans and agents. A TypeScript SDK typed from your own install, with a CLI, a terminal UI, a web panel and a guide for coding agents.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -73,7 +73,7 @@
73
73
  "test:raw": "bun test",
74
74
  "test:watch": "bun test --watch",
75
75
  "typecheck": "tsc -p tsconfig.lib.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
76
- "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
76
+ "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json && tsc -p examples/depth-explorer/web/tsconfig.json",
77
77
  "lint": "oxlint src examples scripts tests",
78
78
  "format": "oxfmt src examples scripts tests",
79
79
  "format:check": "oxfmt --check src examples scripts tests",
@@ -102,6 +102,7 @@
102
102
  "serve:0000": "bun src/cli/comfy-ts-cli.ts serve --host 0.0.0.0",
103
103
  "serve:0000:rvion": "bun src/cli/comfy-ts-cli.ts serve --host 0.0.0.0 examples/rvion",
104
104
  "serve:rvion": "bun --watch src/cli/comfy-ts-cli.ts serve examples/rvion",
105
+ "depth": "bun examples/depth-explorer/serve.ts",
105
106
  "check:panel-scroll": "bun scripts/check-panel-scroll.ts"
106
107
  },
107
108
  "rvt": {
@@ -13,8 +13,10 @@ import {
13
13
  statSync,
14
14
  writeFileSync,
15
15
  } from 'node:fs'
16
+ import { createHash } from 'node:crypto'
16
17
  import { nanoid } from 'nanoid'
17
- import { basename, dirname, extname, join, resolve } from 'pathe'
18
+ import { basename, dirname, extname, isAbsolute, join, resolve } from 'pathe'
19
+ import { isHttpUrl, ThumbStore, thumbUrl } from 'src/cli/serve/thumbs.ts'
18
20
  import { applyVarPayload } from 'src/cli/serve/applyVarPayload.ts'
19
21
  import { describeVar, type VarDescriptor } from 'src/cli/serve/describeVar.ts'
20
22
  import { deletePromptEnhancer, listPromptEnhancers, writePromptEnhancer } from 'src/promptEnhancers.ts'
@@ -74,7 +76,15 @@ import {
74
76
  import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
75
77
  import type { ComfyHost } from 'src/host/ComfyHost.ts'
76
78
  import { DEFAULT_MEDIA_EXTENSIONS, MEDIA_KINDS, type MediaKind } from 'src/runner/mediaKinds.ts'
77
- import type { ChoiceVar, LorasVar, MediaVar, OptionalChoiceVar, PromptVar, SeedVar } from 'src/vars/ComfyVars.ts'
79
+ import type {
80
+ ChoiceOptionLook,
81
+ ChoiceVar,
82
+ LorasVar,
83
+ MediaVar,
84
+ OptionalChoiceVar,
85
+ PromptVar,
86
+ SeedVar,
87
+ } from 'src/vars/ComfyVars.ts'
78
88
  import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
79
89
  import { bang } from 'src/utils/bang.ts'
80
90
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
@@ -88,7 +98,7 @@ export type ServeExecution = {
88
98
  status: string
89
99
  /** buffer is the ONLY copy for an in-memory image (saving off); reading it on a
90
100
  * SAVED image would hit the disk, so it is only touched when absPath is null */
91
- images: { absPath: string | null; filename: string; buffer?: Uint8Array }[]
101
+ images: { absPath: string | null; filename: string; buffer?: Uint8Array; tags?: string[] }[]
92
102
  /** STRING outputs (PreviewAny, i.e. every llm graph). A text-only workflow has no images at
93
103
  * all, so without these its run reply is empty and the panel shows nothing */
94
104
  texts?: { nodeId: string; nodeKey: string | null; text: string }[]
@@ -485,6 +495,7 @@ export class ServeApp {
485
495
  if (segs[0] === 'tags' && segs.length === 3 && segs[1] != null && segs[2] != null)
486
496
  return await this.replyTags(segs[1], segs[2], req.url)
487
497
  if (segs[0] === 'settings' && segs.length === 1) return this.replySettings()
498
+ if (segs[0] === 'thumb' && segs.length === 1) return await this.replyThumb(req.url)
488
499
  if (segs[0] === 'tabs' && segs.length === 1) return this.replyTabs()
489
500
  if (segs[0] === 'hosts' && segs.length === 1) return this.replyHosts()
490
501
  if (segs[0] === 'hosts' && segs.length === 3 && segs[1] != null && segs[2] === 'logs')
@@ -617,12 +628,64 @@ export class ServeApp {
617
628
  }
618
629
 
619
630
  // #region introspection ----------------------------------------------------
631
+ /** the pictures of a descriptor made concrete for the page: a local thumb or preset becomes a
632
+ * /thumb url the store allows, a local preset not on this machine is flagged missing, a url
633
+ * stays as it is. Relative paths are relative to the workflow file */
634
+ private decorateLooks(desc: VarDescriptor, mod: ServeModule): void {
635
+ const dir = dirname(mod.file)
636
+ this.thumbs.allowRoot(dir)
637
+ this.thumbs.allowRoot(this.outputRoot)
638
+ const local = (p: string): string => (isAbsolute(p) ? p : resolve(dir, p))
639
+ const options = desc.ui?.options
640
+ if (desc.ui != null && options != null) {
641
+ const looks: Record<string, ChoiceOptionLook> = {}
642
+ for (const [value, look] of Object.entries(options)) {
643
+ if (look.thumb == null || isHttpUrl(look.thumb)) {
644
+ looks[value] = look
645
+ continue
646
+ }
647
+ const abs = local(look.thumb)
648
+ this.thumbs.allow(abs)
649
+ looks[value] = { ...look, thumb: thumbUrl(abs, 128) }
650
+ }
651
+ // a copy: the var's own ui object must keep the authored paths
652
+ desc.ui = { ...desc.ui, options: looks }
653
+ }
654
+ if (desc.mediaPresets != null)
655
+ desc.mediaPresets = desc.mediaPresets.map((preset) => {
656
+ if (isHttpUrl(preset.value)) {
657
+ // once a run fetched it, the tile is a small local thumb, not the whole remote file
658
+ const cached = this.urlInputPath(preset.value, basename(new URL(preset.value).pathname))
659
+ return { ...preset, thumb: existsSync(cached) ? thumbUrl(cached, 160) : preset.value }
660
+ }
661
+ const abs = local(preset.value)
662
+ this.thumbs.allow(abs)
663
+ return existsSync(abs)
664
+ ? { ...preset, value: abs, thumb: thumbUrl(abs, 160) }
665
+ : { ...preset, value: abs, missing: true }
666
+ })
667
+ if (MEDIA_KINDS.includes(desc.kind as MediaKind) && typeof desc.default === 'string' && desc.default !== '')
668
+ if (!isHttpUrl(desc.default)) this.thumbs.allow(local(desc.default))
669
+ }
670
+
671
+ private async replyThumb(url: string): Promise<ServeReply> {
672
+ const q = new URLSearchParams(url.split('?')[1] ?? '')
673
+ const src = q.get('src')
674
+ if (src == null || src === '') return json(400, { error: 'thumb needs ?src=<local path>' })
675
+ const out = await this.thumbs.render(src, Number(q.get('w') ?? 160) || 160)
676
+ if (out === 'forbidden')
677
+ return json(403, { error: 'not a picture a served workflow declared, nor under its folder or the outputs' })
678
+ if (out === 'missing') return json(404, { error: 'not on this machine' })
679
+ return { status: 200, contentType: 'image/webp', body: out, headers: { 'cache-control': 'max-age=300' } }
680
+ }
681
+
620
682
  private describeModule(mod: ServeModule): Record<string, unknown> {
621
683
  refreshLoraInfoCacheIfChanged()
622
684
  const hostId = mod.dw.host.data.id
623
685
  const vars: Record<string, VarDescriptor> = {}
624
686
  for (const [name, varDef] of mod.dw.entries()) {
625
687
  const desc = describeVar(varDef)
688
+ this.decorateLooks(desc, mod)
626
689
  // the raw enum values stay the payload keys; the mirror's names are for humans
627
690
  if (desc.kind === 'loras' && desc.options != null) {
628
691
  const labels: Record<string, string> = {}
@@ -700,6 +763,8 @@ export class ServeApp {
700
763
 
701
764
  /** per module, read once from a dry build: the omnibox searches and shows them */
702
765
  private tagsByModule = new Map<string, string[]>()
766
+ /** the local images the page may preview (GET /thumb), filled by describeModule */
767
+ private thumbs = new ThumbStore()
703
768
 
704
769
  private async tagsFor(mod: ServeModule): Promise<string[]> {
705
770
  const known = this.tagsByModule.get(mod.key)
@@ -1680,6 +1745,7 @@ export class ServeApp {
1680
1745
  filename: img.filename,
1681
1746
  url: img.absPath != null ? this.outputUrl(img.absPath) : key != null ? memoryUrl('images', key) : null,
1682
1747
  absPath: img.absPath,
1748
+ ...(img.tags != null && img.tags.length > 0 ? { tags: [...img.tags] } : {}),
1683
1749
  }
1684
1750
  }),
1685
1751
  audios: audios.map((a, ix) => {
@@ -1700,6 +1766,7 @@ export class ServeApp {
1700
1766
  absPath: a.absPath,
1701
1767
  }
1702
1768
  }),
1769
+ ...(mod.dw.spec.widgets != null && mod.dw.spec.widgets.length > 0 ? { widgets: mod.dw.spec.widgets } : {}),
1703
1770
  }
1704
1771
  this.kept.add({ record, imageKeys, audioKeys, videoKeys, blobs })
1705
1772
 
@@ -1872,8 +1939,16 @@ export class ServeApp {
1872
1939
  return next
1873
1940
  }
1874
1941
 
1942
+ /** one file per url: a preset or a pasted url downloads once per output root, not per run */
1943
+ private urlInputPath(url: string, name: string): string {
1944
+ const hash = createHash('sha1').update(url).digest('hex').slice(0, 16)
1945
+ return join(this.outputRoot, 'serve-inputs', `url-${hash}${extname(name)}`)
1946
+ }
1947
+
1875
1948
  /** payload image urls land as local files under outputs/serve-inputs/ */
1876
1949
  private async downloadInput(url: string): Promise<string> {
1950
+ const cached = this.urlInputPath(url, basename(new URL(url).pathname))
1951
+ if (existsSync(cached)) return cached
1877
1952
  // every failure below answers the SAME thing. Refused, DNS miss, 403 and 200-of-the-wrong
1878
1953
  // -type were four distinguishable replies, which is a port and host scanner for anything
1879
1954
  // this box can reach. The reason goes to the server log
@@ -1900,7 +1975,7 @@ export class ServeApp {
1900
1975
  if (declared > INPUT_DOWNLOAD_CAP) throw new Error(`download too large (${declared} bytes): ${url}`)
1901
1976
  const bytes = await readCapped(res, INPUT_DOWNLOAD_CAP, url)
1902
1977
  const name = basename(new URL(url).pathname) || 'input'
1903
- const abs = join(this.outputRoot, 'serve-inputs', `${nanoid(6)}-${name}`)
1978
+ const abs = this.urlInputPath(url, name)
1904
1979
  mkdirSync(dirname(abs), { recursive: true })
1905
1980
  writeFileSync(abs, bytes)
1906
1981
  return abs