comfy-ts 2.6.0 → 2.8.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 +22 -13
- package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
- package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
- package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
- package/dist/LogsSt-DFxzQfDc.js.map +1 -0
- package/dist/cli.js +8 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +288 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -7
- package/dist/index.d.ts +128 -7
- package/dist/index.js +286 -37
- package/dist/index.js.map +1 -1
- package/dist/run-serve-_nrvJYyt.js +1948 -0
- package/dist/run-serve-_nrvJYyt.js.map +1 -0
- package/dist/{run-tui-idFhdO4f.js → run-tui-BPw-SZYW.js} +107 -158
- package/dist/run-tui-BPw-SZYW.js.map +1 -0
- package/dist/serve-web.js +434 -81
- package/dist/{state-C90kdjtB.js → state-B-boDz-Z.js} +184 -45
- package/dist/state-B-boDz-Z.js.map +1 -0
- package/dist/web.d.ts +112 -7
- package/dist/web.js +239 -36
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/sdk.d.ts +4066 -321
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
- package/examples/web/tsconfig.json +7 -1
- package/extra/README.md +32 -0
- package/extra/comfyui-textgen-stream/README.md +35 -0
- package/extra/comfyui-textgen-stream/__init__.py +166 -0
- package/extra/scripts/fetch_text_encoder.py +137 -0
- package/package.json +6 -3
- package/src/cli/comfy-ts-cli.ts +4 -2
- package/src/cli/serve/ServeApp.ts +825 -43
- package/src/cli/serve/applyVarPayload.ts +10 -3
- package/src/cli/serve/describeVar.ts +47 -7
- package/src/cli/serve/managerOnlyLoras.ts +27 -0
- package/src/cli/serve/run-serve.ts +58 -29
- package/src/cli/serve/serveSettings.ts +86 -0
- package/src/cli/serve/startupPrint.ts +111 -0
- package/src/cli/serve/web/api.ts +120 -1
- package/src/cli/serve/web/components/App.tsx +61 -22
- package/src/cli/serve/web/components/Gallery.tsx +243 -30
- package/src/cli/serve/web/components/Icon.tsx +160 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +85 -38
- package/src/cli/serve/web/components/Sidebar.tsx +43 -19
- package/src/cli/serve/web/components/VarsForm.tsx +440 -80
- package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
- package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
- package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
- package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
- package/src/cli/serve/web/llm.ts +254 -0
- package/src/cli/serve/web/logWeb.ts +6 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +261 -157
- package/src/cli/serve/web/state/FormSt.ts +70 -18
- package/src/cli/serve/web/state/RunSt.ts +22 -1
- package/src/cli/serve/web/state/WebSt.ts +542 -13
- package/src/cli/serve/web/state/lightbox.ts +44 -0
- package/src/cli/serve/web/state/moduleTree.ts +52 -0
- package/src/cli/serve/web/state/payload.ts +44 -2
- package/src/cli/serve/web/state/urlSelection.ts +53 -0
- package/src/cli/serve/web/styles.ts +415 -57
- package/src/cli/serve/web/tsconfig.json +4 -0
- package/src/cli/tui/components/PickerOverlays.tsx +37 -0
- package/src/cli/tui/components/StatusBar.tsx +14 -1
- package/src/cli/tui/components/TuiApp.tsx +5 -2
- package/src/cli/tui/state/HostSt.ts +3 -2
- package/src/cli/tui/state/PickerSt.ts +48 -2
- package/src/cli/tui/state/TreeSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +2 -1
- package/src/coreExports.ts +8 -1
- package/src/graph/ComfyNode.ts +58 -1
- package/src/host/ComfyHost.ts +13 -2
- package/src/host/ComfyManager.ts +31 -13
- package/src/host/loraInfoCache.ts +35 -1
- package/src/host/loraManagerApi.ts +94 -0
- package/src/index.ts +2 -0
- package/src/promptEnhancers.ts +102 -0
- package/src/runner/ComfyExecution.ts +61 -6
- package/src/runner/ComfyWorkflow.ts +18 -4
- package/src/runner/ComfyWsApi.ts +3 -0
- package/src/runner/describePromptRejection.ts +34 -0
- package/src/sdk-generator/ComfySchema.ts +17 -4
- package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
- package/src/state.ts +6 -0
- package/src/utils/ansi.ts +13 -0
- package/src/utils/matchesRegex.ts +13 -0
- package/src/utils/safeName.ts +29 -0
- package/src/utils/stringMap.ts +9 -0
- package/src/vars/ComfyVars.ts +61 -10
- package/src/vars/presets.ts +17 -0
- package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
- package/dist/DraftsSt-dizp3VcC.js.map +0 -1
- package/dist/run-serve-CVu39RNd.js +0 -1002
- package/dist/run-serve-CVu39RNd.js.map +0 -1
- package/dist/run-tui-idFhdO4f.js.map +0 -1
- package/dist/state-C90kdjtB.js.map +0 -1
- package/src/cli/serve/web/openrouter.ts +0 -142
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// what the lightbox SHOWS, derived rather than captured. PURE and DOM-free on purpose:
|
|
2
|
+
// headless-tested by tests/serve-web-lightbox.test.ts.
|
|
3
|
+
import { runPreviewSrc } from 'src/cli/serve/web/api.ts'
|
|
4
|
+
|
|
5
|
+
/** an IMAGE target is a fixed file. A LATENT target names the running MODULE instead of a url,
|
|
6
|
+
* because the url carries the frame tick: capturing it froze the lightbox on the frame you
|
|
7
|
+
* happened to click, through every later frame and past the end of the run */
|
|
8
|
+
export type LightboxTarget =
|
|
9
|
+
| { kind: 'image'; url: string; title: string; promptId: string | null }
|
|
10
|
+
/** `after` is how many results that module already had when the latent was opened: the run
|
|
11
|
+
* being watched is the one that ADDS to it. Without it, a run that fails promotes the
|
|
12
|
+
* lightbox to the PREVIOUS run's image, as if the one you watched had produced it */
|
|
13
|
+
| { kind: 'latent'; module: string; after: number }
|
|
14
|
+
|
|
15
|
+
export type LightboxRun = {
|
|
16
|
+
module: string
|
|
17
|
+
promptId: string
|
|
18
|
+
images: { url: string | null; filename: string }[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type LightboxView = { url: string; title: string; promptId: string | null }
|
|
22
|
+
|
|
23
|
+
/** a latent target follows the live frame, and the moment the run ends it promotes itself to
|
|
24
|
+
* the image that run produced, watching a latent become the picture is the point of opening
|
|
25
|
+
* it big, so stopping at the last frame loses exactly what you opened it for */
|
|
26
|
+
export function lightboxView(p: {
|
|
27
|
+
target: LightboxTarget
|
|
28
|
+
isRunning: boolean
|
|
29
|
+
previewTick: number
|
|
30
|
+
/** newest first */
|
|
31
|
+
results: readonly LightboxRun[]
|
|
32
|
+
}): LightboxView {
|
|
33
|
+
if (p.target.kind === 'image') return { url: p.target.url, title: p.target.title, promptId: p.target.promptId }
|
|
34
|
+
const module = p.target.module
|
|
35
|
+
const done = p.results.filter((r) => r.module === module)
|
|
36
|
+
// only a NEW result counts as "the run you were watching finished"
|
|
37
|
+
const finished = done.length > p.target.after ? done[0] : undefined
|
|
38
|
+
// an image with no url is one this run could not serve: stay on the latent rather than
|
|
39
|
+
// blank the lightbox at the very moment the run pays off
|
|
40
|
+
const image = finished?.images.find((i) => i.url != null)
|
|
41
|
+
if (!p.isRunning && image?.url != null)
|
|
42
|
+
return { url: image.url, title: image.filename, promptId: finished?.promptId ?? null }
|
|
43
|
+
return { url: runPreviewSrc({ module, tick: p.previewTick }), title: 'latent preview', promptId: null }
|
|
44
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// the sidebar is a TREE, not a list: modules keep the folder they came from.
|
|
2
|
+
// PURE and DOM-free (browser side, so no node:path), tests/serve-web-tree.test.ts.
|
|
3
|
+
// the module KEY stays the basename (it is the api identity); this only decides
|
|
4
|
+
// what the sidebar shows above it.
|
|
5
|
+
|
|
6
|
+
export type TreeItem = { module: string; file: string }
|
|
7
|
+
|
|
8
|
+
export type ModuleGroup<T extends TreeItem> = { folder: string; modules: T[] }
|
|
9
|
+
|
|
10
|
+
function segmentsOf(path: string): string[] {
|
|
11
|
+
return path.split(/[/\\]/).filter((s) => s !== '')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function dirSegments(file: string): string[] {
|
|
15
|
+
return segmentsOf(file).slice(0, -1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** longest shared leading path of every module, as segments */
|
|
19
|
+
function commonPrefix(dirs: string[][]): string[] {
|
|
20
|
+
const first = dirs[0]
|
|
21
|
+
if (first == null) return []
|
|
22
|
+
const out: string[] = []
|
|
23
|
+
for (let i = 0; i < first.length; i++) {
|
|
24
|
+
const seg = first[i]
|
|
25
|
+
if (seg == null || !dirs.every((d) => d[i] === seg)) break
|
|
26
|
+
out.push(seg)
|
|
27
|
+
}
|
|
28
|
+
return out
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* group by folder, labelled from ONE level above the shared root, so serving a single
|
|
33
|
+
* folder still says `rvion` instead of showing a flat list with the prefix eaten. Groups
|
|
34
|
+
* and modules stay in a stable alphabetical order, drafts keep the server's order.
|
|
35
|
+
*/
|
|
36
|
+
export function groupModulesByFolder<T extends TreeItem>(modules: readonly T[]): ModuleGroup<T>[] {
|
|
37
|
+
if (modules.length === 0) return []
|
|
38
|
+
const dirs = modules.map((m) => dirSegments(m.file))
|
|
39
|
+
// one level up from the shared root: that last segment is the label worth seeing
|
|
40
|
+
const shared = commonPrefix(dirs)
|
|
41
|
+
const cut = Math.max(0, shared.length - 1)
|
|
42
|
+
const groups = new Map<string, T[]>()
|
|
43
|
+
for (const [i, mod] of modules.entries()) {
|
|
44
|
+
const folder = (dirs[i] ?? []).slice(cut).join('/')
|
|
45
|
+
const list = groups.get(folder)
|
|
46
|
+
if (list == null) groups.set(folder, [mod])
|
|
47
|
+
else list.push(mod)
|
|
48
|
+
}
|
|
49
|
+
return [...groups.entries()]
|
|
50
|
+
.map(([folder, list]) => ({ folder, modules: [...list].sort((a, b) => a.module.localeCompare(b.module)) }))
|
|
51
|
+
.sort((a, b) => a.folder.localeCompare(b.folder))
|
|
52
|
+
}
|
|
@@ -40,7 +40,7 @@ export function asSizeForm(raw: unknown): SizeFormValue {
|
|
|
40
40
|
|
|
41
41
|
/** the record the web keeps holds ON loras ONLY, so it always reads as "what is in the
|
|
42
42
|
* palette". Two things are dropped: keys the host no longer offers (dead weight the ui
|
|
43
|
-
* cannot display, and a server-side build failure), and `false` entries
|
|
43
|
+
* cannot display, and a server-side build failure), and `false` entries, LorasVar writes
|
|
44
44
|
* one for every lora ever unticked, so treating them as palette members put the WHOLE
|
|
45
45
|
* catalog in the row. Off is off: `activeLoras` skips both spellings, so nothing changes
|
|
46
46
|
* in the graph, and with live drafts the next autosave heals the file */
|
|
@@ -92,7 +92,11 @@ export function setLoraEnabled(
|
|
|
92
92
|
prev?: LoraStrengthPair,
|
|
93
93
|
): Record<string, unknown> {
|
|
94
94
|
const next = { ...record }
|
|
95
|
-
|
|
95
|
+
// PAUSE KEEPS THE KEY (as `false`): deleting it dropped the lora out of the record's
|
|
96
|
+
// insertion order, so pausing a card sent it to the end of the row. `false` is the same
|
|
97
|
+
// "selected but off" spelling LorasVar uses, every reader ignores it, and normalizeInitial
|
|
98
|
+
// prunes it on load, so nothing accumulates in the draft file
|
|
99
|
+
if (!on) next[name] = false
|
|
96
100
|
else {
|
|
97
101
|
const pair = prev ?? loraStrengthPair(record[name])
|
|
98
102
|
next[name] = [pair.model, pair.clip]
|
|
@@ -100,6 +104,44 @@ export function setLoraEnabled(
|
|
|
100
104
|
return next
|
|
101
105
|
}
|
|
102
106
|
|
|
107
|
+
/**
|
|
108
|
+
* the palette, IN ORDER: the record's own key order (newest last on disk, shown newest FIRST),
|
|
109
|
+
* plus loras paused in this session that already left the record. Pure, because the order is
|
|
110
|
+
* the thing a drag rewrites and a pause must not touch.
|
|
111
|
+
*/
|
|
112
|
+
export function paletteOrder(p: {
|
|
113
|
+
record: Record<string, unknown>
|
|
114
|
+
options: readonly string[]
|
|
115
|
+
/** paused in this session — kept in the palette even when the record no longer lists them */
|
|
116
|
+
paused: ReadonlySet<string>
|
|
117
|
+
}): string[] {
|
|
118
|
+
const known = new Set(p.options)
|
|
119
|
+
const inRecord = Object.keys(p.record).filter((n) => known.has(n) && (loraIsOn(p.record[n]) || p.paused.has(n)))
|
|
120
|
+
const pausedOnly = [...p.paused].filter((n) => known.has(n) && !inRecord.includes(n))
|
|
121
|
+
return [...inRecord, ...pausedOnly].reverse()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** move a lora to a new slot in the PALETTE (what the row shows, newest first) and give back the
|
|
125
|
+
* record rewritten in that order, the record's key order IS the stored order */
|
|
126
|
+
export function reorderLoras(p: {
|
|
127
|
+
record: Record<string, unknown>
|
|
128
|
+
/** palette order, as displayed */
|
|
129
|
+
displayed: readonly string[]
|
|
130
|
+
from: number
|
|
131
|
+
to: number
|
|
132
|
+
}): Record<string, unknown> {
|
|
133
|
+
const next = [...p.displayed]
|
|
134
|
+
const [moved] = next.splice(p.from, 1)
|
|
135
|
+
if (moved == null) return p.record
|
|
136
|
+
next.splice(p.to, 0, moved)
|
|
137
|
+
const out: Record<string, unknown> = {}
|
|
138
|
+
// displayed is newest-first; the record stores the opposite, so it is written back reversed
|
|
139
|
+
for (const name of [...next].reverse()) if (name in p.record) out[name] = p.record[name]
|
|
140
|
+
// anything the palette does not show (a key pruned from view) keeps its entry
|
|
141
|
+
for (const [k, v] of Object.entries(p.record)) if (!(k in out)) out[k] = v
|
|
142
|
+
return out
|
|
143
|
+
}
|
|
144
|
+
|
|
103
145
|
/** set both strengths; an OFF lora stays off (its strength is edited on re-enable) */
|
|
104
146
|
export function setLoraStrength(
|
|
105
147
|
record: Record<string, unknown>,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// the selection lives in the URL, so a panel you are looking at can be SENT to someone and
|
|
2
|
+
// they land on the same workflow and draft. PURE and DOM-free: headless-tested by
|
|
3
|
+
// tests/serve-web-url-selection.test.ts, the browser side is two calls in WebSt.
|
|
4
|
+
|
|
5
|
+
export type UrlSelection = { module: string | null; draft: string | null }
|
|
6
|
+
|
|
7
|
+
const MODULE_PARAM = 'workflow'
|
|
8
|
+
const DRAFT_PARAM = 'draft'
|
|
9
|
+
|
|
10
|
+
/** what a url asks for. Never throws: a hand-edited or truncated query is simply "nothing
|
|
11
|
+
* asked", because a bad link must open the panel, not break it */
|
|
12
|
+
export function readUrlSelection(search: string): UrlSelection {
|
|
13
|
+
try {
|
|
14
|
+
const params = new URLSearchParams(search.startsWith('?') ? search.slice(1) : search)
|
|
15
|
+
const module = params.get(MODULE_PARAM)
|
|
16
|
+
const draft = params.get(DRAFT_PARAM)
|
|
17
|
+
return { module: module === '' ? null : module, draft: draft === '' ? null : draft }
|
|
18
|
+
} catch {
|
|
19
|
+
return { module: null, draft: null }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* the query for a selection, with everything else in the url PRESERVED, the panel does not
|
|
25
|
+
* own the whole query string, and eating an unrelated param someone appended would be rude.
|
|
26
|
+
* returns the full search string, `''` when there is nothing to carry.
|
|
27
|
+
*/
|
|
28
|
+
export function writeUrlSelection(p: { search: string; module: string; draft: string }): string {
|
|
29
|
+
const params = new URLSearchParams(p.search.startsWith('?') ? p.search.slice(1) : p.search)
|
|
30
|
+
params.set(MODULE_PARAM, p.module)
|
|
31
|
+
params.set(DRAFT_PARAM, p.draft)
|
|
32
|
+
const text = params.toString()
|
|
33
|
+
return text === '' ? '' : `?${text}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** the selection to open with: THE URL WINS over what this browser last had. A link is an
|
|
37
|
+
* explicit instruction from whoever sent it; the stored selection is only a memory of your
|
|
38
|
+
* own last visit, and it must never override the link you just clicked. */
|
|
39
|
+
export function resolveSelection(p: {
|
|
40
|
+
url: UrlSelection
|
|
41
|
+
stored: UrlSelection
|
|
42
|
+
/** module key → its drafts */
|
|
43
|
+
modules: readonly { module: string; drafts: readonly string[] }[]
|
|
44
|
+
}): { module: string; draft: string } | null {
|
|
45
|
+
const pick = (key: string | null): { module: string; drafts: readonly string[] } | null =>
|
|
46
|
+
key == null ? null : (p.modules.find((m) => m.module === key) ?? null)
|
|
47
|
+
// a url naming a module this server does not serve falls back rather than showing nothing
|
|
48
|
+
const mod = pick(p.url.module) ?? pick(p.stored.module) ?? p.modules[0]
|
|
49
|
+
if (mod == null) return null
|
|
50
|
+
const wanted = p.url.module != null && p.url.module === mod.module ? p.url.draft : p.stored.draft
|
|
51
|
+
const draft = wanted != null && mod.drafts.includes(wanted) ? wanted : 'default'
|
|
52
|
+
return { module: mod.module, draft }
|
|
53
|
+
}
|