comfy-ts 2.23.0 → 2.24.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/dist/{ServeApp-DolRCMHj.js → ServeApp-fsHtW5zG.js} +3 -3
- package/dist/{ServeApp-DolRCMHj.js.map → ServeApp-fsHtW5zG.js.map} +1 -1
- package/dist/cli.js +5 -5
- package/dist/{exampleAssets-Duneoq6r.js → exampleAssets-DZynSkZm.js} +79 -15
- package/dist/exampleAssets-DZynSkZm.js.map +1 -0
- package/dist/{findDefinedWorkflow-DjoJA8y7.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
- package/dist/{findDefinedWorkflow-DjoJA8y7.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
- package/dist/index.cjs +80 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -19
- package/dist/index.d.ts +53 -19
- package/dist/index.js +80 -15
- package/dist/index.js.map +1 -1
- package/dist/{run-run-Cr0L9lCK.js → run-run-Cn2JzKlE.js} +5 -5
- package/dist/{run-run-Cr0L9lCK.js.map → run-run-Cn2JzKlE.js.map} +1 -1
- package/dist/{run-serve---qA7o_m.js → run-serve-BhGegaCI.js} +4 -4
- package/dist/{run-serve---qA7o_m.js.map → run-serve-BhGegaCI.js.map} +1 -1
- package/dist/{run-tui-DxXiWo5J.js → run-tui-CrM4ijkH.js} +4 -4
- package/dist/{run-tui-DxXiWo5J.js.map → run-tui-CrM4ijkH.js.map} +1 -1
- package/dist/{schemaDrift-BTxdABHi.js → schemaDrift-BGYJZGMD.js} +3 -2
- package/dist/{schemaDrift-BTxdABHi.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
- package/dist/web.d.ts +53 -19
- package/dist/web.js +80 -15
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/depth-explorer/models.ts +6 -56
- package/examples/depth-explorer/serve.ts +12 -133
- package/examples/depth-explorer/web/App.tsx +20 -91
- package/examples/depth-explorer/web/index.html +1 -0
- package/examples/depth-explorer/web/state.ts +26 -109
- package/examples/depth-explorer/web/styles.css +1 -286
- package/examples/explorer-kit/catalog.ts +80 -0
- package/examples/explorer-kit/server.ts +167 -0
- package/examples/explorer-kit/web/base.css +289 -0
- package/examples/explorer-kit/web/runs.ts +160 -0
- package/examples/explorer-kit/web/ui.tsx +125 -0
- package/examples/rvion/17-relight.cflow.ts +2 -1
- package/examples/rvion/19-flythrough.cflow.ts +312 -0
- package/examples/rvion/20-grow-splat.cflow.ts +88 -0
- package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
- package/examples/rvion/flythroughChain.ts +171 -0
- package/examples/rvion/flythroughColmap.ts +157 -0
- package/examples/rvion/flythroughFuse.ts +199 -0
- package/examples/rvion/flythroughGuide.ts +300 -0
- package/examples/rvion/flythroughPalette.ts +310 -0
- package/examples/rvion/flythroughPath.ts +177 -0
- package/examples/rvion/flythroughSplat.ts +73 -0
- package/examples/rvion/grow-splat/align.ts +114 -0
- package/examples/rvion/grow-splat/grow.ts +198 -0
- package/examples/rvion/grow-splat/ply.ts +166 -0
- package/examples/rvion/grow-splat/raster.ts +207 -0
- package/examples/rvion/grow-splat/sharp.ts +45 -0
- package/examples/rvion/splatDataset.ts +80 -0
- package/examples/rvion/splatEval.ts +380 -0
- package/examples/upscale-explorer/models.ts +341 -0
- package/examples/upscale-explorer/serve.ts +19 -0
- package/examples/upscale-explorer/web/App.tsx +250 -0
- package/examples/upscale-explorer/web/compare.tsx +285 -0
- package/examples/upscale-explorer/web/index.html +15 -0
- package/examples/upscale-explorer/web/main.tsx +12 -0
- package/examples/upscale-explorer/web/state.ts +279 -0
- package/examples/upscale-explorer/web/styles.css +241 -0
- package/examples/upscale-explorer/web/tsconfig.json +16 -0
- package/examples/upscale-explorer/web/viewport.tsx +130 -0
- package/examples/world-explorer/web/main.tsx +2 -2
- package/package.json +4 -3
- package/src/coreExports.ts +5 -0
- package/src/host/ComfyHost.ts +6 -0
- package/src/runner/ComfyExecution.ts +22 -5
- package/src/runner/ComfyWorkflow.ts +22 -0
- package/src/runner/ComfyWsApi.ts +1 -1
- package/src/runner/comfyOrgApiKey.ts +44 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
- package/src/state.ts +2 -0
- package/src/vars/DefinedWorkflow.ts +1 -0
- package/dist/exampleAssets-Duneoq6r.js.map +0 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/* the look every explorer page shares: tokens, sidebar, source picker, grid of cards, focus box */
|
|
2
|
+
:root {
|
|
3
|
+
--bg: #111316;
|
|
4
|
+
--panel: #181b20;
|
|
5
|
+
--card: #1d2127;
|
|
6
|
+
--line: #2a2f37;
|
|
7
|
+
--text: #e6e8eb;
|
|
8
|
+
--dim: #8a929c;
|
|
9
|
+
--accent: #6aa8ff;
|
|
10
|
+
--err: #ff7a7a;
|
|
11
|
+
color-scheme: dark;
|
|
12
|
+
}
|
|
13
|
+
* {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
}
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
background: var(--bg);
|
|
19
|
+
color: var(--text);
|
|
20
|
+
font:
|
|
21
|
+
13px/1.4 ui-sans-serif,
|
|
22
|
+
system-ui,
|
|
23
|
+
-apple-system,
|
|
24
|
+
sans-serif;
|
|
25
|
+
}
|
|
26
|
+
button,
|
|
27
|
+
select,
|
|
28
|
+
a.ghost {
|
|
29
|
+
font: inherit;
|
|
30
|
+
color: var(--text);
|
|
31
|
+
background: var(--card);
|
|
32
|
+
border: 1px solid var(--line);
|
|
33
|
+
border-radius: 6px;
|
|
34
|
+
padding: 5px 10px;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
text-decoration: none;
|
|
37
|
+
}
|
|
38
|
+
button:disabled {
|
|
39
|
+
opacity: 0.45;
|
|
40
|
+
cursor: default;
|
|
41
|
+
}
|
|
42
|
+
button.primary {
|
|
43
|
+
background: var(--accent);
|
|
44
|
+
border-color: var(--accent);
|
|
45
|
+
color: #0b1220;
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
width: 100%;
|
|
48
|
+
padding: 8px;
|
|
49
|
+
margin-top: 14px;
|
|
50
|
+
}
|
|
51
|
+
.ghost {
|
|
52
|
+
background: transparent;
|
|
53
|
+
}
|
|
54
|
+
.dim {
|
|
55
|
+
color: var(--dim);
|
|
56
|
+
}
|
|
57
|
+
.small {
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
margin-top: 6px;
|
|
60
|
+
}
|
|
61
|
+
.err {
|
|
62
|
+
color: var(--err);
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
gap: 6px;
|
|
66
|
+
padding: 10px;
|
|
67
|
+
font-size: 12px;
|
|
68
|
+
overflow: auto;
|
|
69
|
+
}
|
|
70
|
+
.app {
|
|
71
|
+
min-height: 100vh;
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
}
|
|
75
|
+
header {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: baseline;
|
|
78
|
+
gap: 14px;
|
|
79
|
+
padding: 12px 20px;
|
|
80
|
+
border-bottom: 1px solid var(--line);
|
|
81
|
+
}
|
|
82
|
+
h1 {
|
|
83
|
+
font-size: 16px;
|
|
84
|
+
margin: 0;
|
|
85
|
+
}
|
|
86
|
+
h2 {
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
text-transform: uppercase;
|
|
89
|
+
letter-spacing: 0.08em;
|
|
90
|
+
color: var(--dim);
|
|
91
|
+
margin: 4px 0 10px;
|
|
92
|
+
}
|
|
93
|
+
.body {
|
|
94
|
+
display: flex;
|
|
95
|
+
flex: 1;
|
|
96
|
+
min-height: 0;
|
|
97
|
+
}
|
|
98
|
+
aside {
|
|
99
|
+
width: 280px;
|
|
100
|
+
flex-shrink: 0;
|
|
101
|
+
padding: 16px;
|
|
102
|
+
border-right: 1px solid var(--line);
|
|
103
|
+
background: var(--panel);
|
|
104
|
+
}
|
|
105
|
+
aside label {
|
|
106
|
+
display: block;
|
|
107
|
+
color: var(--dim);
|
|
108
|
+
margin: 14px 0 6px;
|
|
109
|
+
}
|
|
110
|
+
label.check {
|
|
111
|
+
display: flex;
|
|
112
|
+
gap: 8px;
|
|
113
|
+
align-items: center;
|
|
114
|
+
color: var(--text);
|
|
115
|
+
margin: 10px 0 0;
|
|
116
|
+
cursor: pointer;
|
|
117
|
+
}
|
|
118
|
+
.drop {
|
|
119
|
+
border: 1px dashed var(--line);
|
|
120
|
+
border-radius: 8px;
|
|
121
|
+
min-height: 140px;
|
|
122
|
+
display: grid;
|
|
123
|
+
place-items: center;
|
|
124
|
+
cursor: pointer;
|
|
125
|
+
overflow: hidden;
|
|
126
|
+
}
|
|
127
|
+
.drop.over {
|
|
128
|
+
border-color: var(--accent);
|
|
129
|
+
}
|
|
130
|
+
.drop img {
|
|
131
|
+
display: block;
|
|
132
|
+
width: 100%;
|
|
133
|
+
}
|
|
134
|
+
.samples {
|
|
135
|
+
display: flex;
|
|
136
|
+
gap: 6px;
|
|
137
|
+
flex-wrap: wrap;
|
|
138
|
+
margin-top: 10px;
|
|
139
|
+
}
|
|
140
|
+
.samples img {
|
|
141
|
+
width: 40px;
|
|
142
|
+
height: 40px;
|
|
143
|
+
object-fit: cover;
|
|
144
|
+
border-radius: 4px;
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
opacity: 0.8;
|
|
147
|
+
}
|
|
148
|
+
.samples img:hover {
|
|
149
|
+
opacity: 1;
|
|
150
|
+
}
|
|
151
|
+
.seg {
|
|
152
|
+
display: flex;
|
|
153
|
+
}
|
|
154
|
+
.seg button {
|
|
155
|
+
flex: 1;
|
|
156
|
+
border-radius: 0;
|
|
157
|
+
}
|
|
158
|
+
.seg button:first-child {
|
|
159
|
+
border-radius: 6px 0 0 6px;
|
|
160
|
+
}
|
|
161
|
+
.seg button:last-child {
|
|
162
|
+
border-radius: 0 6px 6px 0;
|
|
163
|
+
}
|
|
164
|
+
.seg button.on {
|
|
165
|
+
background: #2c3542;
|
|
166
|
+
border-color: var(--accent);
|
|
167
|
+
}
|
|
168
|
+
main {
|
|
169
|
+
flex: 1;
|
|
170
|
+
padding: 16px 20px 40px;
|
|
171
|
+
overflow: auto;
|
|
172
|
+
}
|
|
173
|
+
section + section {
|
|
174
|
+
margin-top: 24px;
|
|
175
|
+
}
|
|
176
|
+
.grid {
|
|
177
|
+
display: grid;
|
|
178
|
+
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
|
179
|
+
gap: 14px;
|
|
180
|
+
}
|
|
181
|
+
.card {
|
|
182
|
+
background: var(--card);
|
|
183
|
+
border: 1px solid var(--line);
|
|
184
|
+
border-radius: 8px;
|
|
185
|
+
overflow: hidden;
|
|
186
|
+
}
|
|
187
|
+
.card.off {
|
|
188
|
+
opacity: 0.6;
|
|
189
|
+
}
|
|
190
|
+
.cardHead {
|
|
191
|
+
display: flex;
|
|
192
|
+
justify-content: space-between;
|
|
193
|
+
gap: 8px;
|
|
194
|
+
padding: 8px 10px;
|
|
195
|
+
}
|
|
196
|
+
.name {
|
|
197
|
+
font-weight: 600;
|
|
198
|
+
}
|
|
199
|
+
.fam {
|
|
200
|
+
font-weight: 400;
|
|
201
|
+
color: var(--dim);
|
|
202
|
+
}
|
|
203
|
+
.meta {
|
|
204
|
+
color: var(--dim);
|
|
205
|
+
white-space: nowrap;
|
|
206
|
+
}
|
|
207
|
+
.frame {
|
|
208
|
+
background: #0c0d0f;
|
|
209
|
+
display: grid;
|
|
210
|
+
place-items: center;
|
|
211
|
+
position: relative;
|
|
212
|
+
overflow: hidden;
|
|
213
|
+
}
|
|
214
|
+
.card.done .frame {
|
|
215
|
+
cursor: zoom-in;
|
|
216
|
+
}
|
|
217
|
+
.frame > img,
|
|
218
|
+
.frame > canvas {
|
|
219
|
+
width: 100%;
|
|
220
|
+
height: 100%;
|
|
221
|
+
object-fit: contain;
|
|
222
|
+
display: block;
|
|
223
|
+
}
|
|
224
|
+
.frame .dim {
|
|
225
|
+
display: flex;
|
|
226
|
+
flex-direction: column;
|
|
227
|
+
align-items: center;
|
|
228
|
+
gap: 4px;
|
|
229
|
+
}
|
|
230
|
+
.blurb {
|
|
231
|
+
padding: 8px 10px;
|
|
232
|
+
color: var(--dim);
|
|
233
|
+
font-size: 12px;
|
|
234
|
+
}
|
|
235
|
+
.missing {
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: column;
|
|
238
|
+
gap: 4px;
|
|
239
|
+
padding: 10px;
|
|
240
|
+
font-size: 11px;
|
|
241
|
+
word-break: break-all;
|
|
242
|
+
}
|
|
243
|
+
.missing a {
|
|
244
|
+
color: var(--accent);
|
|
245
|
+
}
|
|
246
|
+
.spin {
|
|
247
|
+
display: inline-block;
|
|
248
|
+
width: 12px;
|
|
249
|
+
height: 12px;
|
|
250
|
+
border: 2px solid var(--line);
|
|
251
|
+
border-top-color: var(--accent);
|
|
252
|
+
border-radius: 50%;
|
|
253
|
+
animation: spin 0.8s linear infinite;
|
|
254
|
+
vertical-align: -2px;
|
|
255
|
+
}
|
|
256
|
+
@keyframes spin {
|
|
257
|
+
to {
|
|
258
|
+
transform: rotate(360deg);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
.focus {
|
|
262
|
+
position: fixed;
|
|
263
|
+
inset: 0;
|
|
264
|
+
background: rgba(0, 0, 0, 0.75);
|
|
265
|
+
display: grid;
|
|
266
|
+
place-items: center;
|
|
267
|
+
padding: 24px;
|
|
268
|
+
z-index: 10;
|
|
269
|
+
}
|
|
270
|
+
.focusBox {
|
|
271
|
+
background: var(--panel);
|
|
272
|
+
border: 1px solid var(--line);
|
|
273
|
+
border-radius: 10px;
|
|
274
|
+
width: min(1200px, 100%);
|
|
275
|
+
max-height: 100%;
|
|
276
|
+
display: flex;
|
|
277
|
+
flex-direction: column;
|
|
278
|
+
overflow: hidden;
|
|
279
|
+
}
|
|
280
|
+
.focusBar {
|
|
281
|
+
display: flex;
|
|
282
|
+
align-items: center;
|
|
283
|
+
gap: 10px;
|
|
284
|
+
padding: 10px 14px;
|
|
285
|
+
border-bottom: 1px solid var(--line);
|
|
286
|
+
}
|
|
287
|
+
.focusBar b {
|
|
288
|
+
margin-right: auto;
|
|
289
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// what every explorer page shares: the catalog and samples from its server, the uploaded source
|
|
2
|
+
// image, and a sequential run queue (one prompt at a time on the GPU), one RunSt per result key.
|
|
3
|
+
import { makeAutoObservable, runInAction } from 'mobx'
|
|
4
|
+
|
|
5
|
+
export type WeightFile = { node: string; input: string; file: string; folder: string; url: string }
|
|
6
|
+
|
|
7
|
+
/** a catalog entry as the server sends it (examples/explorer-kit/catalog.ts `entryPayload`) */
|
|
8
|
+
export type CardInfo = {
|
|
9
|
+
id: string
|
|
10
|
+
label: string
|
|
11
|
+
family: string
|
|
12
|
+
year: number
|
|
13
|
+
blurb: string
|
|
14
|
+
date: string
|
|
15
|
+
size: string
|
|
16
|
+
quality: number
|
|
17
|
+
speed: string
|
|
18
|
+
autoDownload: boolean
|
|
19
|
+
ok: boolean
|
|
20
|
+
missingNodes: string[]
|
|
21
|
+
missingFiles: WeightFile[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Source = { key: string; url: string; name: string; width: number; height: number }
|
|
25
|
+
|
|
26
|
+
export async function fetchCatalog<M extends CardInfo>(): Promise<{ host: string; models: M[]; samples: string[] }> {
|
|
27
|
+
const [m, s] = await Promise.all([fetch('/api/models'), fetch('/api/samples')])
|
|
28
|
+
const mj = (await m.json()) as { host: string; models: M[] }
|
|
29
|
+
const samples = (await s.json()) as string[]
|
|
30
|
+
return { host: mj.host, models: mj.models, samples }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function sampleBlob(name: string): Promise<Blob> {
|
|
34
|
+
return (await fetch(`/api/samples/${encodeURIComponent(name)}`)).blob()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** decodes the image and uploads it once to the server, which keys it by its content hash */
|
|
38
|
+
export async function uploadSource(blob: Blob, name: string): Promise<Source> {
|
|
39
|
+
const url = URL.createObjectURL(blob)
|
|
40
|
+
const img = new Image()
|
|
41
|
+
img.src = url
|
|
42
|
+
await img.decode()
|
|
43
|
+
const res = await fetch('/api/image', { method: 'POST', body: blob })
|
|
44
|
+
const j = (await res.json()) as { key?: string; error?: string }
|
|
45
|
+
if (j.key == null) throw new Error(j.error ?? 'upload failed')
|
|
46
|
+
return { key: j.key, url, name, width: img.naturalWidth, height: img.naturalHeight }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class RunSt {
|
|
50
|
+
status: 'queued' | 'running' | 'done' | 'error' = 'queued'
|
|
51
|
+
url: string | null = null
|
|
52
|
+
ms: number | null = null
|
|
53
|
+
error: string | null = null
|
|
54
|
+
startedAt = 0
|
|
55
|
+
/** the result's file size and pixel size, once done */
|
|
56
|
+
bytes = 0
|
|
57
|
+
width = 0
|
|
58
|
+
height = 0
|
|
59
|
+
/** 'box': ComfyUI reused an earlier run (`ms` is then the transfer); 'server': the server kept it */
|
|
60
|
+
cached: 'no' | 'box' | 'server' = 'no'
|
|
61
|
+
constructor() {
|
|
62
|
+
makeAutoObservable(this)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type RunBody = { image: string; model: string } & Record<string, unknown>
|
|
67
|
+
|
|
68
|
+
/** POSTs each job's body to /api/run in turn; the body names the image and the model */
|
|
69
|
+
export class RunQueue {
|
|
70
|
+
results = new Map<string, RunSt>()
|
|
71
|
+
private queue: { key: string; body: RunBody; onDone?: (r: RunSt) => void }[] = []
|
|
72
|
+
draining = false
|
|
73
|
+
/** ticks every 200 ms, for the elapsed timers of running cards */
|
|
74
|
+
now = Date.now()
|
|
75
|
+
|
|
76
|
+
constructor() {
|
|
77
|
+
makeAutoObservable(this, { results: true })
|
|
78
|
+
setInterval(() => runInAction(() => (this.now = Date.now())), 200)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get busy(): boolean {
|
|
82
|
+
return this.queue.length > 0 || this.draining
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get(key: string): RunSt | undefined {
|
|
86
|
+
return this.results.get(key)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `onDone`: once this result is in (a page derives a thumbnail from it, say) */
|
|
90
|
+
enqueue(key: string, body: RunBody, onDone?: (r: RunSt) => void): void {
|
|
91
|
+
const prev = this.results.get(key)
|
|
92
|
+
if (prev != null && (prev.status === 'queued' || prev.status === 'running')) return
|
|
93
|
+
this.results.set(key, new RunSt())
|
|
94
|
+
this.queue.push({ key, body, onDone })
|
|
95
|
+
void this.drain()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** resolves once the queue is empty */
|
|
99
|
+
settled(): Promise<void> {
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
const tick = (): void => {
|
|
102
|
+
if (this.busy) setTimeout(tick, 100)
|
|
103
|
+
else resolve()
|
|
104
|
+
}
|
|
105
|
+
tick()
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async drain(): Promise<void> {
|
|
110
|
+
if (this.draining) return
|
|
111
|
+
this.draining = true
|
|
112
|
+
try {
|
|
113
|
+
for (;;) {
|
|
114
|
+
const job = this.queue.shift()
|
|
115
|
+
if (job == null) break
|
|
116
|
+
const r = this.results.get(job.key)
|
|
117
|
+
if (r == null) continue
|
|
118
|
+
runInAction(() => {
|
|
119
|
+
r.status = 'running'
|
|
120
|
+
r.startedAt = Date.now()
|
|
121
|
+
})
|
|
122
|
+
try {
|
|
123
|
+
const res = await fetch('/api/run', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: { 'content-type': 'application/json' },
|
|
126
|
+
body: JSON.stringify(job.body),
|
|
127
|
+
})
|
|
128
|
+
if (!res.ok) {
|
|
129
|
+
const j = (await res.json()) as { error?: string }
|
|
130
|
+
throw new Error(j.error ?? `http ${res.status}`)
|
|
131
|
+
}
|
|
132
|
+
const blob = await res.blob()
|
|
133
|
+
const url = URL.createObjectURL(blob)
|
|
134
|
+
const img = new Image()
|
|
135
|
+
img.src = url
|
|
136
|
+
await img.decode()
|
|
137
|
+
const ms = Number(res.headers.get('x-ms'))
|
|
138
|
+
const cached = res.headers.get('x-cached')
|
|
139
|
+
runInAction(() => {
|
|
140
|
+
r.url = url
|
|
141
|
+
r.ms = ms
|
|
142
|
+
r.bytes = blob.size
|
|
143
|
+
r.width = img.naturalWidth
|
|
144
|
+
r.height = img.naturalHeight
|
|
145
|
+
r.cached = cached === 'box' || cached === 'server' ? cached : 'no'
|
|
146
|
+
r.status = 'done'
|
|
147
|
+
})
|
|
148
|
+
job.onDone?.(r)
|
|
149
|
+
} catch (e) {
|
|
150
|
+
runInAction(() => {
|
|
151
|
+
r.error = e instanceof Error ? e.message : String(e)
|
|
152
|
+
r.status = 'error'
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} finally {
|
|
157
|
+
runInAction(() => (this.draining = false))
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// the widgets every explorer page shares: a segmented choice, the source picker (drop, click,
|
|
2
|
+
// paste or a sample) and a card's body before its result shows.
|
|
3
|
+
import { observer } from 'mobx-react-lite'
|
|
4
|
+
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
5
|
+
import type { CardInfo, RunSt, Source } from './runs.ts'
|
|
6
|
+
|
|
7
|
+
export function Seg<T extends string | number>(p: {
|
|
8
|
+
value: T
|
|
9
|
+
options: [T, string][]
|
|
10
|
+
onChange: (v: T) => void
|
|
11
|
+
tips?: string[]
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<div className="seg">
|
|
15
|
+
{p.options.map(([v, label], i) => (
|
|
16
|
+
<button key={String(v)} className={v === p.value ? 'on' : ''} title={p.tips?.[i]} onClick={() => p.onChange(v)}>
|
|
17
|
+
{label}
|
|
18
|
+
</button>
|
|
19
|
+
))}
|
|
20
|
+
</div>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** a finished run's time; a result ComfyUI took from its cache has none of its own */
|
|
25
|
+
export const timeOf = (r: RunSt): string =>
|
|
26
|
+
r.cached === 'box' ? 'box cache' : r.ms != null ? `${(r.ms / 1000).toFixed(1)} s` : ''
|
|
27
|
+
|
|
28
|
+
/** the source image: drop a file, click to pick one, paste anywhere on the page, or a sample */
|
|
29
|
+
export function SourcePicker(p: {
|
|
30
|
+
source: Source | null
|
|
31
|
+
samples: string[]
|
|
32
|
+
onFile: (f: Blob, name: string) => void
|
|
33
|
+
onSample: (name: string) => void
|
|
34
|
+
}) {
|
|
35
|
+
const [drag, setDrag] = useState(false)
|
|
36
|
+
const fileRef = useRef<HTMLInputElement>(null)
|
|
37
|
+
const take = (f: File | undefined): void => {
|
|
38
|
+
if (f != null && f.type.startsWith('image/')) p.onFile(f, f.name)
|
|
39
|
+
}
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const onPaste = (e: ClipboardEvent): void => {
|
|
42
|
+
take([...(e.clipboardData?.files ?? [])].find((x) => x.type.startsWith('image/')))
|
|
43
|
+
}
|
|
44
|
+
window.addEventListener('paste', onPaste)
|
|
45
|
+
return () => window.removeEventListener('paste', onPaste)
|
|
46
|
+
})
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
<div
|
|
50
|
+
className={`drop ${drag ? 'over' : ''}`}
|
|
51
|
+
onDragOver={(e) => {
|
|
52
|
+
e.preventDefault()
|
|
53
|
+
setDrag(true)
|
|
54
|
+
}}
|
|
55
|
+
onDragLeave={() => setDrag(false)}
|
|
56
|
+
onDrop={(e) => {
|
|
57
|
+
e.preventDefault()
|
|
58
|
+
setDrag(false)
|
|
59
|
+
take(e.dataTransfer.files[0])
|
|
60
|
+
}}
|
|
61
|
+
onClick={() => fileRef.current?.click()}
|
|
62
|
+
>
|
|
63
|
+
{p.source != null ? <img src={p.source.url} alt={p.source.name} /> : <span>drop an image</span>}
|
|
64
|
+
<input ref={fileRef} type="file" accept="image/*" hidden onChange={(e) => take(e.target.files?.[0])} />
|
|
65
|
+
</div>
|
|
66
|
+
<div className="dim small">
|
|
67
|
+
{p.source != null ? `${p.source.name} · ${p.source.width}×${p.source.height}` : ''}
|
|
68
|
+
<br />
|
|
69
|
+
drop, click or paste an image
|
|
70
|
+
</div>
|
|
71
|
+
<div className="samples">
|
|
72
|
+
{p.samples.map((s) => (
|
|
73
|
+
<img key={s} src={`/api/samples/${s}`} alt={s} title={s} onClick={() => p.onSample(s)} />
|
|
74
|
+
))}
|
|
75
|
+
</div>
|
|
76
|
+
</>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** a card's frame before its result: the missing files, a run button, queued, the timer, the error */
|
|
81
|
+
export const RunBody = observer(function RunBody(p: {
|
|
82
|
+
model: CardInfo
|
|
83
|
+
run: RunSt | undefined
|
|
84
|
+
now: number
|
|
85
|
+
canRun: boolean
|
|
86
|
+
onRun: () => void
|
|
87
|
+
}): ReactNode {
|
|
88
|
+
const r = p.run
|
|
89
|
+
if (!p.model.ok)
|
|
90
|
+
return (
|
|
91
|
+
<div className="missing">
|
|
92
|
+
<b>not on this host</b>
|
|
93
|
+
{p.model.missingNodes.length > 0 && <span>nodes: {p.model.missingNodes.join(', ')}</span>}
|
|
94
|
+
{p.model.missingFiles.map((f) => (
|
|
95
|
+
<a key={f.file} href={f.url} target="_blank" rel="noreferrer">
|
|
96
|
+
models/{f.folder}/{f.file}
|
|
97
|
+
</a>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
)
|
|
101
|
+
if (r == null)
|
|
102
|
+
return (
|
|
103
|
+
<button className="ghost" onClick={p.onRun} disabled={!p.canRun}>
|
|
104
|
+
run
|
|
105
|
+
</button>
|
|
106
|
+
)
|
|
107
|
+
if (r.status === 'queued') return <span className="dim">queued</span>
|
|
108
|
+
if (r.status === 'running')
|
|
109
|
+
return (
|
|
110
|
+
<span className="dim">
|
|
111
|
+
<span className="spin" /> {((p.now - r.startedAt) / 1000).toFixed(1)} s
|
|
112
|
+
{p.model.autoDownload && p.now - r.startedAt > 8000 && <small>first run downloads the weights</small>}
|
|
113
|
+
</span>
|
|
114
|
+
)
|
|
115
|
+
if (r.status === 'error')
|
|
116
|
+
return (
|
|
117
|
+
<div className="err">
|
|
118
|
+
<span>{r.error}</span>
|
|
119
|
+
<button className="ghost" onClick={p.onRun}>
|
|
120
|
+
retry
|
|
121
|
+
</button>
|
|
122
|
+
</div>
|
|
123
|
+
)
|
|
124
|
+
return null
|
|
125
|
+
})
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
//
|
|
10
10
|
// run directly: bun examples/rvion/17-relight.cflow.ts [path/to/image.png]
|
|
11
11
|
import { asAbsolutePath, type BaseNodeInputs, ComfyTS, exampleImagePath, MediaImage, v, widget } from 'comfy-ts'
|
|
12
|
-
import {
|
|
12
|
+
import { MODELS, optionLook, type ModelEntry } from '../depth-explorer/models.ts'
|
|
13
|
+
import { availability } from '../explorer-kit/catalog.ts'
|
|
13
14
|
|
|
14
15
|
const comfy = ComfyTS.create()
|
|
15
16
|
const host = comfy.host({ id: 'windows-1' })
|