comfy-ts 2.12.0 → 2.13.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/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +123 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -16
- package/dist/index.d.ts +96 -16
- package/dist/index.js +123 -12
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BeAznay5.js → run-serve-DlRBv_Nk.js} +281 -19
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-BTGjvnKk.js → run-tui-B5uxm2_l.js} +4 -4
- package/dist/{run-tui-BTGjvnKk.js.map → run-tui-B5uxm2_l.js.map} +1 -1
- package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
- package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
- package/dist/serve-web.js +291 -129
- package/dist/{state-C7REnHan.js → state-CUp2J1Zy.js} +122 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +96 -16
- package/dist/web.js +123 -12
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -0
- package/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +157 -18
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/web/api.ts +24 -0
- package/src/cli/serve/web/components/App.tsx +305 -156
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +44 -19
- package/src/cli/serve/web/components/Icon.tsx +40 -0
- package/src/cli/serve/web/components/Omnibox.tsx +70 -20
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
- package/src/cli/serve/web/components/VarsForm.tsx +70 -351
- package/src/cli/serve/web/components/controls/LorasControl.tsx +24 -22
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +6 -3
- package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
- package/src/cli/serve/web/state/FormSt.ts +22 -2
- package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
- package/src/cli/serve/web/state/WebSt.ts +172 -33
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -0
- package/src/cli/serve/web/state/generateButton.ts +1 -1
- package/src/cli/serve/web/state/omnibox.ts +82 -18
- package/src/cli/serve/web/state/shortcuts.ts +56 -7
- package/src/cli/serve/web/styles.ts +242 -82
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/state/DraftsSt.ts +10 -6
- package/src/coreExports.ts +1 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/utils/copyName.ts +12 -0
- package/src/vars/DefinedWorkflow.ts +7 -1
- package/dist/LogsSt-U1H0mP1m.js.map +0 -1
- package/dist/run-serve-BeAznay5.js.map +0 -1
- package/dist/state-C7REnHan.js.map +0 -1
|
@@ -24,9 +24,12 @@ import { ENHANCE_KEY, isDraftMetaKey } from 'src/cli/draftMeta.ts'
|
|
|
24
24
|
import { managerOnlyLoraOptions } from 'src/cli/serve/managerOnlyLoras.ts'
|
|
25
25
|
import { resolveTagSource, TagSources } from 'src/cli/serve/tagSource.ts'
|
|
26
26
|
import { FAVICON_DATA_URI } from 'src/cli/serve/favicon.ts'
|
|
27
|
+
import { type TagNode, workflowTags } from 'src/cli/serve/workflowTags.ts'
|
|
28
|
+
import { workspaceLabels } from 'src/cli/serve/workspaceLabels.ts'
|
|
27
29
|
import { driftChanged, summarizeDrift } from 'src/host/schemaDrift.ts'
|
|
28
30
|
import { validSavePrefix, validStoreName } from 'src/utils/safeName.ts'
|
|
29
31
|
import { readServeSettings, writeServeSettings, type ServeSettings } from 'src/cli/serve/serveSettings.ts'
|
|
32
|
+
import { readTabs, SERVE_TABS_FILE, type DraftTab } from 'src/cli/serve/web/state/draftTabs.ts'
|
|
30
33
|
import { assembleLogChunks } from 'src/cli/tui/state/LogsSt.ts'
|
|
31
34
|
import { draftsDirForFile, listDraftsForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
32
35
|
import {
|
|
@@ -82,6 +85,8 @@ export type ServeExecution = {
|
|
|
82
85
|
/** STRING outputs (PreviewAny, i.e. every llm graph). A text-only workflow has no images at
|
|
83
86
|
* all, so without these its run reply is empty and the panel shows nothing */
|
|
84
87
|
texts?: { nodeId: string; nodeKey: string | null; text: string }[]
|
|
88
|
+
/** audio files (SaveAudio*, PreviewAudio). absPath null = saving off, bytes the only copy */
|
|
89
|
+
audios?: { absPath: string | null; filename: string; mime: string; bytes: Uint8Array }[]
|
|
85
90
|
data: { id: string; error?: unknown }
|
|
86
91
|
/** live global progress (ComfyExecution has it; fakes may omit) — the /run/<module> poll reads it */
|
|
87
92
|
progressGlobal?: { percent: number }
|
|
@@ -228,6 +233,12 @@ const CONTENT_TYPES: Record<string, string> = {
|
|
|
228
233
|
'.gif': 'image/gif',
|
|
229
234
|
'.mp4': 'video/mp4',
|
|
230
235
|
'.webm': 'video/webm',
|
|
236
|
+
'.flac': 'audio/flac',
|
|
237
|
+
'.mp3': 'audio/mpeg',
|
|
238
|
+
'.opus': 'audio/ogg',
|
|
239
|
+
'.ogg': 'audio/ogg',
|
|
240
|
+
'.wav': 'audio/wav',
|
|
241
|
+
'.m4a': 'audio/mp4',
|
|
231
242
|
'.json': 'application/json',
|
|
232
243
|
'.txt': 'text/plain',
|
|
233
244
|
}
|
|
@@ -286,6 +297,7 @@ const USAGE = [
|
|
|
286
297
|
'GET /hosts/<hostId>/ping — is that host answering right now (restart watch)',
|
|
287
298
|
'GET /hosts/<hostId>/logs — the last lines of that host console',
|
|
288
299
|
'GET /images/<promptId>/<ix> — an in-memory output (saving off), while the process lives',
|
|
300
|
+
'GET /audio/<promptId>/<ix> — the same for an in-memory audio output',
|
|
289
301
|
'GET /outputs/<path> — generated files',
|
|
290
302
|
]
|
|
291
303
|
|
|
@@ -318,10 +330,10 @@ const WEB_SHELL = `<!doctype html>
|
|
|
318
330
|
export class ServeApp {
|
|
319
331
|
private starter: ServeStarter
|
|
320
332
|
/** last SERVED seed per `module/draft/var` — '+'/'-' modes continue from it.
|
|
321
|
-
* draftBase remembers which DRAFT value the continuation grew from
|
|
322
|
-
*
|
|
323
|
-
* value wins and the
|
|
324
|
-
private seedState = new Map<string, { last: number; draftBase: number }>()
|
|
333
|
+
* draftBase remembers which DRAFT value the continuation grew from, served every seed
|
|
334
|
+
* the chain handed out: a draft holding one of them is the panel's write-back (it lags a
|
|
335
|
+
* queued run), anything else is a typed value, which wins and restarts the chain there */
|
|
336
|
+
private seedState = new Map<string, { last: number; draftBase: number; served: number[] }>()
|
|
325
337
|
/** per-module promise chain: vars are shared mutable state, apply→send is exclusive */
|
|
326
338
|
private chains = new Map<string, Promise<unknown>>()
|
|
327
339
|
/** saving + host overrides are live settings (the web ui flips them). LAZY: a ServeApp can
|
|
@@ -345,6 +357,10 @@ export class ServeApp {
|
|
|
345
357
|
starter?: ServeStarter
|
|
346
358
|
outputRoot?: string
|
|
347
359
|
loadErrors?: Record<string, string>
|
|
360
|
+
/** where `.comfy-ts/` lives and the folder serve scanned: the menu's read-only cards.
|
|
361
|
+
* absent = the index leaves both out */
|
|
362
|
+
workspace?: string
|
|
363
|
+
root?: string
|
|
348
364
|
/** web ui bundle provider (run-serve wires loadOrBuildWebJs), called on every page load
|
|
349
365
|
* and owning its own cache; absent = api only */
|
|
350
366
|
webJs?: () => Promise<string | null>
|
|
@@ -384,7 +400,7 @@ export class ServeApp {
|
|
|
384
400
|
headers: NO_STORE,
|
|
385
401
|
}
|
|
386
402
|
}
|
|
387
|
-
if (segs.length === 0 || (segs[0] === 'drafts' && segs.length === 1)) return this.replyIndex()
|
|
403
|
+
if (segs.length === 0 || (segs[0] === 'drafts' && segs.length === 1)) return await this.replyIndex()
|
|
388
404
|
if (segs[0] === 'web' && segs[1] === 'app.js' && segs.length === 2) return await this.replyWebJs()
|
|
389
405
|
if (segs[0] === 'drafts' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
390
406
|
return this.replyDraft(segs[1], segs[2])
|
|
@@ -402,6 +418,7 @@ export class ServeApp {
|
|
|
402
418
|
if (segs[0] === 'tags' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
403
419
|
return await this.replyTags(segs[1], segs[2], req.url)
|
|
404
420
|
if (segs[0] === 'settings' && segs.length === 1) return this.replySettings()
|
|
421
|
+
if (segs[0] === 'tabs' && segs.length === 1) return this.replyTabs()
|
|
405
422
|
if (segs[0] === 'hosts' && segs.length === 1) return this.replyHosts()
|
|
406
423
|
if (segs[0] === 'hosts' && segs.length === 3 && segs[1] != null && segs[2] === 'logs')
|
|
407
424
|
return await this.replyHostLogs(segs[1])
|
|
@@ -411,6 +428,8 @@ export class ServeApp {
|
|
|
411
428
|
return await this.replyHostDrift(segs[1], req.url.includes('full=1'))
|
|
412
429
|
if (segs[0] === 'images' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
413
430
|
return this.replyMemoryImage(`${segs[1]}/${segs[2]}`)
|
|
431
|
+
if (segs[0] === 'audio' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
432
|
+
return this.replyMemoryImage(`audio/${segs[1]}/${segs[2]}`)
|
|
414
433
|
if (segs[0] === 'outputs') return this.replyOutput(segs.slice(1))
|
|
415
434
|
return json(404, { error: `no route: GET ${path}`, usage: USAGE })
|
|
416
435
|
}
|
|
@@ -427,6 +446,7 @@ export class ServeApp {
|
|
|
427
446
|
if (req.method === 'DELETE' && segs[0] === 'drafts' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
428
447
|
return await this.replyDeleteDraft(segs[1], segs[2])
|
|
429
448
|
if (req.method === 'PUT' && segs[0] === 'settings' && segs.length === 1) return this.replySaveSettings(req)
|
|
449
|
+
if (req.method === 'PUT' && segs[0] === 'tabs' && segs.length === 1) return this.replySaveTabs(req)
|
|
430
450
|
if (req.method === 'PUT' && segs[0] === 'hosts' && segs.length === 2 && segs[1] != null)
|
|
431
451
|
return this.replySetHost(segs[1], req)
|
|
432
452
|
if (req.method === 'POST' && segs[0] === 'hosts' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
@@ -598,14 +618,52 @@ export class ServeApp {
|
|
|
598
618
|
vars,
|
|
599
619
|
// the names of the workflow's live previews: the panel asks POST /preview/<module>
|
|
600
620
|
previews: Object.keys(mod.dw.spec.previews ?? {}),
|
|
621
|
+
tags: this.tagsByModule.get(mod.key) ?? mod.dw.spec.tags ?? [],
|
|
601
622
|
}
|
|
602
623
|
}
|
|
603
624
|
|
|
604
|
-
|
|
625
|
+
/** per module, read once from a dry build: the omnibox searches and shows them */
|
|
626
|
+
private tagsByModule = new Map<string, string[]>()
|
|
627
|
+
|
|
628
|
+
private async tagsFor(mod: ServeModule): Promise<string[]> {
|
|
629
|
+
const known = this.tagsByModule.get(mod.key)
|
|
630
|
+
if (known != null) return known
|
|
631
|
+
const extra = mod.dw.spec.tags ?? []
|
|
632
|
+
const varKinds = mod.dw.entries().map(([, varDef]) => varDef.kind)
|
|
633
|
+
let tags: string[]
|
|
634
|
+
try {
|
|
635
|
+
const wf = await mod.dw.build({ dry: true })
|
|
636
|
+
const nodes: TagNode[] = wf.nodes.map((n) => ({
|
|
637
|
+
id: n.uid,
|
|
638
|
+
classType: n.json.class_type,
|
|
639
|
+
outputNode: n.$schema.raw.output_node,
|
|
640
|
+
outputTypes: n.$schema.outputs.map((o) => o.typeName),
|
|
641
|
+
links: Object.values(n.json.inputs).flatMap((v): [string, number][] =>
|
|
642
|
+
Array.isArray(v) && v.length === 2 && typeof v[1] === 'number' ? [[String(v[0]), v[1]]] : [],
|
|
643
|
+
),
|
|
644
|
+
}))
|
|
645
|
+
tags = workflowTags({ nodes, varKinds, extra })
|
|
646
|
+
} catch (e) {
|
|
647
|
+
console.error(`[serve] 🔴 tags for ${mod.key}: dry build failed, spec tags only: ${extractErrorMessage(e)}`)
|
|
648
|
+
tags = workflowTags({ nodes: [], varKinds, extra })
|
|
649
|
+
}
|
|
650
|
+
this.tagsByModule.set(mod.key, tags)
|
|
651
|
+
return tags
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private async replyIndex(): Promise<ServeReply> {
|
|
655
|
+
for (const m of this.modules) await this.tagsFor(m)
|
|
605
656
|
return json(200, {
|
|
606
657
|
server: 'comfy-ts serve',
|
|
607
658
|
usage: USAGE,
|
|
608
659
|
workflows: this.modules.map((m) => this.describeModule(m)),
|
|
660
|
+
...(this.opts.workspace == null
|
|
661
|
+
? {}
|
|
662
|
+
: workspaceLabels({
|
|
663
|
+
workspace: this.opts.workspace,
|
|
664
|
+
root: this.opts.root ?? this.opts.workspace,
|
|
665
|
+
home: process.env.HOME ?? '',
|
|
666
|
+
})),
|
|
609
667
|
...(this.opts.loadErrors != null && Object.keys(this.opts.loadErrors).length > 0
|
|
610
668
|
? { loadErrors: this.opts.loadErrors }
|
|
611
669
|
: {}),
|
|
@@ -1070,7 +1128,7 @@ export class ServeApp {
|
|
|
1070
1128
|
const hit = this.memoryImages.get(key)
|
|
1071
1129
|
if (hit == null)
|
|
1072
1130
|
return json(404, {
|
|
1073
|
-
error: `no in-memory
|
|
1131
|
+
error: `no in-memory output '${key}' — it expired (only the last ${this.MEMORY_IMAGE_CAP} are kept) or the server restarted. Turn saving on to keep outputs.`,
|
|
1074
1132
|
})
|
|
1075
1133
|
return { status: 200, contentType: hit.contentType, body: hit.bytes }
|
|
1076
1134
|
}
|
|
@@ -1138,6 +1196,60 @@ export class ServeApp {
|
|
|
1138
1196
|
})
|
|
1139
1197
|
}
|
|
1140
1198
|
|
|
1199
|
+
// #region open draft tabs (the web ui's tab bar) ------------------------------
|
|
1200
|
+
/** held by the process, so every window and reload sees the same tabs, and mirrored to a file
|
|
1201
|
+
* under .comfy-ts/ (gitignored wholesale) so a restart keeps them. null = not read yet */
|
|
1202
|
+
private tabs: DraftTab[] | null = null
|
|
1203
|
+
|
|
1204
|
+
private tabsFile(): string {
|
|
1205
|
+
return join(comfyts.baseFolder, SERVE_TABS_FILE)
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/** only drafts that still exist: a tab whose file was deleted elsewhere is dropped on read */
|
|
1209
|
+
private liveTabs(raw: unknown): DraftTab[] {
|
|
1210
|
+
return readTabs(
|
|
1211
|
+
raw,
|
|
1212
|
+
this.modules.map((m) => ({ module: m.key, drafts: this.draftsFor(m) })),
|
|
1213
|
+
)
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
private replyTabs(): ServeReply {
|
|
1217
|
+
if (this.tabs == null) {
|
|
1218
|
+
const path = this.tabsFile()
|
|
1219
|
+
let raw: unknown = []
|
|
1220
|
+
try {
|
|
1221
|
+
if (existsSync(path)) raw = JSON.parse(readFileSync(path, 'utf8'))
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
console.error(`[serve] 🔴 open tabs unreadable (${path}), starting with none:`, e)
|
|
1224
|
+
}
|
|
1225
|
+
this.tabs = this.liveTabs(raw)
|
|
1226
|
+
}
|
|
1227
|
+
this.tabs = this.liveTabs(this.tabs)
|
|
1228
|
+
return json(200, { tabs: this.tabs })
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
private replySaveTabs(req: ServeRequest): ServeReply {
|
|
1232
|
+
let parsed: unknown
|
|
1233
|
+
try {
|
|
1234
|
+
parsed = JSON.parse(req.body ?? '')
|
|
1235
|
+
} catch (e) {
|
|
1236
|
+
return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` })
|
|
1237
|
+
}
|
|
1238
|
+
const raw = parsed != null && typeof parsed === 'object' ? (parsed as { tabs?: unknown }).tabs : undefined
|
|
1239
|
+
if (!Array.isArray(raw) || raw.length > 100)
|
|
1240
|
+
return json(400, { error: 'expects { "tabs": [{ "module", "draft" }, …] }' })
|
|
1241
|
+
this.tabs = this.liveTabs(raw)
|
|
1242
|
+
try {
|
|
1243
|
+
mkdirSync(comfyts.baseFolder, { recursive: true })
|
|
1244
|
+
writeFileSync(this.tabsFile(), JSON.stringify(this.tabs, null, 2))
|
|
1245
|
+
} catch (e) {
|
|
1246
|
+
// kept for this process either way: only the restart loses them, and the reply says so
|
|
1247
|
+
console.error(`[serve] 🔴 open tabs not saved to ${this.tabsFile()}:`, e)
|
|
1248
|
+
return json(200, { tabs: this.tabs, warning: `not saved: ${extractErrorMessage(e)}` })
|
|
1249
|
+
}
|
|
1250
|
+
return json(200, { tabs: this.tabs })
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1141
1253
|
// #region prompt enhancers (the web ui's master prompts, as .md files) ------
|
|
1142
1254
|
/** the folder is seeded on the first read, so `refine-krea2-prompt.md` exists to be edited */
|
|
1143
1255
|
/** tag lists by source, loaded on the first query and kept for the process */
|
|
@@ -1466,6 +1578,8 @@ export class ServeApp {
|
|
|
1466
1578
|
}
|
|
1467
1579
|
|
|
1468
1580
|
const produced = [`${execution.images.length} image(s)`]
|
|
1581
|
+
const audios = execution.audios ?? []
|
|
1582
|
+
if (audios.length > 0) produced.push(`${audios.length} audio(s)`)
|
|
1469
1583
|
if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`)
|
|
1470
1584
|
console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1000).toFixed(1)}s · ${produced.join(' · ')}`)
|
|
1471
1585
|
|
|
@@ -1479,6 +1593,15 @@ export class ServeApp {
|
|
|
1479
1593
|
memoryKeys.set(ix, key)
|
|
1480
1594
|
}
|
|
1481
1595
|
|
|
1596
|
+
// same store as the images, own key space: the audio route adds the `audio/` prefix
|
|
1597
|
+
const audioKeys = new Map<number, string>()
|
|
1598
|
+
for (const [ix, a] of audios.entries()) {
|
|
1599
|
+
if (a.absPath != null) continue
|
|
1600
|
+
const key = `${execution.data.id}/${ix}`
|
|
1601
|
+
this.rememberMemoryImage(`audio/${key}`, a.bytes, a.filename)
|
|
1602
|
+
audioKeys.set(ix, key)
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1482
1605
|
// Accept: image/* → first image's bytes directly (curl -o, <img src>)
|
|
1483
1606
|
const first = execution.images[0]
|
|
1484
1607
|
if (req.accept?.includes('image/') && first != null) {
|
|
@@ -1514,6 +1637,20 @@ export class ServeApp {
|
|
|
1514
1637
|
: null,
|
|
1515
1638
|
absPath: img.absPath,
|
|
1516
1639
|
})),
|
|
1640
|
+
audios: audios.map((a, ix) => ({
|
|
1641
|
+
filename: a.filename,
|
|
1642
|
+
mime: a.mime,
|
|
1643
|
+
url:
|
|
1644
|
+
a.absPath != null
|
|
1645
|
+
? this.outputUrl(a.absPath)
|
|
1646
|
+
: audioKeys.has(ix)
|
|
1647
|
+
? `/audio/${(audioKeys.get(ix) ?? '')
|
|
1648
|
+
.split('/')
|
|
1649
|
+
.map((seg) => encodeURIComponent(seg))
|
|
1650
|
+
.join('/')}`
|
|
1651
|
+
: null,
|
|
1652
|
+
absPath: a.absPath,
|
|
1653
|
+
})),
|
|
1517
1654
|
})
|
|
1518
1655
|
}
|
|
1519
1656
|
|
|
@@ -1615,17 +1752,19 @@ export class ServeApp {
|
|
|
1615
1752
|
const seedVar = varDef as SeedVar
|
|
1616
1753
|
const stateKey = `${mod.key}/${draft}/${k}`
|
|
1617
1754
|
const draftValue = draftSeedValues.get(k) ?? seedVar.value
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1755
|
+
const prev = this.seedState.get(stateKey)
|
|
1756
|
+
const continues =
|
|
1757
|
+
!(k in payload) &&
|
|
1758
|
+
(seedVar.mode === '+' || seedVar.mode === '-') &&
|
|
1759
|
+
prev != null &&
|
|
1760
|
+
(prev.draftBase === draftValue || prev.served.includes(draftValue))
|
|
1761
|
+
if (!(k in payload) && seedVar.mode === '?') seedVar.randomize()
|
|
1762
|
+
if (continues) {
|
|
1763
|
+
seedVar.set(prev.last + (seedVar.mode === '+' ? 1 : -1))
|
|
1764
|
+
// bounded: a write-back never lags by more than the queue
|
|
1765
|
+
const served = [...prev.served, seedVar.value].slice(-256)
|
|
1766
|
+
this.seedState.set(stateKey, { last: seedVar.value, draftBase: prev.draftBase, served })
|
|
1767
|
+
} else this.seedState.set(stateKey, { last: seedVar.value, draftBase: draftValue, served: [seedVar.value] })
|
|
1629
1768
|
seeds[k] = seedVar.value
|
|
1630
1769
|
}
|
|
1631
1770
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// HTTP byte ranges on binary replies. WebKit (Safari, and a WKWebView app window) plays audio and
|
|
2
|
+
// video only from a server that answers `Range` with 206: without it a flac never starts there
|
|
3
|
+
import type { ServeReply } from 'src/cli/serve/ServeApp.ts'
|
|
4
|
+
|
|
5
|
+
/** one range, the only kind media players send: `bytes=a-b`, `bytes=a-`, `bytes=-n` */
|
|
6
|
+
function parseRange(header: string, size: number): { start: number; end: number } | 'unsatisfiable' | null {
|
|
7
|
+
const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim())
|
|
8
|
+
if (m == null) return null
|
|
9
|
+
const a = m[1] ?? ''
|
|
10
|
+
const b = m[2] ?? ''
|
|
11
|
+
if (a === '' && b === '') return null
|
|
12
|
+
if (a === '') {
|
|
13
|
+
const n = Number(b)
|
|
14
|
+
if (n === 0) return 'unsatisfiable'
|
|
15
|
+
return { start: Math.max(0, size - n), end: size - 1 }
|
|
16
|
+
}
|
|
17
|
+
const start = Number(a)
|
|
18
|
+
const end = b === '' ? size - 1 : Math.min(Number(b), size - 1)
|
|
19
|
+
if (start >= size || start > end) return 'unsatisfiable'
|
|
20
|
+
return { start, end }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** a whole 200 binary reply gets its length and `accept-ranges`; a range request gets 206 with
|
|
24
|
+
* those bytes, or 416 past the end. Text replies and errors pass through untouched */
|
|
25
|
+
export function withByteRange(reply: ServeReply, req: { method: string; range?: string }): ServeReply {
|
|
26
|
+
if (req.method !== 'GET' || reply.status !== 200 || typeof reply.body === 'string') return reply
|
|
27
|
+
const size = reply.body.length
|
|
28
|
+
const base = { ...reply.headers, 'accept-ranges': 'bytes' }
|
|
29
|
+
const range = req.range == null ? null : parseRange(req.range, size)
|
|
30
|
+
if (range == null) return { ...reply, headers: { ...base, 'content-length': String(size) } }
|
|
31
|
+
if (range === 'unsatisfiable')
|
|
32
|
+
return {
|
|
33
|
+
status: 416,
|
|
34
|
+
contentType: reply.contentType,
|
|
35
|
+
body: new Uint8Array(0),
|
|
36
|
+
headers: { ...base, 'content-range': `bytes */${size}` },
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
status: 206,
|
|
40
|
+
contentType: reply.contentType,
|
|
41
|
+
body: reply.body.subarray(range.start, range.end + 1),
|
|
42
|
+
headers: {
|
|
43
|
+
...base,
|
|
44
|
+
'content-range': `bytes ${range.start}-${range.end}/${size}`,
|
|
45
|
+
'content-length': String(range.end - range.start + 1),
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -4,12 +4,13 @@ import { statSync } from 'node:fs'
|
|
|
4
4
|
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
|
|
5
5
|
import { networkInterfaces } from 'node:os'
|
|
6
6
|
import { pathToFileURL } from 'node:url'
|
|
7
|
-
import { resolve } from 'pathe'
|
|
7
|
+
import { dirname, resolve } from 'pathe'
|
|
8
8
|
import { scanCflowFiles } from 'src/cli/tui/discoverWorkflows.ts'
|
|
9
9
|
import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
|
|
10
10
|
import { draftKeyForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
11
11
|
import { describeVar, renderDescriptorLine } from 'src/cli/serve/describeVar.ts'
|
|
12
12
|
import { ServeApp, type ServeModule } from 'src/cli/serve/ServeApp.ts'
|
|
13
|
+
import { withByteRange } from 'src/cli/serve/byteRange.ts'
|
|
13
14
|
import { renderStartupLines } from 'src/cli/serve/startupPrint.ts'
|
|
14
15
|
import { loadOrBuildWebJs } from 'src/cli/serve/webBundle.ts'
|
|
15
16
|
import { colorsAvailable } from 'src/utils/ansi.ts'
|
|
@@ -82,7 +83,9 @@ export function makeRequestListener(app: ServeApp): (req: IncomingMessage, res:
|
|
|
82
83
|
accept: req.headers.accept,
|
|
83
84
|
body: Buffer.concat(chunks).toString('utf8'),
|
|
84
85
|
})
|
|
85
|
-
.then((
|
|
86
|
+
.then((whole) => {
|
|
87
|
+
const range = req.headers.range
|
|
88
|
+
const reply = withByteRange(whole, { method: req.method ?? 'GET', range })
|
|
86
89
|
res.writeHead(reply.status, { 'content-type': reply.contentType, ...reply.headers, ...cors })
|
|
87
90
|
res.end(reply.body)
|
|
88
91
|
})
|
|
@@ -138,7 +141,13 @@ export async function runServe(args: string[]): Promise<number> {
|
|
|
138
141
|
return 1
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
const app = new ServeApp(modules, {
|
|
144
|
+
const app = new ServeApp(modules, {
|
|
145
|
+
loadErrors,
|
|
146
|
+
webJs: loadOrBuildWebJs,
|
|
147
|
+
// the modules registered comfyts on import: its root holds `.comfy-ts/`
|
|
148
|
+
workspace: typeof comfyts === 'undefined' ? process.cwd() : comfyts.rootPath,
|
|
149
|
+
root: statSync(target).isDirectory() ? target : dirname(target),
|
|
150
|
+
})
|
|
142
151
|
printStartup(app, parsed.bind, parsed.port)
|
|
143
152
|
|
|
144
153
|
const server = createServer(makeRequestListener(app))
|
package/src/cli/serve/web/api.ts
CHANGED
|
@@ -10,10 +10,17 @@ export type ModuleDescription = {
|
|
|
10
10
|
vars: Record<string, VarDescriptor>
|
|
11
11
|
/** names of the workflow's live previews (POST /preview/<module>) */
|
|
12
12
|
previews?: string[]
|
|
13
|
+
/** search tags: what the graph outputs (image, audio, video, text), llm, edit, then free tags */
|
|
14
|
+
tags?: string[]
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
export type PathLabel = { path: string; label: string }
|
|
18
|
+
|
|
15
19
|
export type IndexPayload = {
|
|
16
20
|
workflows: ModuleDescription[]
|
|
21
|
+
/** where `.comfy-ts/` lives, and the folder serve scanned */
|
|
22
|
+
workspace?: PathLabel
|
|
23
|
+
root?: PathLabel
|
|
17
24
|
loadErrors?: Record<string, string>
|
|
18
25
|
}
|
|
19
26
|
|
|
@@ -22,6 +29,9 @@ export type GeneratedImage = { filename: string; url: string | null; absPath: st
|
|
|
22
29
|
/** a STRING output (PreviewAny). An llm graph produces these and no images at all */
|
|
23
30
|
export type GeneratedText = { nodeKey: string | null; text: string }
|
|
24
31
|
|
|
32
|
+
/** an audio file (SaveAudio*, PreviewAudio): the panel plays it in an <audio> player */
|
|
33
|
+
export type GeneratedAudio = { filename: string; mime: string; url: string | null; absPath: string | null }
|
|
34
|
+
|
|
25
35
|
export type GenerateOk = {
|
|
26
36
|
ok: true
|
|
27
37
|
module: string
|
|
@@ -31,6 +41,7 @@ export type GenerateOk = {
|
|
|
31
41
|
seeds: Record<string, number>
|
|
32
42
|
images: GeneratedImage[]
|
|
33
43
|
texts?: GeneratedText[]
|
|
44
|
+
audios?: GeneratedAudio[]
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
async function jsonFetch<T>(url: string, init?: RequestInit): Promise<T> {
|
|
@@ -87,6 +98,19 @@ export function saveDraft(
|
|
|
87
98
|
})
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
/** the open draft tabs: the serve process keeps them, so every window shows the same ones */
|
|
102
|
+
export function fetchTabs(): Promise<{ tabs: unknown }> {
|
|
103
|
+
return jsonFetch('/tabs')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function saveTabs(tabs: readonly { module: string; draft: string }[]): Promise<{ tabs: unknown }> {
|
|
107
|
+
return jsonFetch('/tabs', {
|
|
108
|
+
method: 'PUT',
|
|
109
|
+
headers: { 'content-type': 'application/json' },
|
|
110
|
+
body: JSON.stringify({ tabs }),
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
90
114
|
export function deleteDraft(p: { module: string; draft: string }): Promise<{ ok: true; drafts: string[] }> {
|
|
91
115
|
return jsonFetch(`/drafts/${encodeURIComponent(p.module)}/${encodeURIComponent(p.draft)}`, { method: 'DELETE' })
|
|
92
116
|
}
|