comfy-ts 2.11.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/README.md +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +595 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -46
- package/dist/index.d.ts +286 -46
- package/dist/index.js +591 -74
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
- package/dist/run-tui-B5uxm2_l.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
- package/dist/schemaDrift-E95iTF7E.js.map +1 -0
- package/dist/serve-web.js +710 -174
- package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +286 -46
- package/dist/web.js +591 -74
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
- 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/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +305 -30
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +72 -0
- package/src/cli/serve/web/components/App.tsx +485 -44
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +133 -31
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +58 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +135 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +223 -351
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
- package/src/cli/serve/web/state/FormSt.ts +214 -30
- package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
- package/src/cli/serve/web/state/WebSt.ts +364 -80
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- 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 +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +133 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +103 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +653 -154
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +28 -8
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +21 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/host/loraInfoCache.ts +6 -0
- 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/state.ts +5 -0
- package/src/utils/copyName.ts +12 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +47 -20
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/dist/state--wrz0BQc.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// web ui bundle resolution (architecture item 12, web ui): prebuilt
|
|
2
2
|
// dist/serve-web.js next to the running module, else an in-memory Bun.build
|
|
3
|
-
// from source (src/ ships in the npm tarball),
|
|
4
|
-
// without a UI, never crash
|
|
5
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
3
|
+
// from source (src/ ships in the npm tarball), rebuilt when a source file changes,
|
|
4
|
+
// else null — the api must serve without a UI, never crash
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
6
6
|
import { fileURLToPath } from 'node:url'
|
|
7
7
|
import { dirname, join } from 'pathe'
|
|
8
8
|
|
|
@@ -43,11 +43,42 @@ export async function buildWebJsText(pkgRoot: string): Promise<string> {
|
|
|
43
43
|
return await result.outputs[0].text()
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
46
|
+
/** changes whenever a file under `dir` is added, removed or rewritten. The web bundle reaches
|
|
47
|
+
* outside web/ (vars, protocol types), so the whole src/ tree is the input: ~300 stats, a few ms */
|
|
48
|
+
export function sourceSignature(dir: string): string {
|
|
49
|
+
let count = 0
|
|
50
|
+
let newest = 0
|
|
51
|
+
let bytes = 0
|
|
52
|
+
const walk = (d: string): void => {
|
|
53
|
+
for (const entry of readdirSync(d, { withFileTypes: true })) {
|
|
54
|
+
const abs = join(d, entry.name)
|
|
55
|
+
if (entry.isDirectory()) walk(abs)
|
|
56
|
+
else if (entry.isFile()) {
|
|
57
|
+
const st = statSync(abs)
|
|
58
|
+
count += 1
|
|
59
|
+
bytes += st.size
|
|
60
|
+
newest = Math.max(newest, st.mtimeMs)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
walk(dir)
|
|
65
|
+
return `${count}:${bytes}:${newest}`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let prebuiltJs: string | null = null
|
|
69
|
+
let fromSource: { signature: string; js: Promise<string | null> } | null = null
|
|
70
|
+
|
|
71
|
+
/** the runtime resolution chain; every miss logs loud and degrades to api-only. Called on every
|
|
72
|
+
* page load: a prebuilt file is read once, a source build is redone only when src/ changed, so
|
|
73
|
+
* an edited panel shows on refresh under `bun --watch`, which never sees the bundled files */
|
|
47
74
|
export async function loadOrBuildWebJs(): Promise<string | null> {
|
|
48
75
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
49
76
|
const prebuilt = join(here, 'serve-web.js')
|
|
50
|
-
if (
|
|
77
|
+
if (prebuiltJs != null) return prebuiltJs
|
|
78
|
+
if (existsSync(prebuilt)) {
|
|
79
|
+
prebuiltJs = readFileSync(prebuilt, 'utf8')
|
|
80
|
+
return prebuiltJs
|
|
81
|
+
}
|
|
51
82
|
if (typeof Bun === 'undefined') {
|
|
52
83
|
console.error('[serve] 🔴 no serve-web.js next to the cli and not running under bun — api only, no web ui')
|
|
53
84
|
return null
|
|
@@ -57,10 +88,23 @@ export async function loadOrBuildWebJs(): Promise<string | null> {
|
|
|
57
88
|
console.error(`[serve] 🔴 web ui source not found (looked for ${WEB_ENTRY} above ${here}) — api only, no web ui`)
|
|
58
89
|
return null
|
|
59
90
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
91
|
+
const signature = sourceSignature(join(pkgRoot, 'src'))
|
|
92
|
+
if (fromSource?.signature !== signature) {
|
|
93
|
+
const rebuilt = fromSource != null
|
|
94
|
+
// a failed build stays failed for this signature: logged once, retried on the next edit
|
|
95
|
+
fromSource = {
|
|
96
|
+
signature,
|
|
97
|
+
js: buildWebJsText(pkgRoot).then(
|
|
98
|
+
(js) => {
|
|
99
|
+
if (rebuilt) console.log('[serve] web ui rebuilt from source')
|
|
100
|
+
return js
|
|
101
|
+
},
|
|
102
|
+
(e: unknown) => {
|
|
103
|
+
console.error('[serve] 🔴 web ui bundle failed — api only until the next edit:', e)
|
|
104
|
+
return null
|
|
105
|
+
},
|
|
106
|
+
),
|
|
107
|
+
}
|
|
65
108
|
}
|
|
109
|
+
return await fromSource.js
|
|
66
110
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// search tags of a workflow, read from its built graph. PURE, tests/serve-workflow-tags.test.ts.
|
|
2
|
+
// the graph is the truth: a file named t2a that grew a video output says video
|
|
3
|
+
|
|
4
|
+
/** one node of a built graph, reduced to what tagging reads */
|
|
5
|
+
export type TagNode = {
|
|
6
|
+
id: string
|
|
7
|
+
classType: string
|
|
8
|
+
outputNode: boolean
|
|
9
|
+
/** the node's output slot types, by index */
|
|
10
|
+
outputTypes: readonly string[]
|
|
11
|
+
/** the inputs linked to another node's output: [producer id, output index] */
|
|
12
|
+
links: readonly (readonly [string, number])[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** display order: what the workflow makes first, then how it works, then free tags */
|
|
16
|
+
const MEDIA_BY_TYPE: Record<string, string> = { IMAGE: 'image', AUDIO: 'audio', VIDEO: 'video', STRING: 'text' }
|
|
17
|
+
const MEDIA_ORDER = ['image', 'audio', 'video', 'text']
|
|
18
|
+
|
|
19
|
+
export function workflowTags(p: {
|
|
20
|
+
nodes: readonly TagNode[]
|
|
21
|
+
varKinds: readonly string[]
|
|
22
|
+
extra?: readonly string[]
|
|
23
|
+
}): string[] {
|
|
24
|
+
const byId = new Map(p.nodes.map((n) => [n.id, n]))
|
|
25
|
+
const media = new Set<string>()
|
|
26
|
+
for (const node of p.nodes) {
|
|
27
|
+
if (!node.outputNode) continue
|
|
28
|
+
for (const [producerId, ix] of node.links) {
|
|
29
|
+
const type = byId.get(producerId)?.outputTypes[ix]
|
|
30
|
+
const tag = type == null ? undefined : MEDIA_BY_TYPE[type]
|
|
31
|
+
if (tag != null) media.add(tag)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const out = MEDIA_ORDER.filter((t) => media.has(t))
|
|
35
|
+
if (p.nodes.some((n) => /textgenerate/i.test(n.classType))) out.push('llm')
|
|
36
|
+
if (p.varKinds.includes('image')) out.push('edit')
|
|
37
|
+
for (const tag of p.extra ?? []) {
|
|
38
|
+
const t = tag.trim().toLowerCase()
|
|
39
|
+
if (t !== '' && !out.includes(t)) out.push(t)
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// the menu column's two read-only cards. PURE, tests/serve-workspace-labels.test.ts.
|
|
2
|
+
// the full path is what a click copies; the label is what fits in a 220px card
|
|
3
|
+
|
|
4
|
+
export type PathLabel = { path: string; label: string }
|
|
5
|
+
|
|
6
|
+
function tilde(path: string, home: string): string {
|
|
7
|
+
if (home === '' || home === '/') return path
|
|
8
|
+
if (path === home) return '~'
|
|
9
|
+
return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function workspaceLabels(p: { workspace: string; root: string; home: string }): {
|
|
13
|
+
workspace: PathLabel
|
|
14
|
+
root: PathLabel
|
|
15
|
+
} {
|
|
16
|
+
const ws = p.workspace.replace(/\/+$/, '')
|
|
17
|
+
const root = p.root.replace(/\/+$/, '')
|
|
18
|
+
const rootLabel = root === ws ? '.' : root.startsWith(`${ws}/`) ? root.slice(ws.length + 1) : tilde(root, p.home)
|
|
19
|
+
return {
|
|
20
|
+
workspace: { path: ws, label: tilde(ws, p.home) },
|
|
21
|
+
root: { path: root, label: rootLabel },
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -26,11 +26,18 @@ export const ChoiceOverlay = observer((p: { st: TuiSt }) => {
|
|
|
26
26
|
node: (
|
|
27
27
|
<Text key={opt} inverse={ix === pk.ix}>
|
|
28
28
|
{ix === pk.ix ? '▸ ' : ' '}
|
|
29
|
+
{pk.isPicked(opt) ? '● ' : '○ '}
|
|
29
30
|
{opt}
|
|
30
31
|
</Text>
|
|
31
32
|
),
|
|
32
33
|
}))}
|
|
33
|
-
footer={
|
|
34
|
+
footer={
|
|
35
|
+
options.length === 0 ? (
|
|
36
|
+
<Text color="red">no match</Text>
|
|
37
|
+
) : pk.choiceIsMany ? (
|
|
38
|
+
<Text color="gray">⏎ toggles · esc done</Text>
|
|
39
|
+
) : undefined
|
|
40
|
+
}
|
|
34
41
|
/>
|
|
35
42
|
)
|
|
36
43
|
})
|
|
@@ -41,7 +48,7 @@ export const PresetOverlay = observer((p: { st: TuiSt }) => {
|
|
|
41
48
|
const s = p.st
|
|
42
49
|
const pk = s.picker
|
|
43
50
|
const options = pk.presetOptions
|
|
44
|
-
const current = pk.presetVar?.
|
|
51
|
+
const current = pk.presetVar?.toEditBuffer().trim() ?? ''
|
|
45
52
|
return (
|
|
46
53
|
<OverlayList
|
|
47
54
|
title={
|
|
@@ -12,7 +12,9 @@ import { makeAutoObservable, reaction } from 'mobx'
|
|
|
12
12
|
import { dirname, join } from 'pathe'
|
|
13
13
|
import { moduleName } from 'src/cli/tui/treeRows.ts'
|
|
14
14
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
15
|
+
import { copyName } from 'src/utils/copyName.ts'
|
|
15
16
|
import type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
17
|
+
import { isDraftRecord, preserveDraftMeta } from 'src/cli/draftMeta.ts'
|
|
16
18
|
|
|
17
19
|
/** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */
|
|
18
20
|
export function draftKeyForFile(file: string): string {
|
|
@@ -23,12 +25,15 @@ export function draftsDirForFile(file: string): string {
|
|
|
23
25
|
return comfyts.resolveFromDrafts(draftKeyForFile(file))
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
function listDraftsInDir(dir: string): string[] {
|
|
28
|
+
export function listDraftsInDir(dir: string): string[] {
|
|
27
29
|
if (!existsSync(dir)) return []
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return (
|
|
31
|
+
readdirSync(dir)
|
|
32
|
+
.filter((f) => f.endsWith('.json'))
|
|
33
|
+
.map((f) => f.slice(0, -'.json'.length))
|
|
34
|
+
// numeric: copy counters read 1, 2, 11, never 1, 11, 2
|
|
35
|
+
.sort((a, b) => a.localeCompare(b, 'en', { numeric: true }))
|
|
36
|
+
)
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/** draft names stored for a workflow module (fs read — pair with DraftsSt.version for reactivity) */
|
|
@@ -51,7 +56,7 @@ export class DraftsSt {
|
|
|
51
56
|
(json) => {
|
|
52
57
|
if (json != null && this.active != null) this.write(this.active, json)
|
|
53
58
|
},
|
|
54
|
-
{ delay:
|
|
59
|
+
{ delay: this.st.timing.autosaveMs },
|
|
55
60
|
),
|
|
56
61
|
)
|
|
57
62
|
}
|
|
@@ -73,10 +78,11 @@ export class DraftsSt {
|
|
|
73
78
|
return Object.fromEntries(this.st.entries.map(([k, varDef]) => [k, varDef.toJSON()]))
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
// the TUI knows only the var values: what the panel stored beside them ($enhance) stays
|
|
76
82
|
private write(name: string, json: string): void {
|
|
77
83
|
const path = join(this.dir, `${name}.json`)
|
|
78
84
|
mkdirSync(dirname(path), { recursive: true })
|
|
79
|
-
writeFileSync(path, json)
|
|
85
|
+
writeFileSync(path, keepDraftMeta(path, json))
|
|
80
86
|
this.version++
|
|
81
87
|
}
|
|
82
88
|
|
|
@@ -229,7 +235,7 @@ export class DraftsSt {
|
|
|
229
235
|
promptDuplicate(name: string, file?: string, returnMode: TuiMode = 'nav'): void {
|
|
230
236
|
this.st.editor.beginCustom({
|
|
231
237
|
title: `duplicate draft '${name}'`,
|
|
232
|
-
initial:
|
|
238
|
+
initial: copyName(name, listDraftsInDir(this.dirFor(file))),
|
|
233
239
|
onCommit: (raw) => {
|
|
234
240
|
const ok = this.duplicate(name, raw, file)
|
|
235
241
|
if (ok && returnMode === 'overlay-drafts') this.begin()
|
|
@@ -271,3 +277,17 @@ export class DraftsSt {
|
|
|
271
277
|
this.st.mode = 'nav'
|
|
272
278
|
}
|
|
273
279
|
}
|
|
280
|
+
|
|
281
|
+
/** the new json, plus the `$` keys the file on disk already carried (src/cli/draftMeta.ts) */
|
|
282
|
+
function keepDraftMeta(path: string, json: string): string {
|
|
283
|
+
if (!existsSync(path)) return json
|
|
284
|
+
let previous: unknown
|
|
285
|
+
try {
|
|
286
|
+
previous = JSON.parse(readFileSync(path, 'utf8'))
|
|
287
|
+
} catch {
|
|
288
|
+
return json
|
|
289
|
+
}
|
|
290
|
+
const next: unknown = JSON.parse(json)
|
|
291
|
+
if (!isDraftRecord(previous) || !isDraftRecord(next)) return json
|
|
292
|
+
return JSON.stringify(preserveDraftMeta(previous, next), null, 2)
|
|
293
|
+
}
|
|
@@ -63,7 +63,7 @@ export class EditorSt {
|
|
|
63
63
|
const sel = this.st.selected?.[1]
|
|
64
64
|
if (sel == null) return
|
|
65
65
|
this.st.mode = 'overlay-text'
|
|
66
|
-
this.buffer =
|
|
66
|
+
this.buffer = sel.toEditBuffer()
|
|
67
67
|
this.cursor = [...this.buffer].length
|
|
68
68
|
this.invalid = false
|
|
69
69
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeAutoObservable } from 'mobx'
|
|
2
2
|
import { fuzzyMatch } from 'src/utils/fuzzyMatch.ts'
|
|
3
|
-
import type {
|
|
3
|
+
import type { AnyChoiceVar, PromptVar, SizeVar, TextVar } from 'src/vars/ComfyVars.ts'
|
|
4
4
|
import type { VarPreset } from 'src/vars/presets.ts'
|
|
5
5
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
6
6
|
|
|
@@ -25,9 +25,21 @@ export class PickerSt {
|
|
|
25
25
|
imageSizeRow: string | null = null
|
|
26
26
|
|
|
27
27
|
// kind-narrowing casts sanctioned (agent/coding.md), `kind` is the tag
|
|
28
|
-
private get choiceVar():
|
|
28
|
+
private get choiceVar(): AnyChoiceVar<string> | null {
|
|
29
29
|
const sel = this.st.selected?.[1]
|
|
30
|
-
return sel?.kind === 'choice' ? (sel as
|
|
30
|
+
return sel?.kind === 'choice' ? (sel as AnyChoiceVar<string>) : null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** is this option currently picked (one, one or none, or one of many) */
|
|
34
|
+
isPicked(option: string): boolean {
|
|
35
|
+
const cv = this.choiceVar
|
|
36
|
+
if (cv == null) return false
|
|
37
|
+
return cv.select === 'many' ? cv.value.includes(option) : cv.value === option
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** a many-choice stays open after ⏎: you toggle several, esc leaves */
|
|
41
|
+
get choiceIsMany(): boolean {
|
|
42
|
+
return this.choiceVar?.select === 'many'
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
private get sizeVar(): SizeVar | null {
|
|
@@ -76,7 +88,8 @@ export class PickerSt {
|
|
|
76
88
|
this.st.mode = 'overlay-choice'
|
|
77
89
|
this.filter = ''
|
|
78
90
|
this.invalid = false
|
|
79
|
-
|
|
91
|
+
const first = cv.select === 'many' ? cv.value[0] : cv.value
|
|
92
|
+
this.ix = Math.max(0, first == null ? 0 : cv.choices.indexOf(first))
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
/** `P` on a text/prompt var that declares presets. A var without any stays on `nav`:
|
|
@@ -87,7 +100,7 @@ export class PickerSt {
|
|
|
87
100
|
this.st.mode = 'overlay-preset'
|
|
88
101
|
this.filter = ''
|
|
89
102
|
this.invalid = false
|
|
90
|
-
const value = pv.
|
|
103
|
+
const value = pv.toEditBuffer().trim()
|
|
91
104
|
const ix = pv.presets.findIndex((x) => x.text.trim() === value)
|
|
92
105
|
this.ix = ix === -1 ? 0 : ix
|
|
93
106
|
}
|
|
@@ -142,9 +155,14 @@ export class PickerSt {
|
|
|
142
155
|
}
|
|
143
156
|
const cv = this.choiceVar
|
|
144
157
|
if (cv != null) {
|
|
145
|
-
const hit = this.options[this.ix]
|
|
158
|
+
const hit = cv.choices.find((c) => c === this.options[this.ix])
|
|
146
159
|
if (hit == null) return
|
|
147
|
-
cv.
|
|
160
|
+
if (cv.select === 'many') {
|
|
161
|
+
cv.toggle(hit)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
if (cv.select === 'zero-or-one') cv.toggle(hit)
|
|
165
|
+
else cv.set(hit)
|
|
148
166
|
this.st.mode = 'nav'
|
|
149
167
|
return
|
|
150
168
|
}
|
|
@@ -41,6 +41,9 @@ export type TuiMode =
|
|
|
41
41
|
* ROOT of the TUI state tree (one instance per run). Children are service
|
|
42
42
|
* classes with an `st` backref; components are stateless views over this.
|
|
43
43
|
*/
|
|
44
|
+
export type TuiTiming = { previewMs: number; autosaveMs: number }
|
|
45
|
+
export const TUI_TIMING: TuiTiming = { previewMs: 120, autosaveMs: 300 }
|
|
46
|
+
|
|
44
47
|
export class TuiSt {
|
|
45
48
|
wf: DefinedWorkflow
|
|
46
49
|
mode: TuiMode = 'nav'
|
|
@@ -86,6 +89,9 @@ export class TuiSt {
|
|
|
86
89
|
logs: LogsSt
|
|
87
90
|
settings: SettingsSt
|
|
88
91
|
|
|
92
|
+
/** the debounces the sub-stores run on */
|
|
93
|
+
readonly timing: TuiTiming
|
|
94
|
+
|
|
89
95
|
/** owned cleanups (reactions, listeners) — flushed by dispose() */
|
|
90
96
|
disposers: (() => void)[] = []
|
|
91
97
|
onExit: () => void = () => {}
|
|
@@ -99,15 +105,19 @@ export class TuiSt {
|
|
|
99
105
|
bundledFiles?: Set<string>
|
|
100
106
|
/** modules that failed to load before mount (red rows in the tree) */
|
|
101
107
|
loadErrors?: Map<string, string>
|
|
108
|
+
/** tests set these to a few ms rather than wait them out */
|
|
109
|
+
timing?: TuiTiming
|
|
102
110
|
} = {},
|
|
103
111
|
) {
|
|
104
112
|
this.wf = wf
|
|
113
|
+
this.timing = opts.timing ?? TUI_TIMING
|
|
105
114
|
// wf: observableRef so switching workflows re-renders without proxying
|
|
106
115
|
// the foreign object; children manage their own observability
|
|
107
116
|
makeAutoObservable(this, {
|
|
108
117
|
wf: observableRef,
|
|
109
118
|
hostOverride: observableRef,
|
|
110
119
|
onExit: false,
|
|
120
|
+
timing: false,
|
|
111
121
|
editor: false,
|
|
112
122
|
picker: false,
|
|
113
123
|
loras: false,
|
package/src/coreExports.ts
CHANGED
|
@@ -35,6 +35,7 @@ export {
|
|
|
35
35
|
} from 'src/runner/ComfyWorkflow.ts'
|
|
36
36
|
export {
|
|
37
37
|
ComfyExecution,
|
|
38
|
+
type ComfyAudioOutput,
|
|
38
39
|
type ComfyExecutionData,
|
|
39
40
|
type ComfyTextOutput,
|
|
40
41
|
type ExecutionProgress,
|
|
@@ -85,11 +86,16 @@ export {
|
|
|
85
86
|
SeedVar,
|
|
86
87
|
ToggleVar,
|
|
87
88
|
ChoiceVar,
|
|
89
|
+
OptionalChoiceVar,
|
|
90
|
+
MultiChoiceVar,
|
|
88
91
|
LorasVar,
|
|
89
92
|
SizeVar,
|
|
90
93
|
ImageVar,
|
|
91
94
|
ImageVarEmptyError,
|
|
92
95
|
DEFAULT_SIZE_PRESETS,
|
|
96
|
+
SD15_SIZE_PRESETS,
|
|
97
|
+
DEFAULT_STARRED_SIZES,
|
|
98
|
+
sizePresetsFor,
|
|
93
99
|
DEFAULT_IMAGE_EXTENSIONS,
|
|
94
100
|
activeLoras,
|
|
95
101
|
} from 'src/vars/ComfyVars.ts'
|
|
@@ -97,6 +103,9 @@ export type {
|
|
|
97
103
|
AnyVar,
|
|
98
104
|
VarKind,
|
|
99
105
|
VarsSpec,
|
|
106
|
+
VarUi,
|
|
107
|
+
AnyChoiceVar,
|
|
108
|
+
ChoiceSelect,
|
|
100
109
|
VarValues,
|
|
101
110
|
PromptValue,
|
|
102
111
|
ActiveLoraSource,
|
|
@@ -107,8 +116,20 @@ export type {
|
|
|
107
116
|
SizePreset,
|
|
108
117
|
ImageVarOpts,
|
|
109
118
|
TextVarOpts,
|
|
119
|
+
PromptVarOpts,
|
|
120
|
+
PromptTagsOpts,
|
|
110
121
|
} from 'src/vars/ComfyVars.ts'
|
|
111
122
|
export { toPresetList, activePresetLabel, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
|
|
123
|
+
export type {
|
|
124
|
+
PromptInput,
|
|
125
|
+
PromptLane,
|
|
126
|
+
PromptLanes,
|
|
127
|
+
LorasInput,
|
|
128
|
+
LoraLane,
|
|
129
|
+
LoraLanes,
|
|
130
|
+
LoraRecord,
|
|
131
|
+
} from 'src/vars/lanes.ts'
|
|
132
|
+
export type { LoraEntry } from 'src/vars/loraEntry.ts'
|
|
112
133
|
export { DefinedWorkflow, type DefineWorkflowSpec, type BoundVars, type LoraNameOf } from 'src/vars/DefinedWorkflow.ts'
|
|
113
134
|
export {
|
|
114
135
|
clearLoraKeywordOverride,
|
package/src/host/ComfyHost.ts
CHANGED
|
@@ -628,9 +628,24 @@ export class ComfyHost<ID extends string = string> {
|
|
|
628
628
|
return this.postJSON_('/queue', { clear: true })
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
-
/** interrupt the
|
|
631
|
+
/** a repeat interrupt for the same running prompt inside this window reuses the first request */
|
|
632
|
+
interruptCoalesceMs = 3000
|
|
633
|
+
private _lastInterrupt: { promptID: PromptID | null; at: number; req: Promise<void> } | null = null
|
|
634
|
+
|
|
635
|
+
/** interrupt the CURRENTLY RUNNING prompt. A burst of /interrupt posts can make the ComfyUI
|
|
636
|
+
* python process quit, so repeats for the same prompt are coalesced into one request */
|
|
632
637
|
interrupt = (): Promise<void> => {
|
|
633
|
-
|
|
638
|
+
const now = Date.now()
|
|
639
|
+
const last = this._lastInterrupt
|
|
640
|
+
if (last != null && last.promptID === this.activePromptID && now - last.at < this.interruptCoalesceMs)
|
|
641
|
+
return last.req
|
|
642
|
+
const req = this.postJSON_('/interrupt', {})
|
|
643
|
+
this._lastInterrupt = { promptID: this.activePromptID, at: now, req }
|
|
644
|
+
// a failed request must not swallow the retry
|
|
645
|
+
req.catch(() => {
|
|
646
|
+
if (this._lastInterrupt?.req === req) this._lastInterrupt = null
|
|
647
|
+
})
|
|
648
|
+
return req
|
|
634
649
|
}
|
|
635
650
|
|
|
636
651
|
// HISTORY SCRUB (architecture.md item 14) -------------------------------------------
|
|
@@ -17,6 +17,10 @@ export type WsLike = {
|
|
|
17
17
|
onerror: ((event: unknown) => void) | null
|
|
18
18
|
send(data: Message): void
|
|
19
19
|
close(): void
|
|
20
|
+
/** the `ws` package only (a browser answers pings by itself and exposes none of these) */
|
|
21
|
+
ping?(): void
|
|
22
|
+
on?(event: 'pong', cb: () => void): void
|
|
23
|
+
terminate?(): void
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/** what both transports deliver with binaryType 'arraybuffer': string or ArrayBuffer in `data` */
|
|
@@ -25,7 +29,7 @@ export type WsCloseEvent = { code: number; reason: string }
|
|
|
25
29
|
|
|
26
30
|
type WsCtor = new (url: string, opts?: { headers?: Record<string, string> }) => WsLike
|
|
27
31
|
|
|
28
|
-
type WsTransport = { ctor: WsCtor; supportsHeaders: boolean }
|
|
32
|
+
export type WsTransport = { ctor: WsCtor; supportsHeaders: boolean }
|
|
29
33
|
|
|
30
34
|
let transportPromise: Promise<WsTransport> | null = null
|
|
31
35
|
|
|
@@ -92,6 +96,14 @@ export class ResilientWebSocketClient {
|
|
|
92
96
|
* waiter sit for the full connect deadline. No callback = retry as before.
|
|
93
97
|
*/
|
|
94
98
|
onFirstConnectFailed?: (error: unknown) => void
|
|
99
|
+
/** tests only: a fake socket instead of the ws package / browser WebSocket */
|
|
100
|
+
transport?: WsTransport
|
|
101
|
+
/** a host that vanishes (power loss, hard reboot) never sends a close frame, so the
|
|
102
|
+
* socket would look open forever: every `heartbeatMs` it is pinged, and one without a
|
|
103
|
+
* pong since the last ping is dropped, which starts the reconnect. Default 15s */
|
|
104
|
+
heartbeatMs?: number
|
|
105
|
+
/** pause before a reconnect. Default 2s */
|
|
106
|
+
reconnectMs?: number
|
|
95
107
|
},
|
|
96
108
|
) {
|
|
97
109
|
this.url = options.url()
|
|
@@ -102,12 +114,46 @@ export class ResilientWebSocketClient {
|
|
|
102
114
|
private hasEverOpened: boolean = false
|
|
103
115
|
|
|
104
116
|
private reconnectTimeout?: Maybe<ReturnType<typeof setTimeout>>
|
|
117
|
+
private heartbeat: ReturnType<typeof setInterval> | null = null
|
|
105
118
|
private permanentlyClosed: boolean = false
|
|
106
119
|
|
|
120
|
+
private stopHeartbeat(): void {
|
|
121
|
+
if (this.heartbeat != null) clearInterval(this.heartbeat)
|
|
122
|
+
this.heartbeat = null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** ping on a timer; no pong since the previous ping = the peer is gone, drop the socket */
|
|
126
|
+
private startHeartbeat(ws: WsLike): void {
|
|
127
|
+
this.stopHeartbeat()
|
|
128
|
+
if (typeof ws.ping !== 'function' || typeof ws.on !== 'function') return
|
|
129
|
+
let awaitingPong = false
|
|
130
|
+
ws.on('pong', () => {
|
|
131
|
+
awaitingPong = false
|
|
132
|
+
})
|
|
133
|
+
const ms = this.options.heartbeatMs ?? 15_000
|
|
134
|
+
this.heartbeat = setInterval(() => {
|
|
135
|
+
if (ws !== this.currentWS) return this.stopHeartbeat()
|
|
136
|
+
if (awaitingPong) {
|
|
137
|
+
this.addError(`no pong within ${ms}ms: the host is gone, dropping the socket to reconnect`)
|
|
138
|
+
this.stopHeartbeat()
|
|
139
|
+
if (typeof ws.terminate === 'function') ws.terminate()
|
|
140
|
+
else ws.close()
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
awaitingPong = true
|
|
144
|
+
try {
|
|
145
|
+
ws.ping?.()
|
|
146
|
+
} catch (e) {
|
|
147
|
+
this.addError(`ping failed: ${extractErrorMessage(e)}`)
|
|
148
|
+
}
|
|
149
|
+
}, ms)
|
|
150
|
+
}
|
|
151
|
+
|
|
107
152
|
/** close and stop reconnecting (lets a script exit cleanly) */
|
|
108
153
|
disconnectPermanently(): void {
|
|
109
154
|
this.permanentlyClosed = true
|
|
110
155
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout)
|
|
156
|
+
this.stopHeartbeat()
|
|
111
157
|
this.currentWS?.close()
|
|
112
158
|
this.currentWS = null
|
|
113
159
|
this.isOpen = false
|
|
@@ -133,6 +179,7 @@ export class ResilientWebSocketClient {
|
|
|
133
179
|
|
|
134
180
|
// cleanup a possible re-connection timeout for an other url
|
|
135
181
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout)
|
|
182
|
+
this.stopHeartbeat()
|
|
136
183
|
|
|
137
184
|
this.currentWS = null
|
|
138
185
|
if (prevWS) {
|
|
@@ -142,7 +189,7 @@ export class ResilientWebSocketClient {
|
|
|
142
189
|
|
|
143
190
|
let ws: WsLike
|
|
144
191
|
try {
|
|
145
|
-
const transport = await resolveWsTransport()
|
|
192
|
+
const transport = this.options.transport ?? (await resolveWsTransport())
|
|
146
193
|
if (this.permanentlyClosed) return // closed while the transport resolved
|
|
147
194
|
const headers = this.options.headers?.() ?? {}
|
|
148
195
|
ws = transport.supportsHeaders
|
|
@@ -171,11 +218,13 @@ export class ResilientWebSocketClient {
|
|
|
171
218
|
this.isOpen = true
|
|
172
219
|
this.options.onConnectOrReconnect()
|
|
173
220
|
this.flushMessageBuffer()
|
|
221
|
+
this.startHeartbeat(ws)
|
|
174
222
|
}
|
|
175
223
|
|
|
176
224
|
ws.onclose = (event: WsCloseEvent): void => {
|
|
177
225
|
if (ws !== this.currentWS) return
|
|
178
226
|
this.isOpen = false
|
|
227
|
+
this.stopHeartbeat()
|
|
179
228
|
this.options.onClose()
|
|
180
229
|
if (this.permanentlyClosed) return
|
|
181
230
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`)
|
|
@@ -187,8 +236,9 @@ export class ResilientWebSocketClient {
|
|
|
187
236
|
)
|
|
188
237
|
return
|
|
189
238
|
}
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
239
|
+
const wait = this.options.reconnectMs ?? 2000
|
|
240
|
+
this.addInfo(`⏱️ reconnecting in ${wait / 1000} seconds...`)
|
|
241
|
+
this.reconnectTimeout = setTimeout(() => void this.connect(), wait)
|
|
192
242
|
}
|
|
193
243
|
|
|
194
244
|
ws.onerror = (event: unknown): void => {
|
|
@@ -333,3 +333,9 @@ export function loraMatchesFilter(name: string, filter: string, hostId?: string)
|
|
|
333
333
|
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase())
|
|
334
334
|
return tokens.every((token) => fields.some((field) => field.includes(token)))
|
|
335
335
|
}
|
|
336
|
+
|
|
337
|
+
/** the loras a host lists that the local copy of its lora manager list does not know yet:
|
|
338
|
+
* downloaded after the last sync, so they have no name, preview or trigger words here */
|
|
339
|
+
export function lorasMissingFromMirror(hostLoras: readonly string[], inMirror: (name: string) => boolean): string[] {
|
|
340
|
+
return hostLoras.filter((n) => !inMirror(n))
|
|
341
|
+
}
|